forked from SKKU-ESLAB/ANT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkconfig.cmake
34 lines (29 loc) · 1.1 KB
/
kconfig.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Original Source: https://github.com/zephyrproject-rtos/zephyr (Apache 2.0)
# 2.2 Misc
#
# Parse a KConfig formatted file (typically named *.config) and
# introduce all the CONF_ variables into the CMake namespace
function(import_kconfig config_file)
# Parse the lines prefixed with CONFIG_ in ${config_file}
file(
STRINGS
${config_file}
DOT_CONFIG_LIST
REGEX "^CONFIG_"
ENCODING "UTF-8"
)
foreach (CONFIG ${DOT_CONFIG_LIST})
# CONFIG looks like: CONFIG_NET_BUF=y
# Match the first part, the variable name
string(REGEX MATCH "[^=]+" CONF_VARIABLE_NAME ${CONFIG})
# Match the second part, variable value
string(REGEX MATCH "=(.+$)" CONF_VARIABLE_VALUE ${CONFIG})
# The variable name match we just did included the '=' symbol. To just get the
# part on the RHS we use match group 1
set(CONF_VARIABLE_VALUE ${CMAKE_MATCH_1})
if("${CONF_VARIABLE_VALUE}" MATCHES "^\"(.*)\"$") # Is surrounded by quotes
set(CONF_VARIABLE_VALUE ${CMAKE_MATCH_1})
endif()
set("${CONF_VARIABLE_NAME}" "${CONF_VARIABLE_VALUE}" PARENT_SCOPE)
endforeach()
endfunction()