Skip to content

Commit

Permalink
[nrf fromlist] scripts: gen_dts_cmake: Support variable target name i…
Browse files Browse the repository at this point in the history
…n 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)
  • Loading branch information
57300 authored and rlubos committed Jul 16, 2024
1 parent d2701ba commit d53b51e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 2 additions & 0 deletions cmake/modules/dts.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ set(GEN_DTS_CMAKE_SCRIPT ${DT_SCRIPTS}/gen_dts_cmake.py)
# The generated information itself, which we include() after
# creating it.
set(DTS_CMAKE ${PROJECT_BINARY_DIR}/dts.cmake)
# The CMake target to be initialized by including ${DTS_CMAKE}.
set(DEVICETREE_TARGET devicetree_target)

# The location of a file containing known vendor prefixes, relative to
# each element of DTS_ROOT. Users can define their own in their own
Expand Down
21 changes: 10 additions & 11 deletions scripts/dts/gen_dts_cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
The generated CMake file looks like this:
add_custom_target(devicetree_target)
set_target_properties(devicetree_target PROPERTIES
add_custom_target(${DEVICETREE_TARGET})
set_target_properties(${DEVICETREE_TARGET} PROPERTIES
"DT_PROP|/soc|compatible" "vnd,soc;")
...
It defines a special CMake target, and saves various values in the
It takes an input variable - DEVICETREE_TARGET - and creates a special
CMake target with this name, which will contain various values in the
devicetree as CMake target properties.
Be careful:
Expand Down Expand Up @@ -154,15 +155,13 @@ def main():
cmake_comp = f'DT_COMP|{comp}'
cmake_props.append(f'"{cmake_comp}" "{cmake_path}"')

cmake_props = map(
'set_target_properties(${{DEVICETREE_TARGET}} PROPERTIES {})'.format,
cmake_props
)
with open(args.cmake_out, "w", encoding="utf-8") as cmake_file:
print('add_custom_target(devicetree_target)', file=cmake_file)
print(file=cmake_file)

for prop in cmake_props:
print(
f'set_target_properties(devicetree_target PROPERTIES {prop})',
file=cmake_file
)
print('add_custom_target(${DEVICETREE_TARGET})\n', *cmake_props,
sep='\n', file=cmake_file)


if __name__ == "__main__":
Expand Down

0 comments on commit d53b51e

Please sign in to comment.