Browse Source

cmake: introduce arch and soc cmake modules for hw model v2

Introduce dedicated arch and soc hw model v2 CMake module files.

Rename existing arch and soc cmake file to have a `_v1` post fix.
This help to identify the purpose of each of those files and thus a
cleaner implementation.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
pull/69687/head
Torsten Rasmussen 2 years ago committed by Jamie McCrae
parent
commit
bd854a3af8
  1. 36
      cmake/modules/arch_v1.cmake
  2. 41
      cmake/modules/arch_v2.cmake
  3. 71
      cmake/modules/soc.cmake
  4. 73
      cmake/modules/soc_v1.cmake
  5. 29
      cmake/modules/soc_v2.cmake
  6. 6
      cmake/modules/zephyr_default.cmake

36
cmake/modules/arch.cmake → cmake/modules/arch_v1.cmake

@ -2,6 +2,10 @@
# #
# Copyright (c) 2022, Nordic Semiconductor ASA # Copyright (c) 2022, Nordic Semiconductor ASA
#
# This CMake module is only valid for hw model v1.
# In hw model v1, then arch is determined by the board folder structure.
#
# Configure ARCH settings based on board directory and arch root. # Configure ARCH settings based on board directory and arch root.
# #
# This CMake module will set the following variables in the build system based # This CMake module will set the following variables in the build system based
@ -25,24 +29,26 @@
include_guard(GLOBAL) include_guard(GLOBAL)
# 'ARCH_ROOT' is a prioritized list of directories where archs may be if(HWMv1)
# found. It always includes ${ZEPHYR_BASE} at the lowest priority (except for unittesting). # 'ARCH_ROOT' is a prioritized list of directories where archs may be
if(NOT unittest IN_LIST Zephyr_FIND_COMPONENTS) # found. It always includes ${ZEPHYR_BASE} at the lowest priority (except for unittesting).
list(APPEND ARCH_ROOT ${ZEPHYR_BASE}) if(NOT unittest IN_LIST Zephyr_FIND_COMPONENTS)
endif() list(APPEND ARCH_ROOT ${ZEPHYR_BASE})
endif()
cmake_path(GET BOARD_DIR PARENT_PATH board_arch_dir) cmake_path(GET BOARD_DIR PARENT_PATH board_arch_dir)
cmake_path(GET board_arch_dir FILENAME ARCH) cmake_path(GET board_arch_dir FILENAME ARCH)
foreach(root ${ARCH_ROOT}) foreach(root ${ARCH_ROOT})
if(EXISTS ${root}/arch/${ARCH}/CMakeLists.txt) if(EXISTS ${root}/arch/${ARCH}/CMakeLists.txt)
set(ARCH_DIR ${root}/arch) set(ARCH_DIR ${root}/arch)
break() break()
endif() endif()
endforeach() endforeach()
if(NOT ARCH_DIR) if(NOT ARCH_DIR)
message(FATAL_ERROR "Could not find ARCH=${ARCH} for BOARD=${BOARD}, \ message(FATAL_ERROR "Could not find ARCH=${ARCH} for BOARD=${BOARD}, \
please check your installation. ARCH roots searched: \n\ please check your installation. ARCH roots searched: \n\
${ARCH_ROOT}") ${ARCH_ROOT}")
endif()
endif() endif()

41
cmake/modules/arch_v2.cmake

@ -0,0 +1,41 @@
# SPDX-License-Identifier: Apache-2.0
#
# Copyright (c) 2023, Nordic Semiconductor ASA
#
# Configure ARCH settings based on KConfig settings 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
#
# 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.
include_guard(GLOBAL)
if(HWMv2)
# HWMv2 obtains arch from Kconfig for the given Board / SoC variant because
# the Board / SoC path is no longer sufficient for determine the arch
# (read: multi-core and multi-arch SoC).
set(ARCH ${CONFIG_ARCH})
string(TOUPPER "${ARCH}" arch_upper)
cmake_path(GET ARCH_V2_${arch_upper}_DIR PARENT_PATH ARCH_DIR)
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()
endif()

71
cmake/modules/soc.cmake

@ -1,71 +0,0 @@
# 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.
include_guard(GLOBAL)
include(kconfig)
# '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/<ARCH>/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()

73
cmake/modules/soc_v1.cmake

@ -0,0 +1,73 @@
# 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.
include_guard(GLOBAL)
include(kconfig)
if(HWMv1)
# '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/<ARCH>/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()
endif()

29
cmake/modules/soc_v2.cmake

@ -0,0 +1,29 @@
# SPDX-License-Identifier: Apache-2.0
#
# Copyright (c) 2021, Nordic Semiconductor ASA
# Configure SoC settings based on Kconfig settings.
#
# This CMake module will set the following variables in the build system based
# on Kconfig settings for the selected SoC.
#
# 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
#
# 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.
include_guard(GLOBAL)
include(kconfig)
if(HWMv2)
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})
endif()

6
cmake/modules/zephyr_default.cmake

@ -96,8 +96,8 @@ list(APPEND zephyr_cmake_modules zephyr_module)
list(APPEND zephyr_cmake_modules boards) list(APPEND zephyr_cmake_modules boards)
list(APPEND zephyr_cmake_modules shields) list(APPEND zephyr_cmake_modules shields)
list(APPEND zephyr_cmake_modules snippets) list(APPEND zephyr_cmake_modules snippets)
list(APPEND zephyr_cmake_modules arch_v1)
list(APPEND zephyr_cmake_modules hwm_v2) list(APPEND zephyr_cmake_modules hwm_v2)
list(APPEND zephyr_cmake_modules arch)
list(APPEND zephyr_cmake_modules configuration_files) list(APPEND zephyr_cmake_modules configuration_files)
list(APPEND zephyr_cmake_modules generated_file_directories) list(APPEND zephyr_cmake_modules generated_file_directories)
@ -109,7 +109,9 @@ list(APPEND zephyr_cmake_modules "\${pre_dt_board}")
# kconfig and dts should be available at the same time. # kconfig and dts should be available at the same time.
list(APPEND zephyr_cmake_modules dts) list(APPEND zephyr_cmake_modules dts)
list(APPEND zephyr_cmake_modules kconfig) list(APPEND zephyr_cmake_modules kconfig)
list(APPEND zephyr_cmake_modules soc) list(APPEND zephyr_cmake_modules arch_v2)
list(APPEND zephyr_cmake_modules soc_v1)
list(APPEND zephyr_cmake_modules soc_v2)
foreach(component ${SUB_COMPONENTS}) foreach(component ${SUB_COMPONENTS})
if(NOT ${component} IN_LIST zephyr_cmake_modules) if(NOT ${component} IN_LIST zephyr_cmake_modules)

Loading…
Cancel
Save