Skip to content

Commit 5c57abc

Browse files
SebastianBoecarlescufi
authored andcommitted
cmake: dt: Reconfigure when DTS dependencies change
When DT sources change CMake must be run again. CMake is currently detecting changes to DT source files that we manually specify, but not sources that are included through use of the preprocessor. This patch makes the preprocessor output the includes used and adds them to the 'CMAKE_CONFIGURE_DEPENDS' property. This fixes #16791. Signed-off-by: Sebastian Bøe <[email protected]>
1 parent c5dd84a commit 5c57abc

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

cmake/dts.cmake

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,6 @@ if(SUPPORTS_DTS)
6565
message(STATUS "Overlaying ${dts_file}")
6666
endif()
6767

68-
# Ensure that changes to 'dts_file's cause CMake to be re-run
69-
set_property(DIRECTORY APPEND PROPERTY
70-
CMAKE_CONFIGURE_DEPENDS
71-
${dts_file}
72-
)
73-
7468
math(EXPR i "${i}+1")
7569
endforeach()
7670

@@ -109,7 +103,8 @@ if(SUPPORTS_DTS)
109103

110104
# Run the C preprocessor on an empty C source file that has one or
111105
# more DTS source files -include'd into it to create the
112-
# intermediary file *.dts.pre.tmp
106+
# intermediary file *.dts.pre.tmp. Also, generate a dependency file
107+
# so that changes to DT sources are detected.
113108
execute_process(
114109
COMMAND ${CMAKE_C_COMPILER}
115110
-x assembler-with-cpp
@@ -119,15 +114,30 @@ if(SUPPORTS_DTS)
119114
${NOSYSDEF_CFLAG}
120115
-D__DTS__
121116
-P
122-
-E ${ZEPHYR_BASE}/misc/empty_file.c
117+
-E # Stop after preprocessing
118+
-MD # Generate a dependency file as a side-effect
123119
-o ${BOARD}.dts.pre.tmp
120+
${ZEPHYR_BASE}/misc/empty_file.c
124121
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
125122
RESULT_VARIABLE ret
126123
)
127124
if(NOT "${ret}" STREQUAL "0")
128125
message(FATAL_ERROR "command failed with return code: ${ret}")
129126
endif()
130127

128+
# Parse the generated dependency file to find the DT sources that
129+
# were included and then add them to the list of files that trigger
130+
# a re-run of CMake.
131+
toolchain_parse_make_rule(
132+
${PROJECT_BINARY_DIR}/${BOARD}.dts.pre.d
133+
include_files # Output parameter
134+
)
135+
136+
set_property(DIRECTORY APPEND PROPERTY
137+
CMAKE_CONFIGURE_DEPENDS
138+
${include_files}
139+
)
140+
131141
# Run the DTC on *.dts.pre.tmp to create the intermediary file *.dts_compiled
132142

133143
set(DTC_WARN_UNIT_ADDR_IF_ENABLED "")

0 commit comments

Comments
 (0)