2018-01-12 02:49:13 +00:00
|
|
|
include(ExternalProject)
|
|
|
|
|
2018-01-17 03:01:57 +00:00
|
|
|
macro(kconfig_set_variables)
|
2018-02-06 10:03:41 +00:00
|
|
|
set(MCONF kconfig_bin/mconf)
|
2018-01-12 02:49:13 +00:00
|
|
|
|
2018-01-17 03:01:57 +00:00
|
|
|
set_default(SDKCONFIG ${PROJECT_PATH}/sdkconfig)
|
|
|
|
set(SDKCONFIG_HEADER ${CMAKE_BINARY_DIR}/sdkconfig.h)
|
|
|
|
set(SDKCONFIG_CMAKE ${CMAKE_BINARY_DIR}/sdkconfig.cmake)
|
2018-01-12 02:49:13 +00:00
|
|
|
|
2018-01-17 03:01:57 +00:00
|
|
|
set(ROOT_KCONFIG ${IDF_PATH}/Kconfig)
|
|
|
|
endmacro()
|
2018-01-12 02:49:13 +00:00
|
|
|
|
2018-02-06 10:03:41 +00:00
|
|
|
# Use the existing Makefile to build mconf (out of tree) when needed
|
2018-01-12 02:49:13 +00:00
|
|
|
#
|
2018-02-06 10:03:41 +00:00
|
|
|
# TODO: Find a solution on Windows
|
2018-01-12 02:49:13 +00:00
|
|
|
ExternalProject_Add(mconf
|
|
|
|
SOURCE_DIR ${IDF_PATH}/tools/kconfig
|
|
|
|
CONFIGURE_COMMAND ""
|
2018-02-06 10:03:41 +00:00
|
|
|
BINARY_DIR "kconfig_bin"
|
|
|
|
BUILD_COMMAND make -f ${IDF_PATH}/tools/kconfig/Makefile mconf
|
|
|
|
BUILD_BYPRODUCTS "kconfig_bin" ${MCONF}
|
2018-01-12 02:49:13 +00:00
|
|
|
INSTALL_COMMAND ""
|
|
|
|
EXCLUDE_FROM_ALL 1
|
|
|
|
)
|
|
|
|
|
2018-02-06 10:03:41 +00:00
|
|
|
|
2018-01-12 02:49:13 +00:00
|
|
|
# Find all Kconfig files for all components
|
2018-01-17 03:01:57 +00:00
|
|
|
function(kconfig_process_config)
|
2018-01-12 02:49:13 +00:00
|
|
|
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include/config")
|
|
|
|
set(kconfigs )
|
|
|
|
set(kconfigs_projbuild )
|
|
|
|
|
|
|
|
# Find Kconfig and Kconfig.projbuild for each component as applicable
|
|
|
|
# if any of these change, cmake should rerun
|
2018-01-17 05:25:14 +00:00
|
|
|
foreach(dir ${COMPONENT_PATHS} "${CMAKE_SOURCE_DIR}/main")
|
2018-01-12 02:49:13 +00:00
|
|
|
file(GLOB kconfig "${dir}/Kconfig")
|
|
|
|
if(kconfig)
|
|
|
|
set(kconfigs "${kconfigs} ${kconfig}")
|
|
|
|
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${kconfig})
|
|
|
|
endif()
|
|
|
|
file(GLOB kconfig ${dir}/Kconfig.projbuild)
|
|
|
|
if(kconfig)
|
|
|
|
set(kconfigs_projbuild "${kconfigs_projbuild} ${kconfig}")
|
|
|
|
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${kconfig})
|
|
|
|
endif()
|
|
|
|
endforeach(dir ${COMPONENT_PATHS})
|
|
|
|
|
2018-01-22 03:32:02 +00:00
|
|
|
if(EXISTS ${SDKCONFIG}.defaults)
|
|
|
|
set(defaults_arg --defaults "${SDKCONFIG}.defaults")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(confgen_basecommand
|
|
|
|
${PYTHON} ${IDF_PATH}/tools/kconfig_new/confgen.py
|
|
|
|
--kconfig ${ROOT_KCONFIG}
|
|
|
|
--config ${SDKCONFIG}
|
|
|
|
${defaults_arg}
|
|
|
|
--create-config-if-missing
|
|
|
|
--env "COMPONENT_KCONFIGS=${kconfigs}"
|
|
|
|
--env "COMPONENT_KCONFIGS_PROJBUILD=${kconfigs_projbuild}")
|
|
|
|
|
2018-01-12 02:49:13 +00:00
|
|
|
# Generate the menuconfig target (uses C-based mconf tool)
|
|
|
|
add_custom_target(menuconfig
|
|
|
|
DEPENDS mconf
|
2018-01-22 03:32:02 +00:00
|
|
|
COMMAND ${confgen_basecommand} --output config ${SDKCONFIG} # create any missing config file, with defaults if necessary
|
2018-01-12 02:49:13 +00:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E env
|
|
|
|
"COMPONENT_KCONFIGS=${kconfigs}"
|
|
|
|
"COMPONENT_KCONFIGS_PROJBUILD=${kconfigs_projbuild}"
|
|
|
|
"KCONFIG_CONFIG=${SDKCONFIG}"
|
2018-02-06 10:03:41 +00:00
|
|
|
${MCONF} ${ROOT_KCONFIG}
|
2018-01-12 02:49:13 +00:00
|
|
|
VERBATIM
|
|
|
|
USES_TERMINAL)
|
|
|
|
|
|
|
|
# Generate configuration output via confgen.py
|
|
|
|
# makes sdkconfig.h and skdconfig.cmake
|
|
|
|
#
|
|
|
|
# This happens at cmake runtime not during the build
|
2018-01-22 03:32:02 +00:00
|
|
|
execute_process(COMMAND ${confgen_basecommand}
|
2018-01-12 02:49:13 +00:00
|
|
|
--output header ${SDKCONFIG_HEADER}
|
|
|
|
--output cmake ${SDKCONFIG_CMAKE})
|
|
|
|
|
|
|
|
# When sdkconfig file changes in the future, trigger a cmake run
|
|
|
|
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${SDKCONFIG})
|
|
|
|
|
|
|
|
# Ditto if either of the generated files are missing/modified (this is a bit irritating as it means
|
|
|
|
# you can't edit these manually without them being regenerated, but I don't know of a better way...)
|
|
|
|
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${SDKCONFIG_HEADER})
|
|
|
|
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${SDKCONFIG_CMAKE})
|
|
|
|
|
|
|
|
# Or if the config generation tool changes
|
|
|
|
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${IDF_PATH}/tools/kconfig_new/confgen.py)
|
|
|
|
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${IDF_PATH}/tools/kconfig_new/kconfiglib.py)
|
|
|
|
|
|
|
|
endfunction()
|