diff --git a/cmake/modules/dts.cmake b/cmake/modules/dts.cmake index a2c56577cfa54ff..5244f8043ebe7e6 100644 --- a/cmake/modules/dts.cmake +++ b/cmake/modules/dts.cmake @@ -349,17 +349,24 @@ endif() # # Run GEN_DTS_CMAKE_SCRIPT. # +# A temporary file is used copied to the original file if it differs, this prevents a cycle when +# sysbuild is used of configuring and building multiple times due to the dts.cmake file of images +# having a newer modification time than the sysbuild build.ninja file, despite the output having +# not changed +# +set(dts_cmake_tmp ${DTS_CMAKE}_tmp) execute_process( COMMAND ${PYTHON_EXECUTABLE} ${GEN_DTS_CMAKE_SCRIPT} --edt-pickle ${EDT_PICKLE} - --cmake-out ${DTS_CMAKE} + --cmake-out ${dts_cmake_tmp} WORKING_DIRECTORY ${PROJECT_BINARY_DIR} RESULT_VARIABLE ret ) if(NOT "${ret}" STREQUAL "0") message(FATAL_ERROR "gen_dts_cmake.py failed with return code: ${ret}") else() + file(COPY_FILE ${dts_cmake_tmp} ${DTS_CMAKE} ONLY_IF_DIFFERENT) message(STATUS "Including generated dts.cmake file: ${DTS_CMAKE}") include(${DTS_CMAKE}) endif()