Skip to content

Commit 100befc

Browse files
tejlmandanangl
authored andcommitted
[nrf fromtree] 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]> (cherry picked from commit 24acc7d)
1 parent 06cfbf0 commit 100befc

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
@@ -2534,6 +2534,8 @@ endfunction()
25342534
# to absolute path, relative from `APPLICATION_SOURCE_DIR`
25352535
# Issue an error for any relative path not specified
25362536
# by user with `-D<path>`
2537+
# BASE_DIR <base-dir>: convert paths relative to <base-dir>
2538+
# instead of `APPLICATION_SOURCE_DIR`
25372539
#
25382540
# returns an updated list of absolute paths
25392541
#
@@ -2587,7 +2589,7 @@ Please provide one of following: APPLICATION_ROOT, CONF_FILES")
25872589
endif()
25882590

25892591
if(${ARGV0} STREQUAL APPLICATION_ROOT)
2590-
set(single_args APPLICATION_ROOT)
2592+
set(single_args APPLICATION_ROOT BASE_DIR)
25912593
elseif(${ARGV0} STREQUAL CONF_FILES)
25922594
set(options QUALIFIERS REQUIRED)
25932595
set(single_args BOARD BOARD_REVISION BOARD_QUALIFIERS DTS KCONF DEFCONFIG BUILD SUFFIX)
@@ -2600,6 +2602,10 @@ Please provide one of following: APPLICATION_ROOT, CONF_FILES")
26002602
endif()
26012603

26022604
if(ZFILE_APPLICATION_ROOT)
2605+
if(NOT DEFINED ZFILE_BASE_DIR)
2606+
set(ZFILE_BASE_DIR ${APPLICATION_SOURCE_DIR})
2607+
endif()
2608+
26032609
# Note: user can do: `-D<var>=<relative-path>` and app can at same
26042610
# time specify `list(APPEND <var> <abs-path>)`
26052611
# Thus need to check and update only CACHED variables (-D<var>).
@@ -2610,7 +2616,7 @@ Please provide one of following: APPLICATION_ROOT, CONF_FILES")
26102616
# path from `APPLICATION_SOURCE_DIR`.
26112617
if(NOT IS_ABSOLUTE ${path})
26122618
list(FIND ${ZFILE_APPLICATION_ROOT} ${path} index)
2613-
cmake_path(ABSOLUTE_PATH path BASE_DIRECTORY ${APPLICATION_SOURCE_DIR} NORMALIZE)
2619+
cmake_path(ABSOLUTE_PATH path BASE_DIRECTORY ${ZFILE_BASE_DIR} NORMALIZE)
26142620
if(NOT ${index} LESS 0)
26152621
list(REMOVE_AT ${ZFILE_APPLICATION_ROOT} ${index})
26162622
list(INSERT ${ZFILE_APPLICATION_ROOT} ${index} ${path})
@@ -2630,7 +2636,7 @@ Relative paths are only allowed with `-D${ARGV1}=<path>`")
26302636
endif()
26312637
endforeach()
26322638

2633-
list(REMOVE_DUPLICATES ZFILE_APPLICATION_ROOT)
2639+
list(REMOVE_DUPLICATES ${ZFILE_APPLICATION_ROOT})
26342640
# This updates the provided argument in parent scope (callers scope)
26352641
set(${ZFILE_APPLICATION_ROOT} ${${ZFILE_APPLICATION_ROOT}} PARENT_SCOPE)
26362642
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)