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 <torsten.rasmussen@nordicsemi.no>
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
This commit is contained in:
Jamie McCrae 2023-06-12 15:37:37 +01:00 committed by Anas Nashif
parent e1efafa31d
commit 9642c48a29
2 changed files with 29 additions and 16 deletions

View file

@ -1,6 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
#
# Copyright (c) 2021, Nordic Semiconductor ASA
# Copyright (c) 2021-2023, Nordic Semiconductor ASA
# Convert Zephyr roots to absolute paths.
#
@ -21,21 +21,6 @@ include_guard(GLOBAL)
include(extensions)
# Convert paths to absolute, relative from APPLICATION_SOURCE_DIR
zephyr_file(APPLICATION_ROOT MODULE_EXT_ROOT)
# Convert paths to absolute, relative from APPLICATION_SOURCE_DIR
zephyr_file(APPLICATION_ROOT BOARD_ROOT)
# Convert paths to absolute, relative from APPLICATION_SOURCE_DIR
zephyr_file(APPLICATION_ROOT SOC_ROOT)
# Convert paths to absolute, relative from APPLICATION_SOURCE_DIR
zephyr_file(APPLICATION_ROOT ARCH_ROOT)
# Convert paths to absolute, relative from APPLICATION_SOURCE_DIR
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)
@ -43,6 +28,13 @@ zephyr_get(SOC_ROOT MERGE SYSBUILD GLOBAL)
zephyr_get(ARCH_ROOT MERGE SYSBUILD GLOBAL)
zephyr_get(SCA_ROOT MERGE SYSBUILD GLOBAL)
# Convert paths to absolute, relative from APPLICATION_SOURCE_DIR
zephyr_file(APPLICATION_ROOT MODULE_EXT_ROOT)
zephyr_file(APPLICATION_ROOT BOARD_ROOT)
zephyr_file(APPLICATION_ROOT SOC_ROOT)
zephyr_file(APPLICATION_ROOT ARCH_ROOT)
zephyr_file(APPLICATION_ROOT SCA_ROOT)
if(unittest IN_LIST Zephyr_FIND_COMPONENTS)
# Zephyr used in unittest mode, use dedicated unittest root.
set(BOARD_ROOT ${ZEPHYR_BASE}/subsys/testsuite)

View file

@ -182,6 +182,17 @@ function(ExternalZephyrProject_Add)
)
endif()
endif()
# Update ROOT variables with relative paths to use absolute paths based on
# the source application directory.
foreach(type MODULE_EXT BOARD SOC ARCH SCA)
if(DEFINED CACHE{${ZBUILD_APPLICATION}_${type}_ROOT} AND NOT IS_ABSOLUTE $CACHE{${ZBUILD_APPLICATION}_${type}_ROOT})
set(rel_path $CACHE{${ZBUILD_APPLICATION}_${type}_ROOT})
cmake_path(ABSOLUTE_PATH rel_path BASE_DIRECTORY "${ZBUILD_SOURCE_DIR}" NORMALIZE OUTPUT_VARIABLE abs_path)
set(${ZBUILD_APPLICATION}_${type}_ROOT ${abs_path} CACHE PATH "Sysbuild adjusted absolute path" FORCE)
endif()
endforeach()
# CMake variables which must be known by all Zephyr CMake build systems
# Those are settings which controls the build and must be known to CMake at
# invocation time, and thus cannot be passed though the sysbuild cache file.
@ -315,6 +326,16 @@ function(ExternalZephyrProject_Cmake)
get_target_property(${ZCMAKE_APPLICATION}_BOARD ${ZCMAKE_APPLICATION} BOARD)
get_target_property(${ZCMAKE_APPLICATION}_MAIN_APP ${ZCMAKE_APPLICATION} MAIN_APP)
# Update ROOT variables with relative paths to use absolute paths based on
# the source application directory.
foreach(type MODULE_EXT BOARD SOC ARCH SCA)
if(DEFINED CACHE{${type}_ROOT} AND NOT IS_ABSOLUTE $CACHE{${type}_ROOT})
set(rel_path $CACHE{${type}_ROOT})
cmake_path(ABSOLUTE_PATH rel_path BASE_DIRECTORY "${APP_DIR}" NORMALIZE OUTPUT_VARIABLE abs_path)
set(${type}_ROOT ${abs_path} CACHE PATH "Sysbuild adjusted absolute path" FORCE)
endif()
endforeach()
get_cmake_property(sysbuild_cache CACHE_VARIABLES)
foreach(var_name ${sysbuild_cache})
if(NOT "${var_name}" MATCHES "^(CMAKE_.*|BOARD)$")