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
24include_guard(GLOBAL)
25
26include(extensions)
27
28# Merge in variables from other sources
29zephyr_get(MODULE_EXT_ROOT MERGE)
30zephyr_get(BOARD_ROOT MERGE)
31zephyr_get(SOC_ROOT MERGE)
32zephyr_get(ARCH_ROOT MERGE)
33zephyr_get(SCA_ROOT MERGE)
34zephyr_get(SNIPPET_ROOT MERGE)
35
36# Convert paths to absolute, relative from APP_DIR
37zephyr_file(APPLICATION_ROOT MODULE_EXT_ROOT BASE_DIR ${APP_DIR})
38zephyr_file(APPLICATION_ROOT BOARD_ROOT BASE_DIR ${APP_DIR})
39zephyr_file(APPLICATION_ROOT SOC_ROOT BASE_DIR ${APP_DIR})
40zephyr_file(APPLICATION_ROOT ARCH_ROOT BASE_DIR ${APP_DIR})
41zephyr_file(APPLICATION_ROOT SCA_ROOT BASE_DIR ${APP_DIR})
42zephyr_file(APPLICATION_ROOT SNIPPET_ROOT BASE_DIR ${APP_DIR})
43
44# Sysbuild must ensure any locally defined variables in sysbuild/CMakeLists.txt
45# have been added to the cache in order for the settings to propagate to images.
46# note: zephyr_file has removed any list duplicates
47if(DEFINED MODULE_EXT_ROOT)
48  set(MODULE_EXT_ROOT ${MODULE_EXT_ROOT} CACHE PATH "Sysbuild adjusted MODULE_EXT_ROOT" FORCE)
49endif()
50
51if(DEFINED BOARD_ROOT)
52  set(BOARD_ROOT ${BOARD_ROOT} CACHE PATH "Sysbuild adjusted BOARD_ROOT" FORCE)
53endif()
54
55if(DEFINED SOC_ROOT)
56  set(SOC_ROOT ${SOC_ROOT} CACHE PATH "Sysbuild adjusted SOC_ROOT" FORCE)
57endif()
58
59if(DEFINED ARCH_ROOT)
60  set(ARCH_ROOT ${ARCH_ROOT} CACHE PATH "Sysbuild adjusted ARCH_ROOT" FORCE)
61endif()
62
63if(DEFINED SCA_ROOT)
64  set(SCA_ROOT ${SCA_ROOT} CACHE PATH "Sysbuild adjusted SCA_ROOT" FORCE)
65endif()
66
67if(DEFINED SNIPPET_ROOT)
68  set(SNIPPET_ROOT ${SNIPPET_ROOT} CACHE PATH "Sysbuild adjusted SNIPPET_ROOT" FORCE)
69endif()
70