Skip to content

Commit d53b51e

Browse files
57300rlubos
authored andcommitted
[nrf fromlist] scripts: gen_dts_cmake: Support variable target name in dts.cmake
Upstream PR: zephyrproject-rtos/zephyr#73903 Instead of hardcoding the name `devicetree_target`, we can update the generated `dts.cmake` to accept `DEVICETREE_TARGET` as input variable. This will become useful in multi-image builds, where we would like to process multiple devicetrees. Signed-off-by: Grzegorz Swiderski <[email protected]> (cherry picked from commit cd187c719ae9162a2ab6bd6aeff511a4cc684bdc)
1 parent d2701ba commit d53b51e

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

cmake/modules/dts.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ set(GEN_DTS_CMAKE_SCRIPT ${DT_SCRIPTS}/gen_dts_cmake.py)
117117
# The generated information itself, which we include() after
118118
# creating it.
119119
set(DTS_CMAKE ${PROJECT_BINARY_DIR}/dts.cmake)
120+
# The CMake target to be initialized by including ${DTS_CMAKE}.
121+
set(DEVICETREE_TARGET devicetree_target)
120122

121123
# The location of a file containing known vendor prefixes, relative to
122124
# each element of DTS_ROOT. Users can define their own in their own

scripts/dts/gen_dts_cmake.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
1212
The generated CMake file looks like this:
1313
14-
add_custom_target(devicetree_target)
15-
set_target_properties(devicetree_target PROPERTIES
14+
add_custom_target(${DEVICETREE_TARGET})
15+
set_target_properties(${DEVICETREE_TARGET} PROPERTIES
1616
"DT_PROP|/soc|compatible" "vnd,soc;")
1717
...
1818
19-
It defines a special CMake target, and saves various values in the
19+
It takes an input variable - DEVICETREE_TARGET - and creates a special
20+
CMake target with this name, which will contain various values in the
2021
devicetree as CMake target properties.
2122
2223
Be careful:
@@ -154,15 +155,13 @@ def main():
154155
cmake_comp = f'DT_COMP|{comp}'
155156
cmake_props.append(f'"{cmake_comp}" "{cmake_path}"')
156157

158+
cmake_props = map(
159+
'set_target_properties(${{DEVICETREE_TARGET}} PROPERTIES {})'.format,
160+
cmake_props
161+
)
157162
with open(args.cmake_out, "w", encoding="utf-8") as cmake_file:
158-
print('add_custom_target(devicetree_target)', file=cmake_file)
159-
print(file=cmake_file)
160-
161-
for prop in cmake_props:
162-
print(
163-
f'set_target_properties(devicetree_target PROPERTIES {prop})',
164-
file=cmake_file
165-
)
163+
print('add_custom_target(${DEVICETREE_TARGET})\n', *cmake_props,
164+
sep='\n', file=cmake_file)
166165

167166

168167
if __name__ == "__main__":

0 commit comments

Comments
 (0)