diff --git a/cmake/nuttx_kconfig.cmake b/cmake/nuttx_kconfig.cmake index 2b19a1cd74b..b20d7860f5b 100644 --- a/cmake/nuttx_kconfig.cmake +++ b/cmake/nuttx_kconfig.cmake @@ -18,14 +18,36 @@ # # ############################################################################## +macro(encode_brackets contents) + string(REGEX REPLACE "\\[" "__OPEN_BRACKET__" ${contents} "${${contents}}") + string(REGEX REPLACE "\\]" "__CLOSE_BRACKET__" ${contents} "${${contents}}") +endmacro() + +macro(decode_brackets contents) + string(REGEX REPLACE "__OPEN_BRACKET__" "[" ${contents} "${${contents}}") + string(REGEX REPLACE "__CLOSE_BRACKET__" "]" ${contents} "${${contents}}") +endmacro() + +macro(encode_semicolon contents) + string(REGEX REPLACE ";" "__SEMICOLON__" ${contents} "${${contents}}") +endmacro() + +macro(decode_semicolon contents) + string(REGEX REPLACE "__SEMICOLON__" ";" ${contents} "${${contents}}") +endmacro() + function(nuttx_export_kconfig_by_value kconfigfile config) file(STRINGS ${kconfigfile} ConfigContents) + encode_brackets(ConfigContents) foreach(NameAndValue ${ConfigContents}) + decode_brackets(NameAndValue) + encode_semicolon(NameAndValue) string(REGEX REPLACE "^[ ]+" "" NameAndValue ${NameAndValue}) string(REGEX MATCH "^CONFIG[^=]+" Name ${NameAndValue}) if(Name STREQUAL ${config}) string(REPLACE "${Name}=" "" Value ${NameAndValue}) string(REPLACE "\"" "" Value ${Value}) + decode_semicolon(Value) set(${Name} ${Value} PARENT_SCOPE) @@ -41,7 +63,10 @@ function(nuttx_export_kconfig kconfigfile) set(${key} PARENT_SCOPE) endforeach() file(STRINGS ${kconfigfile} ConfigContents) + encode_brackets(ConfigContents) foreach(NameAndValue ${ConfigContents}) + decode_brackets(NameAndValue) + encode_semicolon(NameAndValue) # Strip leading spaces string(REGEX REPLACE "^[ ]+" "" NameAndValue ${NameAndValue}) @@ -54,7 +79,7 @@ function(nuttx_export_kconfig kconfigfile) # remove extra quotes string(REPLACE "\"" "" Value ${Value}) - + decode_semicolon(Value) # Set the variable set(${Name} ${Value} diff --git a/cmake/nuttx_mkconfig.cmake b/cmake/nuttx_mkconfig.cmake index fc040eb840e..71500c355aa 100644 --- a/cmake/nuttx_mkconfig.cmake +++ b/cmake/nuttx_mkconfig.cmake @@ -92,7 +92,10 @@ file(APPEND ${CONFIG_H} file(APPEND ${CONFIG_H} "#define CONFIG_BASE_DEFCONFIG \"${BASE_DEFCONFIG}\"\n") file(STRINGS ${CMAKE_BINARY_DIR}/.config ConfigContents) +encode_brackets(ConfigContents) foreach(NameAndValue ${ConfigContents}) + decode_brackets(NameAndValue) + encode_semicolon(NameAndValue) string(REGEX REPLACE "^[ ]+" "" NameAndValue ${NameAndValue}) string(REGEX MATCH "^CONFIG[^=]+" NAME ${NameAndValue}) # skip BASE_DEFCONFIG here as it is handled above @@ -121,6 +124,7 @@ foreach(NameAndValue ${ConfigContents}) endif() endforeach() if(NOT "${VALUE}" STREQUAL "") + decode_semicolon(VALUE) file(APPEND ${CONFIG_H} "#define ${NAME} ${VALUE}\n") endif() endif()