Skip to content

Commit 24acc7d

Browse files
tejlmandfabiobaltieri
authored andcommitted
sysbuild: introduce sysbuild_root for root adjustment
Fixes: #73066 Introduce sysbuild_root CMake module similar to the Zephyr root CMake module. The sysbuild_root CMake module works similar to existing root module, but with the difference that root paths are adjusted relative to APP_DIR which is the main image, instead of relative to sysbuild. Signed-off-by: Torsten Rasmussen <[email protected]>
1 parent 8b3d4c6 commit 24acc7d

File tree

5 files changed

+74
-14
lines changed

5 files changed

+74
-14
lines changed

cmake/modules/extensions.cmake

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,6 +2549,8 @@ endfunction()
25492549
# to absolute path, relative from `APPLICATION_SOURCE_DIR`
25502550
# Issue an error for any relative path not specified
25512551
# by user with `-D<path>`
2552+
# BASE_DIR <base-dir>: convert paths relative to <base-dir>
2553+
# instead of `APPLICATION_SOURCE_DIR`
25522554
#
25532555
# returns an updated list of absolute paths
25542556
#
@@ -2602,7 +2604,7 @@ Please provide one of following: APPLICATION_ROOT, CONF_FILES")
26022604
endif()
26032605

26042606
if(${ARGV0} STREQUAL APPLICATION_ROOT)
2605-
set(single_args APPLICATION_ROOT)
2607+
set(single_args APPLICATION_ROOT BASE_DIR)
26062608
elseif(${ARGV0} STREQUAL CONF_FILES)
26072609
set(options QUALIFIERS REQUIRED)
26082610
set(single_args BOARD BOARD_REVISION BOARD_QUALIFIERS DTS KCONF DEFCONFIG BUILD SUFFIX)
@@ -2615,6 +2617,10 @@ Please provide one of following: APPLICATION_ROOT, CONF_FILES")
26152617
endif()
26162618

26172619
if(ZFILE_APPLICATION_ROOT)
2620+
if(NOT DEFINED ZFILE_BASE_DIR)
2621+
set(ZFILE_BASE_DIR ${APPLICATION_SOURCE_DIR})
2622+
endif()
2623+
26182624
# Note: user can do: `-D<var>=<relative-path>` and app can at same
26192625
# time specify `list(APPEND <var> <abs-path>)`
26202626
# Thus need to check and update only CACHED variables (-D<var>).
@@ -2625,7 +2631,7 @@ Please provide one of following: APPLICATION_ROOT, CONF_FILES")
26252631
# path from `APPLICATION_SOURCE_DIR`.
26262632
if(NOT IS_ABSOLUTE ${path})
26272633
list(FIND ${ZFILE_APPLICATION_ROOT} ${path} index)
2628-
cmake_path(ABSOLUTE_PATH path BASE_DIRECTORY ${APPLICATION_SOURCE_DIR} NORMALIZE)
2634+
cmake_path(ABSOLUTE_PATH path BASE_DIRECTORY ${ZFILE_BASE_DIR} NORMALIZE)
26292635
if(NOT ${index} LESS 0)
26302636
list(REMOVE_AT ${ZFILE_APPLICATION_ROOT} ${index})
26312637
list(INSERT ${ZFILE_APPLICATION_ROOT} ${index} ${path})
@@ -2645,7 +2651,7 @@ Relative paths are only allowed with `-D${ARGV1}=<path>`")
26452651
endif()
26462652
endforeach()
26472653

2648-
list(REMOVE_DUPLICATES ZFILE_APPLICATION_ROOT)
2654+
list(REMOVE_DUPLICATES ${ZFILE_APPLICATION_ROOT})
26492655
# This updates the provided argument in parent scope (callers scope)
26502656
set(${ZFILE_APPLICATION_ROOT} ${${ZFILE_APPLICATION_ROOT}} PARENT_SCOPE)
26512657
endif()

cmake/modules/root.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# - SOC_ROOT: CMake list of SoC roots containing SoC implementations
1313
# - BOARD_ROOT: CMake list of board roots containing board and shield implementations
1414
# - MODULE_EXT_ROOT: CMake list of module external roots containing module glue code
15+
# - SCA_ROOT: CMake list of SCA roots containing static code analysis integration code
1516
#
1617
# If a root is defined it will check the list of paths in the root and convert
1718
# any relative path to absolute path and update the root list.

share/sysbuild/cmake/modules/sysbuild_default.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ include(extensions)
99
include(sysbuild_extensions)
1010
include(python)
1111
include(west)
12-
include(root)
12+
include(sysbuild_root)
1313
include(zephyr_module)
1414
include(boards)
1515
include(shields)

