Skip to content

Commit 9642c48

Browse files
nordicjmnashif
authored andcommitted
cmake: boards: Fix issue with relative paths
Fixes an issue with relative paths both with and without using sysbuild where they would not be updated properly or a warning would previously be emitted. Signed-off-by: Torsten Rasmussen <[email protected]> Signed-off-by: Jamie McCrae <[email protected]>
1 parent e1efafa commit 9642c48

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

cmake/modules/root.cmake

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: Apache-2.0
22
#
3-
# Copyright (c) 2021, Nordic Semiconductor ASA
3+
# Copyright (c) 2021-2023, Nordic Semiconductor ASA
44

55
# Convert Zephyr roots to absolute paths.
66
#
@@ -21,28 +21,20 @@ include_guard(GLOBAL)
2121

2222
include(extensions)
2323

24-
# Convert paths to absolute, relative from APPLICATION_SOURCE_DIR
25-
zephyr_file(APPLICATION_ROOT MODULE_EXT_ROOT)
26-
27-
# Convert paths to absolute, relative from APPLICATION_SOURCE_DIR
28-
zephyr_file(APPLICATION_ROOT BOARD_ROOT)
29-
30-
# Convert paths to absolute, relative from APPLICATION_SOURCE_DIR
31-
zephyr_file(APPLICATION_ROOT SOC_ROOT)
32-
33-
# Convert paths to absolute, relative from APPLICATION_SOURCE_DIR
34-
zephyr_file(APPLICATION_ROOT ARCH_ROOT)
35-
36-
# Convert paths to absolute, relative from APPLICATION_SOURCE_DIR
37-
zephyr_file(APPLICATION_ROOT SCA_ROOT)
38-
3924
# Merge in variables from other sources (e.g. sysbuild)
4025
zephyr_get(MODULE_EXT_ROOT MERGE SYSBUILD GLOBAL)
4126
zephyr_get(BOARD_ROOT MERGE SYSBUILD GLOBAL)
4227
zephyr_get(SOC_ROOT MERGE SYSBUILD GLOBAL)
4328
zephyr_get(ARCH_ROOT MERGE SYSBUILD GLOBAL)
4429
zephyr_get(SCA_ROOT MERGE SYSBUILD GLOBAL)
4530

31+
# Convert paths to absolute, relative from APPLICATION_SOURCE_DIR
32+
zephyr_file(APPLICATION_ROOT MODULE_EXT_ROOT)
33+
zephyr_file(APPLICATION_ROOT BOARD_ROOT)
34+
zephyr_file(APPLICATION_ROOT SOC_ROOT)
35+
zephyr_file(APPLICATION_ROOT ARCH_ROOT)
36+
zephyr_file(APPLICATION_ROOT SCA_ROOT)
37+
4638
if(unittest IN_LIST Zephyr_FIND_COMPONENTS)
4739
# Zephyr used in unittest mode, use dedicated unittest root.
4840
set(BOARD_ROOT ${ZEPHYR_BASE}/subsys/testsuite)

share/sysbuild/cmake/modules/sysbuild_extensions.cmake

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,17 @@ function(ExternalZephyrProject_Add)
182182
)
183183
endif()
184184
endif()
185+
186+
# Update ROOT variables with relative paths to use absolute paths based on
187+
# the source application directory.
188+
foreach(type MODULE_EXT BOARD SOC ARCH SCA)
189+
if(DEFINED CACHE{${ZBUILD_APPLICATION}_${type}_ROOT} AND NOT IS_ABSOLUTE $CACHE{${ZBUILD_APPLICATION}_${type}_ROOT})
190+
set(rel_path $CACHE{${ZBUILD_APPLICATION}_${type}_ROOT})
191+
cmake_path(ABSOLUTE_PATH rel_path BASE_DIRECTORY "${ZBUILD_SOURCE_DIR}" NORMALIZE OUTPUT_VARIABLE abs_path)
192+
set(${ZBUILD_APPLICATION}_${type}_ROOT ${abs_path} CACHE PATH "Sysbuild adjusted absolute path" FORCE)
193+
endif()
194+
endforeach()
195+
185196
# CMake variables which must be known by all Zephyr CMake build systems
186197
# Those are settings which controls the build and must be known to CMake at
187198
# invocation time, and thus cannot be passed though the sysbuild cache file.
@@ -315,6 +326,16 @@ function(ExternalZephyrProject_Cmake)
315326
get_target_property(${ZCMAKE_APPLICATION}_BOARD ${ZCMAKE_APPLICATION} BOARD)
316327
get_target_property(${ZCMAKE_APPLICATION}_MAIN_APP ${ZCMAKE_APPLICATION} MAIN_APP)
317328

329+
# Update ROOT variables with relative paths to use absolute paths based on
330+
# the source application directory.
331+
foreach(type MODULE_EXT BOARD SOC ARCH SCA)
332+
if(DEFINED CACHE{${type}_ROOT} AND NOT IS_ABSOLUTE $CACHE{${type}_ROOT})
333+
set(rel_path $CACHE{${type}_ROOT})
334+
cmake_path(ABSOLUTE_PATH rel_path BASE_DIRECTORY "${APP_DIR}" NORMALIZE OUTPUT_VARIABLE abs_path)
335+
set(${type}_ROOT ${abs_path} CACHE PATH "Sysbuild adjusted absolute path" FORCE)
336+
endif()
337+
endforeach()
338+
318339
get_cmake_property(sysbuild_cache CACHE_VARIABLES)
319340
foreach(var_name ${sysbuild_cache})
320341
if(NOT "${var_name}" MATCHES "^(CMAKE_.*|BOARD)$")

0 commit comments

Comments
 (0)