From 08eabb83b23a02872abca1e007ead4d01bf48dd6 Mon Sep 17 00:00:00 2001 From: Torsten Rasmussen Date: Fri, 6 Dec 2019 12:19:35 +0100 Subject: [PATCH] cmake: Zephyr module processing set modules path This commit introduces the variable: ZEPHYR_${MODULE}_MODULE_DIR that can be used for modules to obtain locations of other modules. As example: a module which requires the knowledge of mcuboot con now fetch this information using ZEPHYR_MCUBOOT_MODULE_DIR. Signed-off-by: Torsten Rasmussen --- CMakeLists.txt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1df92c5707b..167c885f7a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -457,6 +457,7 @@ add_subdirectory(drivers) if(EXISTS ${CMAKE_BINARY_DIR}/zephyr_modules.txt) file(STRINGS ${CMAKE_BINARY_DIR}/zephyr_modules.txt ZEPHYR_MODULES_TXT ENCODING UTF-8) + set(module_names) foreach(module ${ZEPHYR_MODULES_TXT}) # Match "":"" for each line of file, each corresponding to @@ -464,13 +465,22 @@ if(EXISTS ${CMAKE_BINARY_DIR}/zephyr_modules.txt) # lazy regexes (it supports greedy only). string(REGEX REPLACE "\"(.*)\":\".*\"" "\\1" module_name ${module}) string(REGEX REPLACE "\".*\":\"(.*)\"" "\\1" module_path ${module}) + + list(APPEND module_names ${module_name}) + + string(TOUPPER ${module_name} MODULE_NAME_UPPER) + set(ZEPHYR_${MODULE_NAME_UPPER}_MODULE_DIR ${module_path}) + endforeach() + + foreach(module_name ${module_names}) # Note the second, binary_dir parameter requires the added # subdirectory to have its own, local cmake target(s). If not then # this binary_dir is created but stays empty. Object files land in # the main binary dir instead. # https://cmake.org/pipermail/cmake/2019-June/069547.html - set(ZEPHYR_CURRENT_MODULE_DIR ${module_path}) - add_subdirectory(${module_path} ${CMAKE_BINARY_DIR}/modules/${module_name}) + 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_CURRENT_BINARY_DIR}/modules/${module_name}) endforeach() # Done processing modules, clear ZEPHYR_CURRENT_MODULE_DIR. set(ZEPHYR_CURRENT_MODULE_DIR)