Skip to content

Commit

Permalink
[nrf toup] cmake: kconfig: Allow setting CONFIG_*s for images via CLI
Browse files Browse the repository at this point in the history
Before this, supplying -DCONFIG_* to cmake via CLI would apply the
config to all images. This change allows prepending the image name
to the config to set it for that image.

e.g.
  -Dmcuboot_CONFIG_FLOAT=y
to set CONFIG_FLOAT to y for MCUboot.

Signed-off-by: Øyvind Rønningstad <[email protected]>
  • Loading branch information
oyvindronningstad authored and SebastianBoe committed Aug 20, 2019
1 parent 8711cfd commit 1dc0ca5
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions cmake/kconfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,33 @@ endforeach()
# user-testing.
unset(EXTRA_KCONFIG_OPTIONS)
get_cmake_property(cache_variable_names CACHE_VARIABLES)

if ("${IMAGE}" STREQUAL "")
foreach (name ${cache_variable_names})
if("${name}" MATCHES "^CONFIG_")
set(app_${name} ${${name}} CACHE STRING "")
unset(${name} CACHE)
endif()
endforeach()
set(KCONFIG_CACHE_IMAGE_PREFIX app_)
else()
set(KCONFIG_CACHE_IMAGE_PREFIX ${IMAGE})
endif()

get_cmake_property(cache_variable_names CACHE_VARIABLES)

foreach (name ${cache_variable_names})
if("${name}" MATCHES "^CONFIG_")
# When a cache variable starts with 'CONFIG_', it is assumed to be
if("${name}" MATCHES "^${KCONFIG_CACHE_IMAGE_PREFIX}CONFIG_")
# When a cache variable starts with '<image_name_>CONFIG_', it is assumed to be
# a Kconfig symbol assignment from the CMake command line.
string(REPLACE "${KCONFIG_CACHE_IMAGE_PREFIX}" "" config_name ${name})
set(EXTRA_KCONFIG_OPTIONS
"${EXTRA_KCONFIG_OPTIONS}\n${name}=${${name}}"
"${EXTRA_KCONFIG_OPTIONS}\n${config_name}=${${name}}"
)
endif()
endforeach()

unset(EXTRA_KCONFIG_OPTIONS_FILE)
if(EXTRA_KCONFIG_OPTIONS)
set(EXTRA_KCONFIG_OPTIONS_FILE ${PROJECT_BINARY_DIR}/misc/generated/extra_kconfig_options.conf)
file(WRITE
Expand Down Expand Up @@ -218,8 +235,9 @@ add_custom_target(${IMAGE}config-sanitycheck DEPENDS ${DOTCONFIG})
# CMakeCache.txt. If the symbols end up in DOTCONFIG they will be
# re-introduced to the namespace through 'import_kconfig'.
foreach (name ${cache_variable_names})
if("${name}" MATCHES "^CONFIG_")
unset(${name})
if("${name}" MATCHES "^${KCONFIG_CACHE_IMAGE_PREFIX}CONFIG_")
string(REPLACE "${KCONFIG_CACHE_IMAGE_PREFIX}" "" config_name ${name})
unset(${config_name})
unset(${name} CACHE)
endif()
endforeach()
Expand All @@ -229,9 +247,10 @@ import_kconfig(CONFIG_ ${DOTCONFIG})

# Re-introduce the CLI Kconfig symbols that survived
foreach (name ${cache_variable_names})
if("${name}" MATCHES "^CONFIG_")
if(DEFINED ${name})
set(${name} ${${name}} CACHE STRING "")
if("${name}" MATCHES "^${KCONFIG_CACHE_IMAGE_PREFIX}CONFIG_")
string(REPLACE "${KCONFIG_CACHE_IMAGE_PREFIX}" "" config_name ${name})
if(DEFINED ${config_name})
set(${name} ${${config_name}} CACHE STRING "")
endif()
endif()
endforeach()

0 comments on commit 1dc0ca5

Please sign in to comment.