2018-01-11 21:49:13 -05:00
|
|
|
include(ExternalProject)
|
|
|
|
|
2019-04-26 01:42:10 -04:00
|
|
|
function(__kconfig_init)
|
2019-09-10 03:58:52 -04:00
|
|
|
if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "FreeBSD")
|
|
|
|
set(MAKE_COMMMAND "gmake")
|
|
|
|
else()
|
|
|
|
set(MAKE_COMMMAND "make")
|
|
|
|
endif()
|
|
|
|
|
2019-04-26 01:42:10 -04:00
|
|
|
idf_build_get_property(idf_path IDF_PATH)
|
2019-09-10 03:58:52 -04:00
|
|
|
if(CMAKE_HOST_WIN32 AND DEFINED ENV{MSYSTEM})
|
2019-04-26 01:42:10 -04:00
|
|
|
# Prefer a prebuilt mconf-idf on Windows
|
2019-09-10 03:58:52 -04:00
|
|
|
find_program(WINPTY winpty)
|
2019-05-27 11:50:31 -04:00
|
|
|
unset(MCONF CACHE) # needed when MSYS and CMD is intermixed (cache could contain an incompatible path)
|
2019-04-26 01:42:10 -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-11-30 03:07:09 -05:00
|
|
|
|
2019-04-26 01:42:10 -04:00
|
|
|
if(NOT MCONF)
|
|
|
|
find_program(NATIVE_GCC gcc)
|
|
|
|
if(NOT NATIVE_GCC)
|
|
|
|
message(FATAL_ERROR
|
2019-09-10 03:58:52 -04:00
|
|
|
"Windows requires an MSYS2 version of gcc on the PATH to build mconf-idf. "
|
2019-04-26 01:42:10 -04:00
|
|
|
"Consult the setup docs for ESP-IDF on Windows.")
|
2019-09-10 03:58:52 -04:00
|
|
|
else()
|
|
|
|
# Use the existing Makefile to build mconf (out of tree) when needed
|
|
|
|
#
|
|
|
|
set(MCONF ${CMAKE_BINARY_DIR}/kconfig_bin/mconf-idf)
|
|
|
|
set(src_path ${idf_path}/tools/kconfig)
|
|
|
|
|
|
|
|
# note: we preemptively remove any build files from the src dir
|
|
|
|
# as we're building out of tree, but don't want build system to
|
|
|
|
# #include any from there that were previously build with/for make
|
|
|
|
externalproject_add(mconf-idf
|
|
|
|
SOURCE_DIR ${src_path}
|
|
|
|
CONFIGURE_COMMAND ""
|
|
|
|
BINARY_DIR "${CMAKE_BINARY_DIR}/kconfig_bin"
|
|
|
|
BUILD_COMMAND rm -f ${src_path}/zconf.lex.c ${src_path}/zconf.hash.c
|
|
|
|
COMMAND ${MAKE_COMMMAND} -f ${src_path}/Makefile mconf-idf
|
|
|
|
BUILD_BYPRODUCTS ${MCONF}
|
|
|
|
INSTALL_COMMAND ""
|
|
|
|
EXCLUDE_FROM_ALL 1
|
|
|
|
)
|
|
|
|
|
|
|
|
file(GLOB mconf_srcfiles ${src_path}/*.c)
|
|
|
|
list(REMOVE_ITEM mconf_srcfiles "${src_path}/zconf.lex.c" "${src_path}/zconf.hash.c")
|
|
|
|
externalproject_add_stepdependencies(mconf-idf build
|
|
|
|
${mconf_srcfiles}
|
|
|
|
${src_path}/Makefile
|
|
|
|
${CMAKE_CURRENT_LIST_FILE})
|
|
|
|
unset(mconf_srcfiles)
|
|
|
|
unset(src_path)
|
|
|
|
|
|
|
|
set(menuconfig_depends DEPENDS mconf-idf)
|
2019-04-26 01:42:10 -04:00
|
|
|
endif()
|
2019-08-15 09:49:46 -04:00
|
|
|
else()
|
|
|
|
execute_process(COMMAND "${MCONF}" -v
|
|
|
|
RESULT_VARIABLE mconf_res
|
|
|
|
OUTPUT_VARIABLE mconf_out
|
|
|
|
ERROR_VARIABLE mconf_err)
|
|
|
|
if(${mconf_res})
|
|
|
|
message(WARNING "Failed to detect version of mconf-idf. Return code was ${mconf_res}.")
|
|
|
|
else()
|
|
|
|
string(STRIP "${mconf_out}" mconf_out)
|
|
|
|
set(mconf_expected_ver "mconf-v4.6.0.0-idf-20190628-win32")
|
|
|
|
if(NOT ${mconf_out} STREQUAL "mconf-idf version ${mconf_expected_ver}")
|
|
|
|
message(WARNING "Unexpected ${mconf_out}. Expected ${mconf_expected_ver}. "
|
|
|
|
"Please check the ESP-IDF Getting Started guide for version "
|
|
|
|
"${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}.${IDF_VERSION_PATCH} "
|
|
|
|
"to correct this issue")
|
|
|
|
else()
|
|
|
|
message(STATUS "${mconf_out}") # prints: mconf-idf version ....
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
if(WINPTY)
|
|
|
|
set(MCONF "\"${WINPTY}\" \"${MCONF}\"")
|
|
|
|
endif()
|
2018-11-30 03:07:09 -05:00
|
|
|
endif()
|
2019-09-10 03:58:52 -04:00
|
|
|
idf_build_set_property(__MCONF ${MCONF})
|
|
|
|
idf_build_set_property(__MENUCONFIG_DEPENDS "${menuconfig_depends}")
|
2018-11-30 03:07:09 -05:00
|
|
|
endif()
|
|
|
|
|
2019-04-26 01:42:10 -04:00
|
|
|
idf_build_get_property(idf_path IDF_PATH)
|
|
|
|
idf_build_set_property(__ROOT_KCONFIG ${idf_path}/Kconfig)
|
2019-07-16 10:39:12 -04:00
|
|
|
idf_build_set_property(__ROOT_SDKCONFIG_RENAME ${idf_path}/sdkconfig.rename)
|
2019-04-26 01:42:10 -04:00
|
|
|
idf_build_set_property(__OUTPUT_SDKCONFIG 1)
|
|
|
|
endfunction()
|
2018-12-10 21:33:09 -05:00
|
|
|
|
2019-04-26 01:42:10 -04:00
|
|
|
#
|
|
|
|
# Initialize Kconfig-related properties for components.
|
|
|
|
# This function assumes that all basic properties of the components have been
|
|
|
|
# set prior to calling it.
|
|
|
|
#
|
|
|
|
function(__kconfig_component_init component_target)
|
|
|
|
__component_get_property(component_dir ${component_target} COMPONENT_DIR)
|
|
|
|
file(GLOB kconfig "${component_dir}/Kconfig")
|
|
|
|
__component_set_property(${component_target} KCONFIG "${kconfig}")
|
|
|
|
file(GLOB kconfig "${component_dir}/Kconfig.projbuild")
|
|
|
|
__component_set_property(${component_target} KCONFIG_PROJBUILD "${kconfig}")
|
2019-07-16 10:39:12 -04:00
|
|
|
file(GLOB sdkconfig_rename "${component_dir}/sdkconfig.rename")
|
|
|
|
__component_set_property(${component_target} SDKCONFIG_RENAME "${sdkconfig_rename}")
|
2019-04-26 01:42:10 -04:00
|
|
|
endfunction()
|
2018-12-10 21:33:09 -05:00
|
|
|
|
2019-04-26 01:42:10 -04:00
|
|
|
#
|
|
|
|
# Generate the config files and create config related targets and configure
|
|
|
|
# dependencies.
|
|
|
|
#
|
|
|
|
function(__kconfig_generate_config sdkconfig sdkconfig_defaults)
|
|
|
|
# List all Kconfig and Kconfig.projbuild in known components
|
|
|
|
idf_build_get_property(component_targets __COMPONENT_TARGETS)
|
2019-05-24 06:32:42 -04:00
|
|
|
idf_build_get_property(build_component_targets __BUILD_COMPONENT_TARGETS)
|
2019-04-26 01:42:10 -04:00
|
|
|
foreach(component_target ${component_targets})
|
2019-05-24 06:32:42 -04:00
|
|
|
if(component_target IN_LIST build_component_targets)
|
|
|
|
__component_get_property(kconfig ${component_target} KCONFIG)
|
|
|
|
__component_get_property(kconfig_projbuild ${component_target} KCONFIG_PROJBUILD)
|
2019-07-16 10:39:12 -04:00
|
|
|
__component_get_property(sdkconfig_rename ${component_target} SDKCONFIG_RENAME)
|
2019-05-24 06:32:42 -04:00
|
|
|
if(kconfig)
|
|
|
|
list(APPEND kconfigs ${kconfig})
|
|
|
|
endif()
|
|
|
|
if(kconfig_projbuild)
|
|
|
|
list(APPEND kconfig_projbuilds ${kconfig_projbuild})
|
|
|
|
endif()
|
2019-07-16 10:39:12 -04:00
|
|
|
if(sdkconfig_rename)
|
|
|
|
list(APPEND sdkconfig_renames ${sdkconfig_rename})
|
|
|
|
endif()
|
2018-02-26 23:45:30 -05:00
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
2019-04-26 01:42:10 -04:00
|
|
|
# Store the list version of kconfigs and kconfig_projbuilds
|
|
|
|
idf_build_set_property(KCONFIGS "${kconfigs}")
|
|
|
|
idf_build_set_property(KCONFIG_PROJBUILDS "${kconfig_projbuilds}")
|
|
|
|
|
|
|
|
idf_build_get_property(idf_target IDF_TARGET)
|
2019-06-27 06:30:42 -04:00
|
|
|
idf_build_get_property(idf_path IDF_PATH)
|
|
|
|
|
|
|
|
string(REPLACE ";" " " kconfigs "${kconfigs}")
|
|
|
|
string(REPLACE ";" " " kconfig_projbuilds "${kconfig_projbuilds}")
|
2019-07-16 10:39:12 -04:00
|
|
|
string(REPLACE ";" " " sdkconfig_renames "${sdkconfig_renames}")
|
2019-06-27 06:30:42 -04:00
|
|
|
|
2019-09-10 03:58:52 -04:00
|
|
|
# These are the paths for files which will contain the generated "source" lines for COMPONENT_KCONFIGS and
|
|
|
|
# COMPONENT_KCONFIGS_PROJBUILD
|
|
|
|
set(kconfigs_projbuild_path "${CMAKE_CURRENT_BINARY_DIR}/kconfigs_projbuild.in")
|
|
|
|
set(kconfigs_path "${CMAKE_CURRENT_BINARY_DIR}/kconfigs.in")
|
|
|
|
|
2019-06-27 06:30:42 -04:00
|
|
|
# Place config-related environment arguments into config.env file
|
|
|
|
# to work around command line length limits for execute_process
|
|
|
|
# on Windows & CMake < 3.11
|
|
|
|
set(config_env_path "${CMAKE_CURRENT_BINARY_DIR}/config.env")
|
|
|
|
configure_file("${idf_path}/tools/kconfig_new/config.env.in" ${config_env_path})
|
|
|
|
idf_build_set_property(CONFIG_ENV_PATH ${config_env_path})
|
2019-04-26 01:42:10 -04:00
|
|
|
|
|
|
|
if(sdkconfig_defaults)
|
2019-10-22 01:01:13 -04:00
|
|
|
foreach(sdkconfig_default ${sdkconfig_defaults})
|
|
|
|
list(APPEND defaults_arg --defaults "${sdkconfig_default}")
|
|
|
|
endforeach()
|
2018-01-11 21:49:13 -05:00
|
|
|
endif()
|
2018-02-26 23:45:30 -05:00
|
|
|
|
2019-10-22 01:01:13 -04:00
|
|
|
if(sdkconfig_defaults)
|
|
|
|
foreach(sdkconfig_default ${sdkconfig_defaults})
|
|
|
|
if(EXISTS "${sdkconfig_default}.${idf_target}")
|
|
|
|
list(APPEND defaults_arg --defaults "${sdkconfig_default}.${idf_target}")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
2018-10-18 23:51:51 -04:00
|
|
|
endif()
|
|
|
|
|
2019-04-26 01:42:10 -04:00
|
|
|
idf_build_get_property(root_kconfig __ROOT_KCONFIG)
|
2019-07-16 10:39:12 -04:00
|
|
|
idf_build_get_property(root_sdkconfig_rename __ROOT_SDKCONFIG_RENAME)
|
2019-04-26 01:42:10 -04:00
|
|
|
idf_build_get_property(python PYTHON)
|
|
|
|
|
2019-10-21 07:44:19 -04:00
|
|
|
set(prepare_kconfig_files_command
|
|
|
|
${python} ${idf_path}/tools/kconfig_new/prepare_kconfig_files.py
|
|
|
|
--env-file ${config_env_path})
|
|
|
|
|
2018-02-26 23:45:30 -05:00
|
|
|
set(confgen_basecommand
|
2019-04-26 01:42:10 -04:00
|
|
|
${python} ${idf_path}/tools/kconfig_new/confgen.py
|
|
|
|
--kconfig ${root_kconfig}
|
2019-07-16 10:39:12 -04:00
|
|
|
--sdkconfig-rename ${root_sdkconfig_rename}
|
2019-04-26 01:42:10 -04:00
|
|
|
--config ${sdkconfig}
|
2018-02-26 23:45:30 -05:00
|
|
|
${defaults_arg}
|
2019-06-27 06:30:42 -04:00
|
|
|
--env-file ${config_env_path})
|
2019-04-26 01:42:10 -04:00
|
|
|
|
|
|
|
idf_build_get_property(build_dir BUILD_DIR)
|
|
|
|
set(config_dir ${build_dir}/config)
|
|
|
|
file(MAKE_DIRECTORY "${config_dir}")
|
|
|
|
|
|
|
|
# Generate the config outputs
|
|
|
|
set(sdkconfig_cmake ${config_dir}/sdkconfig.cmake)
|
|
|
|
set(sdkconfig_header ${config_dir}/sdkconfig.h)
|
|
|
|
set(sdkconfig_json ${config_dir}/sdkconfig.json)
|
2019-05-23 06:08:22 -04:00
|
|
|
set(sdkconfig_json_menus ${config_dir}/kconfig_menus.json)
|
2019-04-26 01:42:10 -04:00
|
|
|
|
|
|
|
idf_build_get_property(output_sdkconfig __OUTPUT_SDKCONFIG)
|
|
|
|
if(output_sdkconfig)
|
2019-10-21 07:44:19 -04:00
|
|
|
execute_process(
|
|
|
|
COMMAND ${prepare_kconfig_files_command})
|
2019-04-26 01:42:10 -04:00
|
|
|
execute_process(
|
|
|
|
COMMAND ${confgen_basecommand}
|
|
|
|
--output header ${sdkconfig_header}
|
|
|
|
--output cmake ${sdkconfig_cmake}
|
|
|
|
--output json ${sdkconfig_json}
|
|
|
|
--output json_menus ${sdkconfig_json_menus}
|
|
|
|
--output config ${sdkconfig}
|
|
|
|
RESULT_VARIABLE config_result)
|
|
|
|
else()
|
2019-10-21 07:44:19 -04:00
|
|
|
execute_process(
|
|
|
|
COMMAND ${prepare_kconfig_files_command})
|
2019-04-26 01:42:10 -04:00
|
|
|
execute_process(
|
|
|
|
COMMAND ${confgen_basecommand}
|
|
|
|
--output header ${sdkconfig_header}
|
|
|
|
--output cmake ${sdkconfig_cmake}
|
|
|
|
--output json ${sdkconfig_json}
|
|
|
|
--output json_menus ${sdkconfig_json_menus}
|
|
|
|
RESULT_VARIABLE config_result)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(config_result)
|
|
|
|
message(FATAL_ERROR "Failed to run confgen.py (${confgen_basecommand}). Error ${config_result}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Add the generated config header to build specifications.
|
|
|
|
idf_build_set_property(INCLUDE_DIRECTORIES ${config_dir} APPEND)
|
|
|
|
|
|
|
|
# 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}")
|
|
|
|
|
|
|
|
idf_build_set_property(SDKCONFIG_HEADER ${sdkconfig_header})
|
|
|
|
idf_build_set_property(SDKCONFIG_JSON ${sdkconfig_json})
|
|
|
|
idf_build_set_property(SDKCONFIG_CMAKE ${sdkconfig_cmake})
|
|
|
|
idf_build_set_property(SDKCONFIG_JSON_MENUS ${sdkconfig_json_menus})
|
2019-06-14 23:17:16 -04:00
|
|
|
idf_build_set_property(CONFIG_DIR ${config_dir})
|
2019-04-26 01:42:10 -04:00
|
|
|
|
2019-09-10 03:58:52 -04:00
|
|
|
if(CMAKE_HOST_WIN32 AND DEFINED ENV{MSYSTEM})
|
|
|
|
idf_build_get_property(menuconfig_depends __MENUCONFIG_DEPENDS)
|
|
|
|
idf_build_get_property(mconf __MCONF)
|
2018-02-26 23:45:30 -05:00
|
|
|
|
2019-09-10 03:58:52 -04:00
|
|
|
set(MENUCONFIG_CMD ${mconf})
|
|
|
|
else()
|
|
|
|
set(MENUCONFIG_CMD "MENUCONFIG_STYLE=aquatic" ${python} ${idf_path}/tools/kconfig_new/menuconfig.py)
|
|
|
|
endif()
|
2019-04-14 23:46:50 -04:00
|
|
|
|
2019-09-10 03:58:52 -04:00
|
|
|
# Generate the menuconfig target
|
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
|
2019-10-21 07:44:19 -04:00
|
|
|
COMMAND ${prepare_kconfig_files_command}
|
2019-11-08 08:40:28 -05:00
|
|
|
COMMAND ${confgen_basecommand}
|
|
|
|
--env "IDF_TARGET=${idf_target}"
|
|
|
|
--dont-write-deprecated
|
|
|
|
--output config ${sdkconfig}
|
2018-02-26 23:45:30 -05:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E env
|
2019-09-10 03:58:52 -04:00
|
|
|
"COMPONENT_KCONFIGS_SOURCE_FILE=${kconfigs_path}"
|
|
|
|
"COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE=${kconfigs_projbuild_path}"
|
2018-05-06 22:01:16 -04:00
|
|
|
"IDF_CMAKE=y"
|
2019-04-26 01:42:10 -04:00
|
|
|
"KCONFIG_CONFIG=${sdkconfig}"
|
2019-06-14 23:20:43 -04:00
|
|
|
"IDF_TARGET=${idf_target}"
|
2019-09-10 03:58:52 -04:00
|
|
|
${MENUCONFIG_CMD} ${root_kconfig}
|
2019-05-27 11:50:31 -04:00
|
|
|
# VERBATIM cannot be used here because it cannot handle ${mconf}="winpty mconf-idf" and the escaping must be
|
|
|
|
# done manually
|
2019-03-14 04:54:04 -04:00
|
|
|
USES_TERMINAL
|
|
|
|
# additional run of confgen esures that the deprecated options will be inserted into sdkconfig (for backward
|
|
|
|
# compatibility)
|
2019-04-26 01:42:10 -04:00
|
|
|
COMMAND ${confgen_basecommand} --env "IDF_TARGET=${idf_target}" --output config ${sdkconfig}
|
2019-03-14 04:54:04 -04:00
|
|
|
)
|
2018-02-26 23:45:30 -05:00
|
|
|
|
2018-05-16 02:54:22 -04:00
|
|
|
# Custom target to run confserver.py from the build tool
|
|
|
|
add_custom_target(confserver
|
2019-10-21 07:44:19 -04:00
|
|
|
COMMAND ${prepare_kconfig_files_command}
|
2019-06-27 06:30:42 -04:00
|
|
|
COMMAND ${PYTHON} ${IDF_PATH}/tools/kconfig_new/confserver.py
|
|
|
|
--env-file ${config_env_path}
|
|
|
|
--kconfig ${IDF_PATH}/Kconfig
|
2019-07-16 10:39:12 -04:00
|
|
|
--sdkconfig-rename ${root_sdkconfig_rename}
|
2019-06-27 06:30:42 -04:00
|
|
|
--config ${sdkconfig}
|
2018-05-16 02:54:22 -04:00
|
|
|
VERBATIM
|
|
|
|
USES_TERMINAL)
|
2019-03-14 04:54:04 -04:00
|
|
|
endfunction()
|