| # SPDX-License-Identifier: Apache-2.0 |
| # |
| # Copyright (c) 2021, Nordic Semiconductor ASA |
| |
| # This CMake module will load all Zephyr CMake modules in correct order for |
| # default Zephyr build system. |
| # |
| # Outcome: |
| # See individual CMake module descriptions |
| |
| include_guard(GLOBAL) |
| |
| # The code line below defines the real minimum supported CMake version. |
| # |
| # Unfortunately CMake requires the toplevel CMakeLists.txt file to define the |
| # required version, not even invoking it from a CMake module is sufficient. |
| # It is however permitted to have multiple invocations of cmake_minimum_required. |
| cmake_minimum_required(VERSION 3.20.0) |
| |
| message(STATUS "Application: ${APPLICATION_SOURCE_DIR}") |
| |
| # Different CMake versions can have very subtle differences, for |
| # instance CMake 3.21 links object files in a different order compared |
| # to CMake 3.20; this produces different binaries. |
| message(STATUS "CMake version: ${CMAKE_VERSION}") |
| |
| # Find and execute workspace build configuration |
| find_package(ZephyrBuildConfiguration |
| QUIET NO_POLICY_SCOPE |
| NAMES ZephyrBuild |
| PATHS ${ZEPHYR_BASE}/../* |
| NO_CMAKE_PATH |
| NO_CMAKE_ENVIRONMENT_PATH |
| NO_SYSTEM_ENVIRONMENT_PATH |
| NO_CMAKE_PACKAGE_REGISTRY |
| NO_CMAKE_SYSTEM_PATH |
| NO_CMAKE_SYSTEM_PACKAGE_REGISTRY |
| ) |
| |
| # Find and execute application-specific build configuration |
| find_package(ZephyrAppConfiguration |
| QUIET NO_POLICY_SCOPE |
| NAMES ZephyrApp |
| PATHS ${APPLICATION_SOURCE_DIR} |
| NO_CMAKE_PATH |
| NO_CMAKE_ENVIRONMENT_PATH |
| NO_SYSTEM_ENVIRONMENT_PATH |
| NO_CMAKE_PACKAGE_REGISTRY |
| NO_CMAKE_SYSTEM_PATH |
| NO_CMAKE_SYSTEM_PACKAGE_REGISTRY |
| ) |
| |
| # Test and error-out if we are affected by the PyPI CMake 3.22.1 / 3.22.2 bug |
| if(${CMAKE_VERSION} VERSION_EQUAL 3.22.1 OR ${CMAKE_VERSION} VERSION_EQUAL 3.22.2) |
| # It seems only pip-installed builds are affected so we test to see if we are affected |
| cmake_path(GET ZEPHYR_BASE PARENT_PATH test_cmake_path) |
| if(ZEPHYR_BASE STREQUAL test_cmake_path) |
| message(FATAL_ERROR "The CMake version ${CMAKE_VERSION} installed suffers" |
| " the \n 'cmake_path(... PARENT_PATH)' bug, see: \n" |
| "https://gitlab.kitware.com/cmake/cmake/-/issues/23187\n" |
| "https://github.com/scikit-build/cmake-python-distributions/issues/221\n" |
| "Please install another CMake version or use a build of CMake that" |
| " does not come from PyPI." |
| ) |
| endif() |
| endif() |
| |
| # Prepare user cache |
| list(APPEND zephyr_cmake_modules python) |
| list(APPEND zephyr_cmake_modules user_cache) |
| |
| # Load Zephyr extensions |
| list(APPEND zephyr_cmake_modules extensions) |
| list(APPEND zephyr_cmake_modules version) |
| |
| # Load basic settings |
| list(APPEND zephyr_cmake_modules basic_settings) |
| |
| # |
| # Find tools |
| # |
| |
| list(APPEND zephyr_cmake_modules west) |
| list(APPEND zephyr_cmake_modules ccache) |
| list(APPEND zephyr_cmake_modules yaml) |
| |
| # Load default root settings |
| list(APPEND zephyr_cmake_modules root) |
| |
| # |
| # Find Zephyr modules. |
| # Those may contain additional DTS, BOARD, SOC, ARCH ROOTs. |
| # Also create the Kconfig binary dir for generated Kconf files. |
| # |
| list(APPEND zephyr_cmake_modules zephyr_module) |
| |
| list(APPEND zephyr_cmake_modules boards) |
| list(APPEND zephyr_cmake_modules shields) |
| 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 configuration_files) |
| list(APPEND zephyr_cmake_modules generated_file_directories) |
| |
| # Include board specific device-tree flags before parsing. |
| set(pre_dt_board "\${BOARD_DIR}/pre_dt_board.cmake" OPTIONAL) |
| list(APPEND zephyr_cmake_modules "\${pre_dt_board}") |
| |
| # DTS should be close to kconfig because CONFIG_ variables from |
| # kconfig and dts should be available at the same time. |
| list(APPEND zephyr_cmake_modules dts) |
| list(APPEND zephyr_cmake_modules kconfig) |
| 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}) |
| if(NOT ${component} IN_LIST zephyr_cmake_modules) |
| message(FATAL_ERROR |
| "Subcomponent '${component}' not default module for Zephyr CMake build system.\n" |
| "Please choose one or more valid components: ${zephyr_cmake_modules}" |
| ) |
| endif() |
| endforeach() |
| |
| foreach(module IN LISTS zephyr_cmake_modules) |
| # Ensures any module of type `${module}` are properly expanded to list before |
| # passed on the `include(${module})`. |
| # This is done twice to support cases where the content of `${module}` itself |
| # contains a variable, like `${BOARD_DIR}`. |
| string(CONFIGURE "${module}" module) |
| string(CONFIGURE "${module}" module) |
| include(${module}) |
| |
| list(REMOVE_ITEM SUB_COMPONENTS ${module}) |
| if(DEFINED SUB_COMPONENTS AND NOT SUB_COMPONENTS) |
| # All requested Zephyr CMake modules have been loaded, so let's return. |
| return() |
| endif() |
| endforeach() |
| |
| include(kernel) |