zephyr/modules/modules.cmake
Torsten Rasmussen 3d88083bf1 cmake: zephyr modules: sanitize all module name when used as variable
The introduction of Zephyr module glue code in the Zephyr repository
introduces a Kconfig variable in the form of:
`config ZEPHYR_<MODULE_NAME>_MODULE`.

All Kconfig variables go into `autoconf.h`, therefore it is necessary
to sanitize the Kconfig variable, so that it does not contain special
characters. To ensure consistent variable name, then the module name
will be sanitized in all variable use in both Kconfig and CMake.
The sanitization is done be replacing all special characters with an
underscore, `_`.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2021-01-20 12:59:19 +01:00

22 lines
761 B
CMake

# SPDX-License-Identifier: Apache-2.0
file(GLOB cmake_modules "${CMAKE_CURRENT_LIST_DIR}/*/CMakeLists.txt")
foreach(module ${cmake_modules})
get_filename_component(module_dir ${module} DIRECTORY)
get_filename_component(module_name ${module_dir} NAME)
zephyr_string(SANITIZE TOUPPER MODULE_NAME_UPPER ${module_name})
set(ZEPHYR_${MODULE_NAME_UPPER}_CMAKE_DIR ${module_dir})
endforeach()
file(GLOB kconfig_modules "${CMAKE_CURRENT_LIST_DIR}/*/Kconfig")
foreach(module ${kconfig_modules})
get_filename_component(module_dir ${module} DIRECTORY)
get_filename_component(module_name ${module_dir} NAME)
zephyr_string(SANITIZE TOUPPER MODULE_NAME_UPPER ${module_name})
set(ZEPHYR_${MODULE_NAME_UPPER}_KCONFIG ${module_dir}/Kconfig)
endforeach()