1# SPDX-License-Identifier: Apache-2.0
2#
3# Copyright (c) 2021-2023, Nordic Semiconductor ASA
4
5# Convert Zephyr roots to absolute paths.
6#
7# This CMake module will convert all relative paths in existing ROOT lists to
8# absolute path relative from APPLICATION_SOURCE_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
21include_guard(GLOBAL)
22
23include(extensions)
24
25# Merge in variables from other sources (e.g. sysbuild)
26zephyr_get(MODULE_EXT_ROOT MERGE SYSBUILD GLOBAL)
27zephyr_get(BOARD_ROOT MERGE SYSBUILD GLOBAL)
28zephyr_get(SOC_ROOT MERGE SYSBUILD GLOBAL)
29zephyr_get(ARCH_ROOT MERGE SYSBUILD GLOBAL)
30zephyr_get(SCA_ROOT MERGE SYSBUILD GLOBAL)
31
32# Convert paths to absolute, relative from APPLICATION_SOURCE_DIR
33zephyr_file(APPLICATION_ROOT MODULE_EXT_ROOT)
34zephyr_file(APPLICATION_ROOT BOARD_ROOT)
35zephyr_file(APPLICATION_ROOT SOC_ROOT)
36zephyr_file(APPLICATION_ROOT ARCH_ROOT)
37zephyr_file(APPLICATION_ROOT SCA_ROOT)
38
39if(unittest IN_LIST Zephyr_FIND_COMPONENTS)
40  # Zephyr used in unittest mode, use dedicated unittest root.
41  set(BOARD_ROOT ${ZEPHYR_BASE}/subsys/testsuite)
42  set(ARCH_ROOT  ${ZEPHYR_BASE}/subsys/testsuite)
43  set(SOC_ROOT   ${ZEPHYR_BASE}/subsys/testsuite)
44endif()
45