From 7f6bb02287e53146da5851badda39856601f412f Mon Sep 17 00:00:00 2001 From: Torsten Rasmussen Date: Thu, 16 Dec 2021 09:58:13 +0100 Subject: [PATCH] cmake: create a soc.cmake module The soc.cmake CMake module remove boilerplate code and place it inside a dedicated soc.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 | 40 +--------------------- cmake/soc.cmake | 67 +++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 39 deletions(-) create mode 100644 cmake/soc.cmake diff --git a/cmake/app/boilerplate.cmake b/cmake/app/boilerplate.cmake index 07a975f34a..36216abd30 100644 --- a/cmake/app/boilerplate.cmake +++ b/cmake/app/boilerplate.cmake @@ -180,10 +180,7 @@ zephyr_linker_sources(SECTIONS) zephyr_file(APPLICATION_ROOT BOARD_ROOT) list(APPEND BOARD_ROOT ${ZEPHYR_BASE}) -# 'SOC_ROOT' is a prioritized list of directories where socs may be -# found. It always includes ${ZEPHYR_BASE}/soc at the lowest priority. zephyr_file(APPLICATION_ROOT SOC_ROOT) -list(APPEND SOC_ROOT ${ZEPHYR_BASE}) # 'ARCH_ROOT' is a prioritized list of directories where archs may be # found. It always includes ${ZEPHYR_BASE} at the lowest priority. @@ -526,11 +523,7 @@ zephyr_boilerplate_watch(DTC_OVERLAY_FILE) include(${ZEPHYR_BASE}/cmake/generic_toolchain.cmake) include(${ZEPHYR_BASE}/cmake/dts.cmake) include(${ZEPHYR_BASE}/cmake/kconfig.cmake) - -set(SOC_NAME ${CONFIG_SOC}) -set(SOC_SERIES ${CONFIG_SOC_SERIES}) -set(SOC_TOOLCHAIN_NAME ${CONFIG_SOC_TOOLCHAIN_NAME}) -set(SOC_FAMILY ${CONFIG_SOC_FAMILY}) +include(${ZEPHYR_BASE}/cmake/soc.cmake) # For the gen_app_partitions.py to work correctly, we must ensure that # all targets exports their compile commands to fetch object files. @@ -539,37 +532,6 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE CACHE BOOL "Export CMake compile commands. Used by gen_app_partitions.py script" FORCE ) - -if("${SOC_SERIES}" STREQUAL "") - set(SOC_PATH ${SOC_NAME}) -else() - set(SOC_PATH ${SOC_FAMILY}/${SOC_SERIES}) -endif() - -# Use SOC to search for a 'CMakeLists.txt' file. -# e.g. zephyr/soc/xtensa/intel_adsp/CMakeLists.txt. -foreach(root ${SOC_ROOT}) - # Check that the root looks reasonable. - if(NOT IS_DIRECTORY "${root}/soc") - message(WARNING "SOC_ROOT element without a 'soc' subdirectory: -${root} -Hints: - - if your SoC family directory is '/foo/bar/soc//my_soc_family', then add '/foo/bar' to SOC_ROOT, not the entire SoC family path - - if in doubt, use absolute paths") - endif() - - if(EXISTS ${root}/soc/${ARCH}/${SOC_PATH}) - set(SOC_DIR ${root}/soc) - break() - endif() -endforeach() - -if(NOT SOC_DIR) - message(FATAL_ERROR "Could not find SOC=${SOC_NAME} for BOARD=${BOARD}, \ -please check your installation. SOC roots searched: \n\ -${SOC_ROOT}") -endif() - include(${ZEPHYR_BASE}/cmake/target_toolchain.cmake) project(Zephyr-Kernel VERSION ${PROJECT_VERSION}) diff --git a/cmake/soc.cmake b/cmake/soc.cmake new file mode 100644 index 0000000000..017af21857 --- /dev/null +++ b/cmake/soc.cmake @@ -0,0 +1,67 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# Copyright (c) 2021, Nordic Semiconductor ASA + +# Configure SoC settings based on Kconfig settings and SoC root. +# +# This CMake module will set the following variables in the build system based +# on Kconfig settings and selected SoC. +# +# If no implementation is available for the selected SoC an error will be raised. +# +# Outcome: +# The following variables will be defined when this CMake module completes: +# +# - SOC_NAME: Name of the SoC in use, identical to CONFIG_SOC +# - SOC_SERIES: Name of the SoC series in use, identical to CONFIG_SOC_SERIES +# - SOC_FAMILY: Name of the SoC family, identical to CONFIG_SOC_FAMILY +# - SOC_PATH: Path fragment defined by either SOC_NAME or SOC_FAMILY/SOC_SERIES. +# - SOC_DIR: Directory containing the SoC implementation +# - SOC_ROOT: SOC_ROOT with ZEPHYR_BASE appended +# +# Variable dependencies: +# - SOC_ROOT: CMake list of SoC roots containing SoC implementations +# +# 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. + +# 'SOC_ROOT' is a prioritized list of directories where socs may be +# found. It always includes ${ZEPHYR_BASE}/soc at the lowest priority. +list(APPEND SOC_ROOT ${ZEPHYR_BASE}) + +set(SOC_NAME ${CONFIG_SOC}) +set(SOC_SERIES ${CONFIG_SOC_SERIES}) +set(SOC_TOOLCHAIN_NAME ${CONFIG_SOC_TOOLCHAIN_NAME}) +set(SOC_FAMILY ${CONFIG_SOC_FAMILY}) + +if("${SOC_SERIES}" STREQUAL "") + set(SOC_PATH ${SOC_NAME}) +else() + set(SOC_PATH ${SOC_FAMILY}/${SOC_SERIES}) +endif() + +# Use SOC to search for a 'CMakeLists.txt' file. +# e.g. zephyr/soc/xtensa/intel_adsp/CMakeLists.txt. +foreach(root ${SOC_ROOT}) + # Check that the root looks reasonable. + if(NOT IS_DIRECTORY "${root}/soc") + message(WARNING "\nSOC_ROOT element(s) without a 'soc' subdirectory: +${root} +Hints: + - if your SoC family directory is '/foo/bar/soc//my_soc_family', then add '/foo/bar' to SOC_ROOT, not the entire SoC family path + - if in doubt, use absolute paths\n") + endif() + + if(EXISTS ${root}/soc/${ARCH}/${SOC_PATH}) + set(SOC_DIR ${root}/soc) + break() + endif() +endforeach() + +if(NOT SOC_DIR) + message(FATAL_ERROR "Could not find SOC=${SOC_NAME} for BOARD=${BOARD},\n" + "please check your installation.\n" + "SOC roots searched:\n" + "${SOC_ROOT}\n" + ) +endif()