Skip to content

Commit cd9465a

Browse files
nordicjmcarlescufi
authored andcommitted
sysbuild: Fix issue with *_ROOT values not propagating
Fixes an issue where variables like BOARD_ROOT would be provided to sysbuild but would then be lost on target images. Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
1 parent 1f070c9 commit cd9465a

File tree

2 files changed

+59
-13
lines changed

2 files changed

+59
-13
lines changed

cmake/modules/extensions.cmake

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,10 +2467,10 @@ function(zephyr_list transform list_var action)
24672467
endfunction()
24682468

24692469
# Usage:
2470-
# zephyr_get(<variable>)
2471-
# zephyr_get(<variable> SYSBUILD [LOCAL|GLOBAL])
2470+
# zephyr_get(<variable> [MERGE] [SYSBUILD [LOCAL|GLOBAL]])
24722471
#
2473-
# Return the value of <variable> as local scoped variable of same name.
2472+
# Return the value of <variable> as local scoped variable of same name. If MERGE
2473+
# is supplied, will return a list of found items.
24742474
#
24752475
# zephyr_get() is a common function to provide a uniform way of supporting
24762476
# build settings that can be set from sysbuild, CMakeLists.txt, CMake cache, or
@@ -2484,6 +2484,8 @@ endfunction()
24842484
# - blinky_BOARD is considered a local sysbuild cache variable only for the
24852485
# blinky image.
24862486
# If no sysbuild scope is specified, GLOBAL is assumed.
2487+
# If using MERGE then SYSBUILD GLOBAL will get both the local and global
2488+
# sysbuild scope variables (in that order, if both exist).
24872489
# - CMake cache, set by `-D<var>=<value>` or `set(<var> <val> CACHE ...)
24882490
# - Environment
24892491
# - Locally in CMakeLists.txt before 'find_package(Zephyr)'
@@ -2493,7 +2495,7 @@ endfunction()
24932495
# using `-DZEPHYR_TOOLCHAIN_VARIANT=<val>`, then the value from the cache is
24942496
# returned.
24952497
function(zephyr_get variable)
2496-
cmake_parse_arguments(GET_VAR "" "SYSBUILD" "" ${ARGN})
2498+
cmake_parse_arguments(GET_VAR "MERGE" "SYSBUILD" "" ${ARGN})
24972499

24982500
if(DEFINED GET_VAR_SYSBUILD)
24992501
if(NOT (${GET_VAR_SYSBUILD} STREQUAL "GLOBAL" OR
@@ -2505,6 +2507,13 @@ function(zephyr_get variable)
25052507
set(GET_VAR_SYSBUILD "GLOBAL")
25062508
endif()
25072509

2510+
if(GET_VAR_MERGE)
2511+
# Clear variable before appending items in MERGE mode
2512+
set(${variable})
2513+
endif()
2514+
2515+
set(used_global false)
2516+
25082517
if(SYSBUILD)
25092518
get_property(sysbuild_name TARGET sysbuild_cache PROPERTY SYSBUILD_NAME)
25102519
get_property(sysbuild_main_app TARGET sysbuild_cache PROPERTY SYSBUILD_MAIN_APP)
@@ -2513,19 +2522,40 @@ function(zephyr_get variable)
25132522
(${GET_VAR_SYSBUILD} STREQUAL "GLOBAL" OR sysbuild_main_app)
25142523
)
25152524
get_property(sysbuild_${variable} TARGET sysbuild_cache PROPERTY ${variable})
2525+
set(used_global true)
25162526
endif()
25172527
endif()
25182528

25192529
if(DEFINED sysbuild_${variable})
2520-
set(${variable} ${sysbuild_${variable}} PARENT_SCOPE)
2521-
elseif(DEFINED CACHE{${variable}})
2522-
set(${variable} $CACHE{${variable}} PARENT_SCOPE)
2523-
elseif(DEFINED ENV{${variable}})
2524-
set(${variable} $ENV{${variable}} PARENT_SCOPE)
2525-
# Set the environment variable in CMake cache, so that a build invocation
2526-
# triggering a CMake rerun doesn't rely on the environment variable still
2527-
# being available / have identical value.
2528-
set(${variable} $ENV{${variable}} CACHE INTERNAL "")
2530+
if(GET_VAR_MERGE)
2531+
list(APPEND ${variable} ${sysbuild_${variable}})
2532+
else()
2533+
set(${variable} ${sysbuild_${variable}} PARENT_SCOPE)
2534+
return()
2535+
endif()
2536+
endif()
2537+
if(SYSBUILD AND GET_VAR_MERGE AND NOT used_global AND ${GET_VAR_SYSBUILD} STREQUAL "GLOBAL")
2538+
get_property(sysbuild_${variable} TARGET sysbuild_cache PROPERTY ${variable})
2539+
list(APPEND ${variable} ${sysbuild_${variable}})
2540+
endif()
2541+
if(DEFINED CACHE{${variable}})
2542+
if(GET_VAR_MERGE)
2543+
list(APPEND ${variable} $CACHE{${variable}})
2544+
else()
2545+
set(${variable} $CACHE{${variable}} PARENT_SCOPE)
2546+
return()
2547+
endif()
2548+
endif()
2549+
if(DEFINED ENV{${variable}})
2550+
if(GET_VAR_MERGE)
2551+
list(APPEND ${variable} $ENV{${variable}}})
2552+
else()
2553+
set(${variable} $ENV{${variable}} PARENT_SCOPE)
2554+
# Set the environment variable in CMake cache, so that a build invocation
2555+
# triggering a CMake rerun doesn't rely on the environment variable still
2556+
# being available / have identical value.
2557+
set(${variable} $ENV{${variable}} CACHE INTERNAL "")
2558+
endif()
25292559

25302560
if(DEFINED ${variable} AND NOT "${${variable}}" STREQUAL "$ENV{${variable}}")
25312561
# Variable exists as a local scoped variable, defined in a CMakeLists.txt
@@ -2537,6 +2567,15 @@ function(zephyr_get variable)
25372567
"Local scope value (hidden): ${${variable}}\n"
25382568
)
25392569
endif()
2570+
2571+
if(NOT GET_VAR_MERGE)
2572+
return()
2573+
endif()
2574+
endif()
2575+
2576+
if(GET_VAR_MERGE)
2577+
list(REMOVE_DUPLICATES ${variable})
2578+
set(${variable} ${${variable}} PARENT_SCOPE)
25402579
endif()
25412580
endfunction(zephyr_get variable)
25422581

cmake/modules/root.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ zephyr_file(APPLICATION_ROOT ARCH_ROOT)
3636
# Convert paths to absolute, relative from APPLICATION_SOURCE_DIR
3737
zephyr_file(APPLICATION_ROOT SCA_ROOT)
3838

39+
# Merge in variables from other sources (e.g. sysbuild)
40+
zephyr_get(MODULE_EXT_ROOT MERGE SYSBUILD GLOBAL)
41+
zephyr_get(BOARD_ROOT MERGE SYSBUILD GLOBAL)
42+
zephyr_get(SOC_ROOT MERGE SYSBUILD GLOBAL)
43+
zephyr_get(ARCH_ROOT MERGE SYSBUILD GLOBAL)
44+
zephyr_get(SCA_ROOT MERGE SYSBUILD GLOBAL)
45+
3946
if(unittest IN_LIST Zephyr_FIND_COMPONENTS)
4047
# Zephyr used in unittest mode, use dedicated unittest root.
4148
set(BOARD_ROOT ${ZEPHYR_BASE}/subsys/testsuite)

0 commit comments

Comments
 (0)