diff --git a/cmake/app/boilerplate.cmake b/cmake/app/boilerplate.cmake index 5eeda7586f9..eaa0e73dfd5 100644 --- a/cmake/app/boilerplate.cmake +++ b/cmake/app/boilerplate.cmake @@ -71,13 +71,7 @@ include(${ZEPHYR_BASE}/cmake/python.cmake) include(${ZEPHYR_BASE}/cmake/west.cmake) include(${ZEPHYR_BASE}/cmake/ccache.cmake) -# 'MODULE_EXT_ROOT' is a prioritized list of directories where module glue code -# may be found. It always includes ${ZEPHYR_BASE} at the lowest priority. -# For module roots, later entries may overrule module settings already defined -# by processed module roots, hence first in list means lowest priority. -zephyr_file(APPLICATION_ROOT MODULE_EXT_ROOT) -list(INSERT MODULE_EXT_ROOT 0 ${ZEPHYR_BASE}) - +include(${ZEPHYR_BASE}/cmake/root.cmake) # # Find Zephyr modules. # Those may contain additional DTS, BOARD, SOC, ARCH ROOTs. @@ -85,12 +79,6 @@ list(INSERT MODULE_EXT_ROOT 0 ${ZEPHYR_BASE}) # include(${ZEPHYR_BASE}/cmake/zephyr_module.cmake) -zephyr_file(APPLICATION_ROOT BOARD_ROOT) - -zephyr_file(APPLICATION_ROOT SOC_ROOT) - -zephyr_file(APPLICATION_ROOT ARCH_ROOT) - include(${ZEPHYR_BASE}/cmake/boards.cmake) include(${ZEPHYR_BASE}/cmake/shields.cmake) include(${ZEPHYR_BASE}/cmake/arch.cmake) diff --git a/cmake/root.cmake b/cmake/root.cmake new file mode 100644 index 00000000000..a03e41ad093 --- /dev/null +++ b/cmake/root.cmake @@ -0,0 +1,30 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# Copyright (c) 2021, Nordic Semiconductor ASA + +# Convert Zephyr roots to absolute paths. +# +# This CMake module will convert all relative paths in existing ROOT lists to +# absolute path relative from APPLICATION_SOURCE_DIR. +# +# Optional variables: +# - ARCH_ROOT: CMake list of arch roots containing arch implementations +# - SOC_ROOT: CMake list of SoC roots containing SoC implementations +# - BOARD_ROOT: CMake list of board roots containing board and shield implementations +# - MODULE_EXT_ROOT: CMake list of module external roots containing module glue code +# +# If a root is defined it will check the list of paths in the root and convert +# any relative path to absolute path and update the root list. +# If a root is undefined it will still be undefined when this module has loaded. + +# Convert paths to absolute, relative from APPLICATION_SOURCE_DIR +zephyr_file(APPLICATION_ROOT MODULE_EXT_ROOT) + +# Convert paths to absolute, relative from APPLICATION_SOURCE_DIR +zephyr_file(APPLICATION_ROOT BOARD_ROOT) + +# Convert paths to absolute, relative from APPLICATION_SOURCE_DIR +zephyr_file(APPLICATION_ROOT SOC_ROOT) + +# Convert paths to absolute, relative from APPLICATION_SOURCE_DIR +zephyr_file(APPLICATION_ROOT ARCH_ROOT) diff --git a/cmake/zephyr_module.cmake b/cmake/zephyr_module.cmake index 63611c31d7c..7377aee072a 100644 --- a/cmake/zephyr_module.cmake +++ b/cmake/zephyr_module.cmake @@ -3,17 +3,17 @@ # This cmake file provides functionality to import CMakeLists.txt and Kconfig # files for Zephyr modules into Zephyr build system. # -# CMakeLists.txt and Kconfig files can reside directly in the module or in a -# MODULE_EXT_ROOT. +# CMakeLists.txt and Kconfig files can reside directly in the Zephyr module or +# in a MODULE_EXT_ROOT. # The `/zephyr/module.yml` file specifies whether the build files are -# located in the module or in a MODULE_EXT_ROOT. +# located in the Zephyr module or in a MODULE_EXT_ROOT. # # A list of Zephyr modules can be provided to the build system using: # -DZEPHYR_MODULES=[;] # # It looks for: /zephyr/module.yml or # /zephyr/CMakeLists.txt -# to load the module into Zephyr build system. +# to load the Zephyr module into Zephyr build system. # If west is available, it uses `west list` to obtain a list of projects to # search for zephyr/module.yml # @@ -81,17 +81,13 @@ if(WEST OR ZEPHYR_MODULES) # lazy regexes (it supports greedy only). string(REGEX REPLACE "\"(.*)\":\".*\"" "\\1" key ${setting}) string(REGEX REPLACE "\".*\":\"(.*)\"" "\\1" value ${setting}) - # MODULE_EXT_ROOT is process order which means module roots processed - # later wins. To ensure ZEPHYR_BASE stays first, and command line settings - # are processed last, we insert at position 1. - if ("${key}" STREQUAL "MODULE_EXT_ROOT") - list(INSERT ${key} 1 ${value}) - else() - list(APPEND ${key} ${value}) - endif() + list(APPEND ${key} ${value}) endforeach() endif() + # Append ZEPHYR_BASE as a default ext root at lowest priority + list(APPEND MODULE_EXT_ROOT ${ZEPHYR_BASE}) + if(EXISTS ${CMAKE_BINARY_DIR}/zephyr_modules.txt) file(STRINGS ${CMAKE_BINARY_DIR}/zephyr_modules.txt ZEPHYR_MODULES_TXT ENCODING UTF-8) @@ -106,6 +102,9 @@ if(WEST OR ZEPHYR_MODULES) endforeach() endif() + # MODULE_EXT_ROOT is process order which means Zephyr module roots processed + # later wins. therefore we reverse the list before processing. + list(REVERSE MODULE_EXT_ROOT) foreach(root ${MODULE_EXT_ROOT}) if(NOT EXISTS ${root}) message(FATAL_ERROR "No `modules.cmake` found in module root `${root}`.") @@ -117,8 +116,8 @@ if(WEST OR ZEPHYR_MODULES) if(DEFINED ZEPHYR_MODULES_TXT) foreach(module ${ZEPHYR_MODULES_TXT}) # Match "":"" for each line of file, each corresponding to - # one module. The use of quotes is required due to CMake not supporting - # lazy regexes (it supports greedy only). + # one Zephyr module. The use of quotes is required due to CMake not + # supporting lazy regexes (it supports greedy only). string(CONFIGURE ${module} module) string(REGEX REPLACE "\"(.*)\":\".*\":\".*\"" "\\1" module_name ${module}) string(REGEX REPLACE "\".*\":\"(.*)\":\".*\"" "\\1" module_path ${module}) @@ -138,7 +137,7 @@ ${MODULE_NAME_UPPER} is a restricted name for Zephyr modules as it is used for \ else() file(WRITE ${KCONFIG_MODULES_FILE} - "# No west and no modules\n" + "# No west and no Zephyr modules\n" ) endif()