@@ -2467,10 +2467,10 @@ function(zephyr_list transform list_var action)
2467
2467
endfunction ()
2468
2468
2469
2469
# Usage:
2470
- # zephyr_get(<variable>)
2471
- # zephyr_get(<variable> SYSBUILD [LOCAL|GLOBAL])
2470
+ # zephyr_get(<variable> [MERGE] [SYSBUILD [LOCAL|GLOBAL]])
2472
2471
#
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.
2474
2474
#
2475
2475
# zephyr_get() is a common function to provide a uniform way of supporting
2476
2476
# build settings that can be set from sysbuild, CMakeLists.txt, CMake cache, or
@@ -2484,6 +2484,8 @@ endfunction()
2484
2484
# - blinky_BOARD is considered a local sysbuild cache variable only for the
2485
2485
# blinky image.
2486
2486
# 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).
2487
2489
# - CMake cache, set by `-D<var>=<value>` or `set(<var> <val> CACHE ...)
2488
2490
# - Environment
2489
2491
# - Locally in CMakeLists.txt before 'find_package(Zephyr)'
@@ -2493,7 +2495,7 @@ endfunction()
2493
2495
# using `-DZEPHYR_TOOLCHAIN_VARIANT=<val>`, then the value from the cache is
2494
2496
# returned.
2495
2497
function (zephyr_get variable )
2496
- cmake_parse_arguments (GET_VAR "" "SYSBUILD" "" ${ARGN} )
2498
+ cmake_parse_arguments (GET_VAR "MERGE " "SYSBUILD" "" ${ARGN} )
2497
2499
2498
2500
if (DEFINED GET_VAR_SYSBUILD )
2499
2501
if (NOT (${GET_VAR_SYSBUILD} STREQUAL "GLOBAL" OR
@@ -2505,6 +2507,13 @@ function(zephyr_get variable)
2505
2507
set (GET_VAR_SYSBUILD "GLOBAL" )
2506
2508
endif ()
2507
2509
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
+
2508
2517
if (SYSBUILD )
2509
2518
get_property (sysbuild_name TARGET sysbuild_cache PROPERTY SYSBUILD_NAME )
2510
2519
get_property (sysbuild_main_app TARGET sysbuild_cache PROPERTY SYSBUILD_MAIN_APP )
@@ -2513,19 +2522,40 @@ function(zephyr_get variable)
2513
2522
(${GET_VAR_SYSBUILD} STREQUAL "GLOBAL" OR sysbuild_main_app )
2514
2523
)
2515
2524
get_property (sysbuild_${variable} TARGET sysbuild_cache PROPERTY ${variable} )
2525
+ set (used_global true )
2516
2526
endif ()
2517
2527
endif ()
2518
2528
2519
2529
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 ()
2529
2559
2530
2560
if (DEFINED ${variable} AND NOT "${${variable} }" STREQUAL "$ENV{${variable} }" )
2531
2561
# Variable exists as a local scoped variable, defined in a CMakeLists.txt
@@ -2537,6 +2567,15 @@ function(zephyr_get variable)
2537
2567
"Local scope value (hidden): ${${variable} }\n "
2538
2568
)
2539
2569
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 )
2540
2579
endif ()
2541
2580
endfunction (zephyr_get variable )
2542
2581
0 commit comments