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>
This commit is contained in:
Jamie McCrae 2023-04-13 10:48:30 +01:00 committed by Carles Cufí
commit cd9465ac94
2 changed files with 59 additions and 13 deletions

View file

@ -2467,10 +2467,10 @@ function(zephyr_list transform list_var action)
endfunction() endfunction()
# Usage: # Usage:
# zephyr_get(<variable>) # zephyr_get(<variable> [MERGE] [SYSBUILD [LOCAL|GLOBAL]])
# zephyr_get(<variable> SYSBUILD [LOCAL|GLOBAL])
# #
# Return the value of <variable> as local scoped variable of same name. # Return the value of <variable> as local scoped variable of same name. If MERGE
# is supplied, will return a list of found items.
# #
# zephyr_get() is a common function to provide a uniform way of supporting # zephyr_get() is a common function to provide a uniform way of supporting
# build settings that can be set from sysbuild, CMakeLists.txt, CMake cache, or # build settings that can be set from sysbuild, CMakeLists.txt, CMake cache, or
@ -2484,6 +2484,8 @@ endfunction()
# - blinky_BOARD is considered a local sysbuild cache variable only for the # - blinky_BOARD is considered a local sysbuild cache variable only for the
# blinky image. # blinky image.
# If no sysbuild scope is specified, GLOBAL is assumed. # If no sysbuild scope is specified, GLOBAL is assumed.
# If using MERGE then SYSBUILD GLOBAL will get both the local and global
# sysbuild scope variables (in that order, if both exist).
# - CMake cache, set by `-D<var>=<value>` or `set(<var> <val> CACHE ...) # - CMake cache, set by `-D<var>=<value>` or `set(<var> <val> CACHE ...)
# - Environment # - Environment
# - Locally in CMakeLists.txt before 'find_package(Zephyr)' # - Locally in CMakeLists.txt before 'find_package(Zephyr)'
@ -2493,7 +2495,7 @@ endfunction()
# using `-DZEPHYR_TOOLCHAIN_VARIANT=<val>`, then the value from the cache is # using `-DZEPHYR_TOOLCHAIN_VARIANT=<val>`, then the value from the cache is
# returned. # returned.
function(zephyr_get variable) function(zephyr_get variable)
cmake_parse_arguments(GET_VAR "" "SYSBUILD" "" ${ARGN}) cmake_parse_arguments(GET_VAR "MERGE" "SYSBUILD" "" ${ARGN})
if(DEFINED GET_VAR_SYSBUILD) if(DEFINED GET_VAR_SYSBUILD)
if(NOT (${GET_VAR_SYSBUILD} STREQUAL "GLOBAL" OR if(NOT (${GET_VAR_SYSBUILD} STREQUAL "GLOBAL" OR
@ -2505,6 +2507,13 @@ function(zephyr_get variable)
set(GET_VAR_SYSBUILD "GLOBAL") set(GET_VAR_SYSBUILD "GLOBAL")
endif() endif()
if(GET_VAR_MERGE)
# Clear variable before appending items in MERGE mode
set(${variable})
endif()
set(used_global false)
if(SYSBUILD) if(SYSBUILD)
get_property(sysbuild_name TARGET sysbuild_cache PROPERTY SYSBUILD_NAME) get_property(sysbuild_name TARGET sysbuild_cache PROPERTY SYSBUILD_NAME)
get_property(sysbuild_main_app TARGET sysbuild_cache PROPERTY SYSBUILD_MAIN_APP) get_property(sysbuild_main_app TARGET sysbuild_cache PROPERTY SYSBUILD_MAIN_APP)
@ -2513,19 +2522,40 @@ function(zephyr_get variable)
(${GET_VAR_SYSBUILD} STREQUAL "GLOBAL" OR sysbuild_main_app) (${GET_VAR_SYSBUILD} STREQUAL "GLOBAL" OR sysbuild_main_app)
) )
get_property(sysbuild_${variable} TARGET sysbuild_cache PROPERTY ${variable}) get_property(sysbuild_${variable} TARGET sysbuild_cache PROPERTY ${variable})
set(used_global true)
endif() endif()
endif() endif()
if(DEFINED sysbuild_${variable}) if(DEFINED sysbuild_${variable})
set(${variable} ${sysbuild_${variable}} PARENT_SCOPE) if(GET_VAR_MERGE)
elseif(DEFINED CACHE{${variable}}) list(APPEND ${variable} ${sysbuild_${variable}})
set(${variable} $CACHE{${variable}} PARENT_SCOPE) else()
elseif(DEFINED ENV{${variable}}) set(${variable} ${sysbuild_${variable}} PARENT_SCOPE)
set(${variable} $ENV{${variable}} PARENT_SCOPE) return()
# Set the environment variable in CMake cache, so that a build invocation endif()
# triggering a CMake rerun doesn't rely on the environment variable still endif()
# being available / have identical value. if(SYSBUILD AND GET_VAR_MERGE AND NOT used_global AND ${GET_VAR_SYSBUILD} STREQUAL "GLOBAL")
set(${variable} $ENV{${variable}} CACHE INTERNAL "") get_property(sysbuild_${variable} TARGET sysbuild_cache PROPERTY ${variable})
list(APPEND ${variable} ${sysbuild_${variable}})
endif()
if(DEFINED CACHE{${variable}})
if(GET_VAR_MERGE)
list(APPEND ${variable} $CACHE{${variable}})
else()
set(${variable} $CACHE{${variable}} PARENT_SCOPE)
return()
endif()
endif()
if(DEFINED ENV{${variable}})
if(GET_VAR_MERGE)
list(APPEND ${variable} $ENV{${variable}}})
else()
set(${variable} $ENV{${variable}} PARENT_SCOPE)
# Set the environment variable in CMake cache, so that a build invocation
# triggering a CMake rerun doesn't rely on the environment variable still
# being available / have identical value.
set(${variable} $ENV{${variable}} CACHE INTERNAL "")
endif()
if(DEFINED ${variable} AND NOT "${${variable}}" STREQUAL "$ENV{${variable}}") if(DEFINED ${variable} AND NOT "${${variable}}" STREQUAL "$ENV{${variable}}")
# Variable exists as a local scoped variable, defined in a CMakeLists.txt # Variable exists as a local scoped variable, defined in a CMakeLists.txt
@ -2537,6 +2567,15 @@ function(zephyr_get variable)
"Local scope value (hidden): ${${variable}}\n" "Local scope value (hidden): ${${variable}}\n"
) )
endif() endif()
if(NOT GET_VAR_MERGE)
return()
endif()
endif()
if(GET_VAR_MERGE)
list(REMOVE_DUPLICATES ${variable})
set(${variable} ${${variable}} PARENT_SCOPE)
endif() endif()
endfunction(zephyr_get variable) endfunction(zephyr_get variable)

