Skip to content

Commit 08eabb8

Browse files
tejlmandcarlescufi
authored andcommitted
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 <[email protected]>
1 parent e413617 commit 08eabb8

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

CMakeLists.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,20 +457,30 @@ add_subdirectory(drivers)
457457
if(EXISTS ${CMAKE_BINARY_DIR}/zephyr_modules.txt)
458458
file(STRINGS ${CMAKE_BINARY_DIR}/zephyr_modules.txt ZEPHYR_MODULES_TXT
459459
ENCODING UTF-8)
460+
set(module_names)
460461

461462
foreach(module ${ZEPHYR_MODULES_TXT})
462463
# Match "<name>":"<path>" for each line of file, each corresponding to
463464
# one module. The use of quotes is required due to CMake not supporting
464465
# lazy regexes (it supports greedy only).
465466
string(REGEX REPLACE "\"(.*)\":\".*\"" "\\1" module_name ${module})
466467
string(REGEX REPLACE "\".*\":\"(.*)\"" "\\1" module_path ${module})
468+
469+
list(APPEND module_names ${module_name})
470+
471+
string(TOUPPER ${module_name} MODULE_NAME_UPPER)
472+
set(ZEPHYR_${MODULE_NAME_UPPER}_MODULE_DIR ${module_path})
473+
endforeach()
474+
475+
foreach(module_name ${module_names})
467476
# Note the second, binary_dir parameter requires the added
468477
# subdirectory to have its own, local cmake target(s). If not then
469478
# this binary_dir is created but stays empty. Object files land in
470479
# the main binary dir instead.
471480
# https://cmake.org/pipermail/cmake/2019-June/069547.html
472-
set(ZEPHYR_CURRENT_MODULE_DIR ${module_path})
473-
add_subdirectory(${module_path} ${CMAKE_BINARY_DIR}/modules/${module_name})
481+
string(TOUPPER ${module_name} MODULE_NAME_UPPER)
482+
set(ZEPHYR_CURRENT_MODULE_DIR ${ZEPHYR_${MODULE_NAME_UPPER}_MODULE_DIR})
483+
add_subdirectory(${ZEPHYR_CURRENT_MODULE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/modules/${module_name})
474484
endforeach()
475485
# Done processing modules, clear ZEPHYR_CURRENT_MODULE_DIR.
476486
set(ZEPHYR_CURRENT_MODULE_DIR)

0 commit comments

Comments
 (0)