1# SPDX-License-Identifier: Apache-2.0
2#
3# Copyright (c) 2023, Nordic Semiconductor ASA
4
5#
6# Configure ARCH settings based on KConfig settings and arch root.
7#
8# This CMake module will set the following variables in the build system based
9# on board directory and arch root.
10#
11# If no implementation is available for the current arch an error will be raised.
12#
13# Outcome:
14# The following variables will be defined when this CMake module completes:
15#
16# - ARCH:      Name of the arch in use.
17# - ARCH_DIR:  Directory containing the arch implementation.
18# - ARCH_ROOT: ARCH_ROOT with ZEPHYR_BASE appended
19#
20# Variable dependencies:
21# - ARCH_ROOT: CMake list of arch roots containing arch implementations
22#
23# Variables set by this module and not mentioned above are considered internal
24# use only and may be removed, renamed, or re-purposed without prior notice.
25
26include_guard(GLOBAL)
27
28if(HWMv2)
29  # HWMv2 obtains arch from Kconfig for the given Board / SoC variant because
30  # the Board / SoC path is no longer sufficient for determine the arch
31  # (read: multi-core and multi-arch SoC).
32  set(ARCH ${CONFIG_ARCH})
33  string(TOUPPER "${ARCH}" arch_upper)
34
35  if(NOT ARCH)
36    message(FATAL_ERROR "ARCH not defined. Check that BOARD=${BOARD}, is selecting "
37            "an appropriate SoC in Kconfig, SoC=${CONFIG_SOC}, and that the SoC "
38            "is selecting the correct architecture."
39    )
40  endif()
41
42  cmake_path(GET ARCH_V2_${arch_upper}_DIR PARENT_PATH ARCH_DIR)
43  if(NOT ARCH_DIR)
44    message(FATAL_ERROR "Could not find ARCH=${ARCH} for BOARD=${BOARD}, \
45please check your installation. ARCH roots searched: \n\
46${ARCH_ROOT}")
47  endif()
48endif()
49