share/sysbuild/cmake/modules/sysbuild_extensions.cmake

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -460,16 +460,6 @@ function(ExternalZephyrProject_Cmake)
460460
PROPERTY IMAGE_CONF_SCRIPT
461461
)
462462

463-
# Update ROOT variables with relative paths to use absolute paths based on
464-
# the source application directory.
465-
foreach(type MODULE_EXT BOARD SOC ARCH SCA)
466-
if(DEFINED CACHE{${type}_ROOT} AND NOT IS_ABSOLUTE $CACHE{${type}_ROOT})
467-
set(rel_path $CACHE{${type}_ROOT})
468-
cmake_path(ABSOLUTE_PATH rel_path BASE_DIRECTORY "${APP_DIR}" NORMALIZE OUTPUT_VARIABLE abs_path)
469-
set(${type}_ROOT ${abs_path} CACHE PATH "Sysbuild adjusted absolute path" FORCE)
470-
endif()
471-
endforeach()
472-
473463
sysbuild_cache(CREATE APPLICATION ${ZCMAKE_APPLICATION})
474464

475465
foreach(script ${${ZCMAKE_APPLICATION}_CONF_SCRIPT})
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
#
3+
# Copyright (c) 2024, Nordic Semiconductor ASA
4+
5+
# Convert Zephyr roots to absolute paths to be used by sysbuild.
6+
#
7+
# This CMake module will convert all relative paths in existing ROOT lists to
8+
# absolute path relative from APP_DIR.
9+
#
10+
# Optional variables:
11+
# - ARCH_ROOT: CMake list of arch roots containing arch implementations
12+
# - SOC_ROOT: CMake list of SoC roots containing SoC implementations
13+
# - BOARD_ROOT: CMake list of board roots containing board and shield implementations
14+
# - MODULE_EXT_ROOT: CMake list of module external roots containing module glue code
15+
# - SCA_ROOT: CMake list of SCA roots containing static code analysis integration code
16+
#
17+
# If a root is defined it will check the list of paths in the root and convert
18+
# any relative path to absolute path and update the root list.
19+
# If a root is undefined it will still be undefined when this module has loaded.
20+
#
21+
# Converted paths are placed in the CMake cache so that they are propagated
22+
# correctly to image builds.
23+
24+
include_guard(GLOBAL)
25+
26+
include(extensions)
27+
28+
# Merge in variables from other sources
29+
zephyr_get(MODULE_EXT_ROOT MERGE)
30+
zephyr_get(BOARD_ROOT MERGE)
31+
zephyr_get(SOC_ROOT MERGE)
32+
zephyr_get(ARCH_ROOT MERGE)
33+
zephyr_get(SCA_ROOT MERGE)
34+
35+
# Convert paths to absolute, relative from APP_DIR
36+
zephyr_file(APPLICATION_ROOT MODULE_EXT_ROOT BASE_DIR ${APP_DIR})
37+
zephyr_file(APPLICATION_ROOT BOARD_ROOT BASE_DIR ${APP_DIR})
38+
zephyr_file(APPLICATION_ROOT SOC_ROOT BASE_DIR ${APP_DIR})
39+
zephyr_file(APPLICATION_ROOT ARCH_ROOT BASE_DIR ${APP_DIR})
40+
zephyr_file(APPLICATION_ROOT SCA_ROOT BASE_DIR ${APP_DIR})
41+
42+
# Sysbuild must ensure any locally defined variables in sysbuild/CMakeLists.txt
43+
# have been added to the cache in order for the settings to propagate to images.
44+
# note: zephyr_file has removed any list duplicates
45+
if(DEFINED MODULE_EXT_ROOT)
46+
set(MODULE_EXT_ROOT ${MODULE_EXT_ROOT} CACHE PATH "Sysbuild adjusted MODULE_EXT_ROOT" FORCE)
47+
endif()
48+
49+
if(DEFINED BOARD_ROOT)
50+
set(BOARD_ROOT ${BOARD_ROOT} CACHE PATH "Sysbuild adjusted BOARD_ROOT" FORCE)
51+
endif()
52+
53+
if(DEFINED SOC_ROOT)
54+
set(SOC_ROOT ${SOC_ROOT} CACHE PATH "Sysbuild adjusted SOC_ROOT" FORCE)
55+
endif()
56+
57+
if(DEFINED ARCH_ROOT)
58+
set(ARCH_ROOT ${ARCH_ROOT} CACHE PATH "Sysbuild adjusted ARCH_ROOT" FORCE)
59+
endif()
60+
61+
if(DEFINED SCA_ROOT)
62+
set(SCA_ROOT ${SCA_ROOT} CACHE PATH "Sysbuild adjusted SCA_ROOT" FORCE)
63+
endif()

0 commit comments

Comments
 (0)