From ab7ec17b865f60625e6d3bf146ff93431ba68407 Mon Sep 17 00:00:00 2001 From: Torsten Rasmussen Date: Tue, 25 Aug 2020 13:32:33 +0200 Subject: [PATCH] cmake: zephyr module processing improvements. This commit improves Zephyr modules support in CMake. All Zephyr modules will now have a corresponding `ZEPHYR_${module_name}_MODULE_DIR` set, regardless of whether they define a cmake folder in module.yml. This results in: `ZEPHYR_${module_name}_MODULE_DIR` defined for all modules and refers to the root of the modle. `ZEPHYR_${module_name}_CMAKE_DIR` defined for modules that specifies cmake in module.yml, or is having both a CMakeLists.txt and Kconfig file in the zephyr folder. Signed-off-by: Torsten Rasmussen --- CMakeLists.txt | 10 +++++++--- cmake/zephyr_module.cmake | 6 ++++-- scripts/zephyr_module.py | 9 +++++---- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 323cb9b4e5a..5dc666f6e57 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -470,11 +470,15 @@ foreach(module_name ${ZEPHYR_MODULE_NAMES}) # the main binary dir instead. # https://cmake.org/pipermail/cmake/2019-June/069547.html string(TOUPPER ${module_name} MODULE_NAME_UPPER) - set(ZEPHYR_CURRENT_MODULE_DIR ${ZEPHYR_${MODULE_NAME_UPPER}_MODULE_DIR}) - add_subdirectory(${ZEPHYR_CURRENT_MODULE_DIR} ${CMAKE_BINARY_DIR}/modules/${module_name}) + if(NOT ${ZEPHYR_${MODULE_NAME_UPPER}_CMAKE_DIR} STREQUAL "") + set(ZEPHYR_CURRENT_MODULE_DIR ${ZEPHYR_${MODULE_NAME_UPPER}_MODULE_DIR}) + set(ZEPHYR_CURRENT_CMAKE_DIR ${ZEPHYR_${MODULE_NAME_UPPER}_CMAKE_DIR}) + add_subdirectory(${ZEPHYR_CURRENT_CMAKE_DIR} ${CMAKE_BINARY_DIR}/modules/${module_name}) + endif() endforeach() -# Done processing modules, clear ZEPHYR_CURRENT_MODULE_DIR. +# Done processing modules, clear ZEPHYR_CURRENT_MODULE_DIR and ZEPHYR_CURRENT_CMAKE_DIR. set(ZEPHYR_CURRENT_MODULE_DIR) +set(ZEPHYR_CURRENT_CMAKE_DIR) set(syscall_list_h ${CMAKE_CURRENT_BINARY_DIR}/include/generated/syscall_list.h) set(syscalls_json ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/syscalls.json) diff --git a/cmake/zephyr_module.cmake b/cmake/zephyr_module.cmake index f72964411c5..e35a327ee76 100644 --- a/cmake/zephyr_module.cmake +++ b/cmake/zephyr_module.cmake @@ -69,13 +69,15 @@ if(WEST OR ZEPHYR_MODULES) # 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). - string(REGEX REPLACE "\"(.*)\":\".*\"" "\\1" module_name ${module}) - string(REGEX REPLACE "\".*\":\"(.*)\"" "\\1" module_path ${module}) + string(REGEX REPLACE "\"(.*)\":\".*\":\".*\"" "\\1" module_name ${module}) + string(REGEX REPLACE "\".*\":\"(.*)\":\".*\"" "\\1" module_path ${module}) + string(REGEX REPLACE "\".*\":\".*\":\"(.*)\"" "\\1" cmake_path ${module}) list(APPEND ZEPHYR_MODULE_NAMES ${module_name}) string(TOUPPER ${module_name} MODULE_NAME_UPPER) set(ZEPHYR_${MODULE_NAME_UPPER}_MODULE_DIR ${module_path}) + set(ZEPHYR_${MODULE_NAME_UPPER}_CMAKE_DIR ${cmake_path}) endforeach() endif() else() diff --git a/scripts/zephyr_module.py b/scripts/zephyr_module.py index 65d29ed27d7..b34cdba2036 100755 --- a/scripts/zephyr_module.py +++ b/scripts/zephyr_module.py @@ -135,12 +135,14 @@ def process_cmake(module, meta): cmake_path = os.path.join(module, cmake_setting or 'zephyr') cmake_file = os.path.join(cmake_path, 'CMakeLists.txt') if os.path.isfile(cmake_file): - return('\"{}\":\"{}\"\n' + return('\"{}\":\"{}\":\"{}\"\n' .format(module_path.name, + module_path.as_posix(), Path(cmake_path).resolve().as_posix())) else: - return "" - + return('\"{}\":\"{}\":\"\"\n' + .format(module_path.name, + module_path.as_posix())) def process_settings(module, meta): section = meta.get('build', dict()) @@ -175,7 +177,6 @@ def process_kconfig(module, meta): else: return "" - def process_sanitycheck(module, meta): out = ""