diff --git a/CMakeLists.txt b/CMakeLists.txt index 6985507aa3f..323cb9b4e5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -463,38 +463,18 @@ add_subdirectory(subsys) add_subdirectory(drivers) # Include zephyr modules generated CMake file. -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 - # 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}) - - list(APPEND 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}_MODULE_DIR ${module_path} PARENT_SCOPE) - 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 - 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}) - endforeach() - # Done processing modules, clear ZEPHYR_CURRENT_MODULE_DIR. - set(ZEPHYR_CURRENT_MODULE_DIR) -endif() +foreach(module_name ${ZEPHYR_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 + 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}) +endforeach() +# Done processing modules, clear ZEPHYR_CURRENT_MODULE_DIR. +set(ZEPHYR_CURRENT_MODULE_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 933a0a569ed..f72964411c5 100644 --- a/cmake/zephyr_module.cmake +++ b/cmake/zephyr_module.cmake @@ -60,6 +60,24 @@ if(WEST OR ZEPHYR_MODULES) endforeach() endif() + if(EXISTS ${CMAKE_BINARY_DIR}/zephyr_modules.txt) + file(STRINGS ${CMAKE_BINARY_DIR}/zephyr_modules.txt ZEPHYR_MODULES_TXT + ENCODING UTF-8) + set(ZEPHYR_MODULE_NAMES) + + 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). + string(REGEX REPLACE "\"(.*)\":\".*\"" "\\1" module_name ${module}) + string(REGEX REPLACE "\".*\":\"(.*)\"" "\\1" module_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}) + endforeach() + endif() else() file(WRITE ${KCONFIG_MODULES_FILE}