Skip to content

Commit 32a28ef

Browse files
committed
cmake: kconfig: allow for Kconfig CONFIG namespace
This commit allows for specifying a dedicated Kconfig namespace, for example: <namespace>_CONFIG This namespace will then be used for handling loading of configuration files into CMake configure scope, as well as handling of CMake cache variables when set using `-D<namespace>_CONFIG_<var>=<value>`. This allows greater flexibility when re-using the cmake/kconfig.cmake in other projects. Signed-off-by: Torsten Rasmussen <[email protected]>
1 parent b1d1c24 commit 32a28ef

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

cmake/modules/kconfig.cmake

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${AUTOCONF_H})
1717
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/kconfig/include/generated)
1818
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/kconfig/include/config)
1919

20+
set_ifndef(KCONFIG_NAMESPACE "CONFIG")
21+
2022
# Support multiple SOC_ROOT, remove ZEPHYR_BASE as that is always sourced.
2123
set(kconfig_soc_root ${SOC_ROOT})
2224
list(REMOVE_ITEM kconfig_soc_root ${ZEPHYR_BASE})
@@ -109,6 +111,7 @@ set(COMMON_KCONFIG_ENV_SETTINGS
109111
PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
110112
srctree=${ZEPHYR_BASE}
111113
KERNELVERSION=${KERNELVERSION}
114+
CONFIG_=${KCONFIG_NAMESPACE}_
112115
KCONFIG_CONFIG=${DOTCONFIG}
113116
# Set environment variables so that Kconfig can prune Kconfig source
114117
# files for other architectures
@@ -170,15 +173,15 @@ foreach(kconfig_target
170173
endforeach()
171174

172175
# Support assigning Kconfig symbols on the command-line with CMake
173-
# cache variables prefixed with 'CONFIG_'. This feature is
174-
# experimental and undocumented until it has undergone more
176+
# cache variables prefixed according to the Kconfig namespace.
177+
# This feature is experimental and undocumented until it has undergone more
175178
# user-testing.
176179
unset(EXTRA_KCONFIG_OPTIONS)
177180
get_cmake_property(cache_variable_names CACHE_VARIABLES)
178181
foreach (name ${cache_variable_names})
179-
if("${name}" MATCHES "^CONFIG_")
180-
# When a cache variable starts with 'CONFIG_', it is assumed to be
181-
# a Kconfig symbol assignment from the CMake command line.
182+
if("${name}" MATCHES "^${KCONFIG_NAMESPACE}_")
183+
# When a cache variable starts with the 'KCONFIG_NAMESPACE' value, it is
184+
# assumed to be a Kconfig symbol assignment from the CMake command line.
182185
set(EXTRA_KCONFIG_OPTIONS
183186
"${EXTRA_KCONFIG_OPTIONS}\n${name}=${${name}}"
184187
)
@@ -316,18 +319,18 @@ add_custom_target(config-twister DEPENDS ${DOTCONFIG})
316319
# CMakeCache.txt. If the symbols end up in DOTCONFIG they will be
317320
# re-introduced to the namespace through 'import_kconfig'.
318321
foreach (name ${cache_variable_names})
319-
if("${name}" MATCHES "^CONFIG_")
322+
if("${name}" MATCHES "^${KCONFIG_NAMESPACE}_")
320323
unset(${name})
321324
unset(${name} CACHE)
322325
endif()
323326
endforeach()
324327

325-
# Parse the lines prefixed with CONFIG_ in the .config file from Kconfig
326-
import_kconfig(CONFIG_ ${DOTCONFIG})
328+
# Import the .config file and make all settings available in CMake processing.
329+
import_kconfig(${KCONFIG_NAMESPACE} ${DOTCONFIG})
327330

328331
# Re-introduce the CLI Kconfig symbols that survived
329332
foreach (name ${cache_variable_names})
330-
if("${name}" MATCHES "^CONFIG_")
333+
if("${name}" MATCHES "^${KCONFIG_NAMESPACE}_")
331334
if(DEFINED ${name})
332335
set(${name} ${${name}} CACHE STRING "")
333336
endif()

0 commit comments

Comments
 (0)