View file

@ -36,6 +36,13 @@ zephyr_file(APPLICATION_ROOT ARCH_ROOT)
# Convert paths to absolute, relative from APPLICATION_SOURCE_DIR # Convert paths to absolute, relative from APPLICATION_SOURCE_DIR
zephyr_file(APPLICATION_ROOT SCA_ROOT) zephyr_file(APPLICATION_ROOT SCA_ROOT)
# Merge in variables from other sources (e.g. sysbuild)
zephyr_get(MODULE_EXT_ROOT MERGE SYSBUILD GLOBAL)
zephyr_get(BOARD_ROOT MERGE SYSBUILD GLOBAL)
zephyr_get(SOC_ROOT MERGE SYSBUILD GLOBAL)
zephyr_get(ARCH_ROOT MERGE SYSBUILD GLOBAL)
zephyr_get(SCA_ROOT MERGE SYSBUILD GLOBAL)
if(unittest IN_LIST Zephyr_FIND_COMPONENTS) if(unittest IN_LIST Zephyr_FIND_COMPONENTS)
# Zephyr used in unittest mode, use dedicated unittest root. # Zephyr used in unittest mode, use dedicated unittest root.
set(BOARD_ROOT ${ZEPHYR_BASE}/subsys/testsuite) set(BOARD_ROOT ${ZEPHYR_BASE}/subsys/testsuite)