1# SPDX-License-Identifier: BSD-3-Clause
2
3set(PROJECT_ROOT ${SdkRootDirPath}/core)
4#set(KCONFIG_ROOT ${SdkRootDirPath}/core/Kconfig)
5string(REGEX MATCH "examples/([^/]+)/" BOARD_VAR ${CMAKE_SOURCE_DIR})
6set(BOARD ${CMAKE_MATCH_1})
7set(BOARD_DIR ${SdkRootDirPath}/core/boards/${BOARD})
8set(KCONFIG_ROOT ${SdkRootDirPath}/core/Kconfig)
9
10message("PROJECT_ROOT ${CMAKE_SOURCE_DIR}")
11
12if(NOT DEFINED APPLICATION_SOURCE_DIR)
13set(APPLICATION_SOURCE_DIR ${CMAKE_SOURCE_DIR} CACHE PATH
14    "Application Source Directory"
15)
16endif()
17
18message("APPLICATION_SOURCE_DIR ${APPLICATION_SOURCE_DIR}")
19
20if(DEFINED APPLICATION_BINARY_DIR)
21unset(APPLICATION_BINARY_DIR)
22unset(APPLICATION_BINARY_DIR CACHE)
23endif()
24
25set(APPLICATION_BINARY_DIR ${CMAKE_SOURCE_DIR}/build CACHE PATH
26    "Application Binary Directory"
27)
28
29set(AUTOCONF_H ${APPLICATION_BINARY_DIR}/kconfig/include/generated/autoconf.h)
30
31message("APPLICATION_BINARY_DIR ${APPLICATION_BINARY_DIR}")
32
33function(import_kconfig prefix kconfig_fragment)
34  # Parse the lines prefixed with 'prefix' in ${kconfig_fragment}
35  file(
36    STRINGS
37    ${kconfig_fragment}
38    DOT_CONFIG_LIST
39    REGEX "^${prefix}"
40    ENCODING "UTF-8"
41  )
42
43  foreach (CONFIG ${DOT_CONFIG_LIST})
44    # CONFIG could look like: CONFIG_NET_BUF=y
45
46    # Match the first part, the variable name
47    string(REGEX MATCH "[^=]+" CONF_VARIABLE_NAME ${CONFIG})
48
49    # Match the second part, variable value
50    string(REGEX MATCH "=(.+$)" CONF_VARIABLE_VALUE ${CONFIG})
51    # The variable name match we just did included the '=' symbol. To just get the
52    # part on the RHS we use match group 1
53    set(CONF_VARIABLE_VALUE ${CMAKE_MATCH_1})
54
55    if("${CONF_VARIABLE_VALUE}" MATCHES "^\"(.*)\"$") # Is surrounded by quotes
56      set(CONF_VARIABLE_VALUE ${CMAKE_MATCH_1})
57    endif()
58
59    set("${CONF_VARIABLE_NAME}" "${CONF_VARIABLE_VALUE}" PARENT_SCOPE)
60    list(APPEND keys "${CONF_VARIABLE_NAME}")
61  endforeach()
62
63  foreach(outvar ${ARGN})
64    set(${outvar} "${keys}" PARENT_SCOPE)
65  endforeach()
66endfunction()
67
68include(${SdkRootDirPath}/core/cmake/python.cmake)
69include(${SdkRootDirPath}/core/cmake/kconfig.cmake)
70
71