cmake: zephyr modules variable names.

This commit refactors processing of Zephyr modules.
The Zephyr module name processing has been moved to zephyr_modules.cmake
to ensure that all `ZEPHYR_<MODULE_NAME>_MODULE_DIR` are defined early
in the build system.

No changes to inclusion of Zephyr module CMake code.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
Torsten Rasmussen 2020-08-24 11:01:04 +02:00 committed by Carles Cufí
commit 2fc062b3a4
2 changed files with 30 additions and 32 deletions

View file

@ -463,26 +463,7 @@ add_subdirectory(subsys)
add_subdirectory(drivers) add_subdirectory(drivers)
# Include zephyr modules generated CMake file. # Include zephyr modules generated CMake file.
if(EXISTS ${CMAKE_BINARY_DIR}/zephyr_modules.txt) foreach(module_name ${ZEPHYR_MODULE_NAMES})
file(STRINGS ${CMAKE_BINARY_DIR}/zephyr_modules.txt ZEPHYR_MODULES_TXT
ENCODING UTF-8)
set(module_names)
foreach(module ${ZEPHYR_MODULES_TXT})
# Match "<name>":"<path>" 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 # Note the second, binary_dir parameter requires the added
# subdirectory to have its own, local cmake target(s). If not then # subdirectory to have its own, local cmake target(s). If not then
# this binary_dir is created but stays empty. Object files land in # this binary_dir is created but stays empty. Object files land in
@ -494,7 +475,6 @@ if(EXISTS ${CMAKE_BINARY_DIR}/zephyr_modules.txt)
endforeach() endforeach()
# Done processing modules, clear ZEPHYR_CURRENT_MODULE_DIR. # Done processing modules, clear ZEPHYR_CURRENT_MODULE_DIR.
set(ZEPHYR_CURRENT_MODULE_DIR) set(ZEPHYR_CURRENT_MODULE_DIR)
endif()
set(syscall_list_h ${CMAKE_CURRENT_BINARY_DIR}/include/generated/syscall_list.h) set(syscall_list_h ${CMAKE_CURRENT_BINARY_DIR}/include/generated/syscall_list.h)
set(syscalls_json ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/syscalls.json) set(syscalls_json ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/syscalls.json)

View file

@ -60,6 +60,24 @@ if(WEST OR ZEPHYR_MODULES)
endforeach() endforeach()
endif() 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 "<name>":"<path>" 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() else()
file(WRITE ${KCONFIG_MODULES_FILE} file(WRITE ${KCONFIG_MODULES_FILE}