2018-01-11 21:49:13 -05:00
|
|
|
include(ExternalProject)
|
|
|
|
|
2018-01-16 22:01:57 -05:00
|
|
|
macro(kconfig_set_variables)
|
2018-05-08 03:33:21 -04:00
|
|
|
set(CONFIG_DIR ${CMAKE_BINARY_DIR}/config)
|
2018-02-26 23:45:30 -05:00
|
|
|
set_default(SDKCONFIG ${PROJECT_PATH}/sdkconfig)
|
2018-05-08 03:33:21 -04:00
|
|
|
set(SDKCONFIG_HEADER ${CONFIG_DIR}/sdkconfig.h)
|
|
|
|
set(SDKCONFIG_CMAKE ${CONFIG_DIR}/sdkconfig.cmake)
|
|
|
|
set(SDKCONFIG_JSON ${CONFIG_DIR}/sdkconfig.json)
|
2018-05-16 02:54:22 -04:00
|
|
|
set(KCONFIG_JSON_MENUS ${CONFIG_DIR}/kconfig_menus.json)
|
2018-01-11 21:49:13 -05:00
|
|
|
|
2018-02-26 23:45:30 -05:00
|
|
|
set(ROOT_KCONFIG ${IDF_PATH}/Kconfig)
|
2018-02-21 23:05:05 -05:00
|
|
|
|
2018-02-26 23:45:30 -05:00
|
|
|
set_default(SDKCONFIG_DEFAULTS "${SDKCONFIG}.defaults")
|
2018-05-08 03:33:21 -04:00
|
|
|
|
|
|
|
# ensure all source files can include sdkconfig.h
|
|
|
|
include_directories("${CONFIG_DIR}")
|
2018-01-16 22:01:57 -05:00
|
|
|
endmacro()
|
2018-01-11 21:49:13 -05:00
|
|
|
|
2018-05-01 01:42:28 -04:00
|
|
|
if(CMAKE_HOST_WIN32)
|
2018-05-23 23:32:34 -04:00
|
|
|
# Prefer a prebuilt mconf-idf on Windows
|
2018-10-17 03:15:41 -04:00
|
|
|
if(DEFINED ENV{MSYSTEM})
|
|
|
|
find_program(WINPTY winpty)
|
|
|
|
else()
|
|
|
|
unset(WINPTY CACHE) # in case previous CMake run was in a tty and this one is not
|
|
|
|
endif()
|
2018-05-23 23:32:34 -04:00
|
|
|
find_program(MCONF mconf-idf)
|
|
|
|
|
|
|
|
# Fall back to the old binary which was called 'mconf' not 'mconf-idf'
|
|
|
|
if(NOT MCONF)
|
|
|
|
find_program(MCONF mconf)
|
|
|
|
if(MCONF)
|
|
|
|
message(WARNING "Falling back to mconf binary '${MCONF}' not mconf-idf. "
|
|
|
|
"This is probably because an old version of IDF mconf is installed and this is fine. "
|
|
|
|
"However if there are config problems please check the Getting Started guide for your platform.")
|
|
|
|
endif()
|
|
|
|
endif()
|
2018-05-01 01:42:28 -04:00
|
|
|
|
|
|
|
if(NOT MCONF)
|
|
|
|
find_program(NATIVE_GCC gcc)
|
|
|
|
if(NOT NATIVE_GCC)
|
|
|
|
message(FATAL_ERROR
|
2018-05-23 23:32:34 -04:00
|
|
|
"Windows requires a prebuilt mconf-idf for your platform "
|
|
|
|
"on the PATH, or an MSYS2 version of gcc on the PATH to build mconf-idf. "
|
2018-05-01 01:42:28 -04:00
|
|
|
"Consult the setup docs for ESP-IDF on Windows.")
|
|
|
|
endif()
|
2018-05-01 02:05:27 -04:00
|
|
|
elseif(WINPTY)
|
|
|
|
set(MCONF "${WINPTY}" "${MCONF}")
|
2018-05-01 01:42:28 -04:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT MCONF)
|
|
|
|
# Use the existing Makefile to build mconf (out of tree) when needed
|
|
|
|
#
|
2018-05-23 23:32:34 -04:00
|
|
|
set(MCONF kconfig_bin/mconf-idf)
|
2018-01-11 21:49:13 -05:00
|
|
|
|
2018-05-23 23:32:34 -04:00
|
|
|
externalproject_add(mconf-idf
|
2018-05-01 01:42:28 -04:00
|
|
|
SOURCE_DIR ${IDF_PATH}/tools/kconfig
|
|
|
|
CONFIGURE_COMMAND ""
|
|
|
|
BINARY_DIR "kconfig_bin"
|
2018-05-23 23:32:34 -04:00
|
|
|
BUILD_COMMAND make -f ${IDF_PATH}/tools/kconfig/Makefile mconf-idf
|
2018-05-01 01:42:28 -04:00
|
|
|
BUILD_BYPRODUCTS ${MCONF}
|
|
|
|
INSTALL_COMMAND ""
|
|
|
|
EXCLUDE_FROM_ALL 1
|
|
|
|
)
|
2018-05-17 00:23:49 -04:00
|
|
|
|
|
|
|
file(GLOB mconf_srcfiles ${IDF_PATH}/tools/kconfig/*.c)
|
2018-05-23 23:32:34 -04:00
|
|
|
externalproject_add_stepdependencies(mconf-idf build
|
2018-05-17 00:23:49 -04:00
|
|
|
${mconf_srcfiles}
|
|
|
|
${IDF_PATH}/tools/kconfig/Makefile
|
|
|
|
${CMAKE_CURRENT_LIST_FILE})
|
|
|
|
unset(mconf_srcfiles)
|
|
|
|
|
2018-05-23 23:32:34 -04:00
|
|
|
set(menuconfig_depends DEPENDS mconf-idf)
|
2018-05-17 00:23:49 -04:00
|
|
|
|
2018-05-01 01:42:28 -04:00
|
|
|
endif()
|
2018-02-06 05:03:41 -05:00
|
|
|
|
2018-01-11 21:49:13 -05:00
|
|
|
# Find all Kconfig files for all components
|
2018-01-16 22:01:57 -05:00
|
|
|
function(kconfig_process_config)
|
2018-05-08 03:33:21 -04:00
|
|
|
file(MAKE_DIRECTORY "${CONFIG_DIR}")
|
2018-02-26 23:45:30 -05:00
|
|
|
set(kconfigs)
|
|
|
|
set(kconfigs_projbuild)
|
|
|
|
|
|
|
|
# Find Kconfig and Kconfig.projbuild for each component as applicable
|
|
|
|
# if any of these change, cmake should rerun
|
2018-09-12 07:31:22 -04:00
|
|
|
foreach(dir ${BUILD_COMPONENT_PATHS})
|
2018-02-26 23:45:30 -05: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()
|
|
|
|
|
|
|
|
if(EXISTS ${SDKCONFIG_DEFAULTS})
|
|
|
|
set(defaults_arg --defaults "${SDKCONFIG_DEFAULTS}")
|
2018-01-11 21:49:13 -05:00
|
|
|
endif()
|
2018-02-26 23:45:30 -05:00
|
|
|
|
2018-04-05 03:26:28 -04:00
|
|
|
# Set these in the parent scope, so that they can be written to project_description.json
|
|
|
|
set(kconfigs "${kconfigs}")
|
|
|
|
set(COMPONENT_KCONFIGS "${kconfigs}" PARENT_SCOPE)
|
|
|
|
set(COMPONENT_KCONFIGS_PROJBUILD "${kconfigs_projbuild}" PARENT_SCOPE)
|
|
|
|
|
2018-02-26 23:45:30 -05:00
|
|
|
set(confgen_basecommand
|
|
|
|
${PYTHON} ${IDF_PATH}/tools/kconfig_new/confgen.py
|
|
|
|
--kconfig ${ROOT_KCONFIG}
|
|
|
|
--config ${SDKCONFIG}
|
|
|
|
${defaults_arg}
|
|
|
|
--env "COMPONENT_KCONFIGS=${kconfigs}"
|
2018-05-06 22:01:16 -04:00
|
|
|
--env "COMPONENT_KCONFIGS_PROJBUILD=${kconfigs_projbuild}"
|
|
|
|
--env "IDF_CMAKE=y")
|
2018-02-26 23:45:30 -05:00
|
|
|
|
2018-05-23 23:32:34 -04:00
|
|
|
# Generate the menuconfig target (uses C-based mconf-idf tool, either prebuilt or via mconf-idf target above)
|
2018-02-26 23:45:30 -05:00
|
|
|
add_custom_target(menuconfig
|
2018-05-01 01:42:28 -04:00
|
|
|
${menuconfig_depends}
|
2018-02-26 23:45:30 -05:00
|
|
|
# create any missing config file, with defaults if necessary
|
|
|
|
COMMAND ${confgen_basecommand} --output config ${SDKCONFIG}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E env
|
|
|
|
"COMPONENT_KCONFIGS=${kconfigs}"
|
|
|
|
"COMPONENT_KCONFIGS_PROJBUILD=${kconfigs_projbuild}"
|
2018-05-06 22:01:16 -04:00
|
|
|
"IDF_CMAKE=y"
|
2018-02-26 23:45:30 -05:00
|
|
|
"KCONFIG_CONFIG=${SDKCONFIG}"
|
|
|
|
${MCONF} ${ROOT_KCONFIG}
|
|
|
|
VERBATIM
|
|
|
|
USES_TERMINAL)
|
|
|
|
|
2018-05-16 02:54:22 -04:00
|
|
|
# Custom target to run confserver.py from the build tool
|
|
|
|
add_custom_target(confserver
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E env
|
|
|
|
"COMPONENT_KCONFIGS=${kconfigs}"
|
|
|
|
"COMPONENT_KCONFIGS_PROJBUILD=${kconfigs_projbuild}"
|
2019-03-24 22:41:28 -04:00
|
|
|
${PYTHON} ${IDF_PATH}/tools/kconfig_new/confserver.py
|
|
|
|
--kconfig ${IDF_PATH}/Kconfig --config ${SDKCONFIG}
|
2018-05-16 02:54:22 -04:00
|
|
|
VERBATIM
|
|
|
|
USES_TERMINAL)
|
|
|
|
|
2018-02-26 23:45:30 -05:00
|
|
|
# Generate configuration output via confgen.py
|
|
|
|
# makes sdkconfig.h and skdconfig.cmake
|
|
|
|
#
|
|
|
|
# This happens during the cmake run not during the build
|
2019-01-15 10:07:17 -05:00
|
|
|
if(NOT BOOTLOADER_BUILD)
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${confgen_basecommand}
|
|
|
|
--output header ${SDKCONFIG_HEADER}
|
|
|
|
--output cmake ${SDKCONFIG_CMAKE}
|
|
|
|
--output json ${SDKCONFIG_JSON}
|
|
|
|
--output json_menus ${KCONFIG_JSON_MENUS}
|
|
|
|
--output config ${SDKCONFIG} # only generate config at the top-level project
|
|
|
|
RESULT_VARIABLE config_result)
|
|
|
|
else()
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${confgen_basecommand}
|
|
|
|
--output header ${SDKCONFIG_HEADER}
|
|
|
|
--output cmake ${SDKCONFIG_CMAKE}
|
|
|
|
--output json ${SDKCONFIG_JSON}
|
|
|
|
--output json_menus ${KCONFIG_JSON_MENUS}
|
|
|
|
RESULT_VARIABLE config_result)
|
|
|
|
endif()
|
2018-02-26 23:45:30 -05:00
|
|
|
if(config_result)
|
|
|
|
message(FATAL_ERROR "Failed to run confgen.py (${confgen_basecommand}). Error ${config_result}")
|
2018-01-11 21:49:13 -05:00
|
|
|
endif()
|
2018-02-26 23:45:30 -05:00
|
|
|
|
|
|
|
# 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")
|
|
|
|
|
|
|
|
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY
|
|
|
|
ADDITIONAL_MAKE_CLEAN_FILES
|
|
|
|
"${SDKCONFIG_HEADER}" "${SDKCONFIG_CMAKE}")
|
2018-01-11 21:49:13 -05:00
|
|
|
|
|
|
|
endfunction()
|