From 254e35d61d59feca6e9b91fcc9ce7d3416917c22 Mon Sep 17 00:00:00 2001 From: Torsten Rasmussen Date: Tue, 4 Jan 2022 11:36:38 +0100 Subject: [PATCH] cmake: create an arch.cmake module The arch.cmake CMake module remove boilerplate code and place it inside a dedicated arch.cmake CMake module. This is part of a general CMake overhaul to allow better modularization and reuse of the Zephyr build system. Signed-off-by: Torsten Rasmussen --- cmake/app/boilerplate.cmake | 19 +--------------- cmake/arch.cmake | 44 +++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 18 deletions(-) create mode 100644 cmake/arch.cmake diff --git a/cmake/app/boilerplate.cmake b/cmake/app/boilerplate.cmake index 36216abd30..a7722cc4df 100644 --- a/cmake/app/boilerplate.cmake +++ b/cmake/app/boilerplate.cmake @@ -182,10 +182,7 @@ list(APPEND BOARD_ROOT ${ZEPHYR_BASE}) zephyr_file(APPLICATION_ROOT SOC_ROOT) -# 'ARCH_ROOT' is a prioritized list of directories where archs may be -# found. It always includes ${ZEPHYR_BASE} at the lowest priority. zephyr_file(APPLICATION_ROOT ARCH_ROOT) -list(APPEND ARCH_ROOT ${ZEPHYR_BASE}) # Check that BOARD has been provided, and that it has not changed. zephyr_check_cache(BOARD REQUIRED) @@ -387,21 +384,7 @@ if(DEFINED SHIELD AND NOT (SHIELD-NOTFOUND STREQUAL "")) message(FATAL_ERROR "Invalid SHIELD; see above.") endif() -get_filename_component(BOARD_ARCH_DIR ${BOARD_DIR} DIRECTORY) -get_filename_component(ARCH ${BOARD_ARCH_DIR} NAME) - -foreach(root ${ARCH_ROOT}) - if(EXISTS ${root}/arch/${ARCH}/CMakeLists.txt) - set(ARCH_DIR ${root}/arch) - break() - endif() -endforeach() - -if(NOT ARCH_DIR) - message(FATAL_ERROR "Could not find ARCH=${ARCH} for BOARD=${BOARD}, \ -please check your installation. ARCH roots searched: \n\ -${ARCH_ROOT}") -endif() +include(${ZEPHYR_BASE}/cmake/arch.cmake) if(DEFINED APPLICATION_CONFIG_DIR) string(CONFIGURE ${APPLICATION_CONFIG_DIR} APPLICATION_CONFIG_DIR) diff --git a/cmake/arch.cmake b/cmake/arch.cmake new file mode 100644 index 0000000000..71f2c96c1b --- /dev/null +++ b/cmake/arch.cmake @@ -0,0 +1,44 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# Copyright (c) 2022, Nordic Semiconductor ASA + +# Configure ARCH settings based on board directory and arch root. +# +# This CMake module will set the following variables in the build system based +# on board directory and arch root. +# +# If no implementation is available for the current arch an error will be raised. +# +# Outcome: +# The following variables will be defined when this CMake module completes: +# +# - ARCH: Name of the arch in use. +# - ARCH_DIR: Directory containing the arch implementation. +# - ARCH_ROOT: ARCH_ROOT with ZEPHYR_BASE appended +# +# Variable dependencies: +# - ARCH_ROOT: CMake list of arch roots containing arch implementations +# - BOARD_DIR: CMake variable specifying the directory of the selected BOARD +# +# Variables set by this module and not mentioned above are considered internal +# use only and may be removed, renamed, or re-purposed without prior notice. + +# 'ARCH_ROOT' is a prioritized list of directories where archs may be +# found. It always includes ${ZEPHYR_BASE} at the lowest priority. +list(APPEND ARCH_ROOT ${ZEPHYR_BASE}) + +cmake_path(GET BOARD_DIR PARENT_PATH board_arch_dir) +cmake_path(GET board_arch_dir FILENAME ARCH) + +foreach(root ${ARCH_ROOT}) + if(EXISTS ${root}/arch/${ARCH}/CMakeLists.txt) + set(ARCH_DIR ${root}/arch) + break() + endif() +endforeach() + +if(NOT ARCH_DIR) + message(FATAL_ERROR "Could not find ARCH=${ARCH} for BOARD=${BOARD}, \ +please check your installation. ARCH roots searched: \n\ +${ARCH_ROOT}") +endif()