2018-01-12 02:49:13 +00:00
|
|
|
include(ExternalProject)
|
|
|
|
|
2019-04-26 05:42:10 +00:00
|
|
|
function(__kconfig_init)
|
|
|
|
idf_build_get_property(idf_path IDF_PATH)
|
2018-11-30 08:07:09 +00:00
|
|
|
|
2019-04-26 05:42:10 +00:00
|
|
|
idf_build_set_property(__ROOT_KCONFIG ${idf_path}/Kconfig)
|
2019-07-16 14:39:12 +00:00
|
|
|
idf_build_set_property(__ROOT_SDKCONFIG_RENAME ${idf_path}/sdkconfig.rename)
|
2019-04-26 05:42:10 +00:00
|
|
|
idf_build_set_property(__OUTPUT_SDKCONFIG 1)
|
|
|
|
endfunction()
|
2018-12-11 02:33:09 +00:00
|
|
|
|
2019-04-26 05:42:10 +00: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")
|
2021-07-08 23:46:06 +00:00
|
|
|
list(SORT kconfig)
|
2019-04-26 05:42:10 +00:00
|
|
|
__component_set_property(${component_target} KCONFIG "${kconfig}")
|
|
|
|
file(GLOB kconfig "${component_dir}/Kconfig.projbuild")
|
2021-07-08 23:46:06 +00:00
|
|
|
list(SORT kconfig)
|
2019-04-26 05:42:10 +00:00
|
|
|
__component_set_property(${component_target} KCONFIG_PROJBUILD "${kconfig}")
|
2019-07-16 14:39:12 +00:00
|
|
|
file(GLOB sdkconfig_rename "${component_dir}/sdkconfig.rename")
|
2021-07-08 23:46:06 +00:00
|
|
|
list(SORT sdkconfig_rename)
|
2019-07-16 14:39:12 +00:00
|
|
|
__component_set_property(${component_target} SDKCONFIG_RENAME "${sdkconfig_rename}")
|
2019-04-26 05:42:10 +00:00
|
|
|
endfunction()
|
2018-12-11 02:33:09 +00:00
|
|
|
|
2021-08-11 06:59:16 +00:00
|
|
|
#
|
|
|
|
# Add bootloader components Kconfig and Kconfig.projbuild files to BOOTLOADER_KCONFIG
|
|
|
|
# and BOOTLOADER_KCONFIGS_PROJ properties respectively.
|
|
|
|
#
|
|
|
|
function(__kconfig_bootloader_component_add component_dir)
|
|
|
|
idf_build_get_property(bootloader_kconfigs BOOTLOADER_KCONFIGS)
|
|
|
|
idf_build_get_property(bootloader_kconfigs_proj BOOTLOADER_KCONFIGS_PROJ)
|
|
|
|
|
|
|
|
file(GLOB kconfig "${component_dir}/Kconfig")
|
2021-08-30 16:02:58 +00:00
|
|
|
list(SORT kconfig)
|
2021-08-11 06:59:16 +00:00
|
|
|
if(EXISTS "${kconfig}" AND NOT IS_DIRECTORY "${kconfig}")
|
|
|
|
list(APPEND bootloader_kconfigs "${kconfig}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
file(GLOB kconfig "${component_dir}/Kconfig.projbuild")
|
2021-08-30 16:02:58 +00:00
|
|
|
list(SORT kconfig)
|
2021-08-11 06:59:16 +00:00
|
|
|
if(EXISTS "${kconfig}" AND NOT IS_DIRECTORY "${kconfig}")
|
|
|
|
list(APPEND bootloader_kconfigs_proj "${kconfig}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
idf_build_set_property(BOOTLOADER_KCONFIGS "${bootloader_kconfigs}")
|
|
|
|
idf_build_set_property(BOOTLOADER_KCONFIGS_PROJ "${bootloader_kconfigs_proj}")
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
2019-04-26 05:42:10 +00: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 10:32:42 +00:00
|
|
|
idf_build_get_property(build_component_targets __BUILD_COMPONENT_TARGETS)
|
2019-04-26 05:42:10 +00:00
|
|
|
foreach(component_target ${component_targets})
|
2019-05-24 10:32:42 +00: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 14:39:12 +00:00
|
|
|
__component_get_property(sdkconfig_rename ${component_target} SDKCONFIG_RENAME)
|
2019-05-24 10:32:42 +00:00
|
|
|
if(kconfig)
|
|
|
|
list(APPEND kconfigs ${kconfig})
|
|
|
|
endif()
|
|
|
|
if(kconfig_projbuild)
|
|
|
|
list(APPEND kconfig_projbuilds ${kconfig_projbuild})
|
|
|
|
endif()
|
2019-07-16 14:39:12 +00:00
|
|
|
if(sdkconfig_rename)
|
|
|
|
list(APPEND sdkconfig_renames ${sdkconfig_rename})
|
|
|
|
endif()
|
2018-02-27 04:45:30 +00:00
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
2021-08-11 06:59:16 +00:00
|
|
|
# Take into account bootloader components configuration files
|
|
|
|
idf_build_get_property(bootloader_kconfigs BOOTLOADER_KCONFIGS)
|
|
|
|
idf_build_get_property(bootloader_kconfigs_proj BOOTLOADER_KCONFIGS_PROJ)
|
2021-08-30 16:01:43 +00:00
|
|
|
if(bootloader_kconfigs)
|
|
|
|
list(APPEND kconfigs "${bootloader_kconfigs}")
|
|
|
|
endif()
|
|
|
|
if(bootloader_kconfigs_proj)
|
|
|
|
list(APPEND kconfig_projbuilds "${bootloader_kconfigs_proj}")
|
|
|
|
endif()
|
2021-08-11 06:59:16 +00:00
|
|
|
|
2019-04-26 05:42:10 +00: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 10:30:42 +00:00
|
|
|
idf_build_get_property(idf_path IDF_PATH)
|
2020-06-26 09:37:34 +00:00
|
|
|
idf_build_get_property(idf_env_fpga __IDF_ENV_FPGA)
|
2019-06-27 10:30:42 +00:00
|
|
|
|
2019-09-10 07:58:52 +00: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 10:30:42 +00: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 05:42:10 +00:00
|
|
|
|
|
|
|
if(sdkconfig_defaults)
|
2019-10-22 05:01:13 +00:00
|
|
|
foreach(sdkconfig_default ${sdkconfig_defaults})
|
|
|
|
list(APPEND defaults_arg --defaults "${sdkconfig_default}")
|
|
|
|
endforeach()
|
2018-01-12 02:49:13 +00:00
|
|
|
endif()
|
2018-02-27 04:45:30 +00:00
|
|
|
|
2019-10-22 05:01:13 +00: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-19 03:51:51 +00:00
|
|
|
endif()
|
|
|
|
|
2019-04-26 05:42:10 +00:00
|
|
|
idf_build_get_property(root_kconfig __ROOT_KCONFIG)
|
2019-07-16 14:39:12 +00:00
|
|
|
idf_build_get_property(root_sdkconfig_rename __ROOT_SDKCONFIG_RENAME)
|
2019-04-26 05:42:10 +00:00
|
|
|
idf_build_get_property(python PYTHON)
|
|
|
|
|
2019-10-21 11:44:19 +00:00
|
|
|
set(prepare_kconfig_files_command
|
|
|
|
${python} ${idf_path}/tools/kconfig_new/prepare_kconfig_files.py
|
2020-10-05 22:13:55 +00:00
|
|
|
--list-separator=semicolon
|
2019-10-21 11:44:19 +00:00
|
|
|
--env-file ${config_env_path})
|
|
|
|
|
2018-02-27 04:45:30 +00:00
|
|
|
set(confgen_basecommand
|
2019-04-26 05:42:10 +00:00
|
|
|
${python} ${idf_path}/tools/kconfig_new/confgen.py
|
2020-10-05 22:13:55 +00:00
|
|
|
--list-separator=semicolon
|
2019-04-26 05:42:10 +00:00
|
|
|
--kconfig ${root_kconfig}
|
2019-07-16 14:39:12 +00:00
|
|
|
--sdkconfig-rename ${root_sdkconfig_rename}
|
2019-04-26 05:42:10 +00:00
|
|
|
--config ${sdkconfig}
|
2018-02-27 04:45:30 +00:00
|
|
|
${defaults_arg}
|
2019-06-27 10:30:42 +00:00
|
|
|
--env-file ${config_env_path})
|
2019-04-26 05:42:10 +00:00
|
|
|
|
|
|
|
idf_build_get_property(build_dir BUILD_DIR)
|
|
|
|
set(config_dir ${build_dir}/config)
|
|
|
|
file(MAKE_DIRECTORY "${config_dir}")
|
|
|
|
|
2020-05-08 00:41:18 +00:00
|
|
|
message(STATUS "Project sdkconfig file ${sdkconfig}")
|
|
|
|
|
2019-04-26 05:42:10 +00:00
|
|
|
# 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 10:08:22 +00:00
|
|
|
set(sdkconfig_json_menus ${config_dir}/kconfig_menus.json)
|
2019-04-26 05:42:10 +00:00
|
|
|
|
|
|
|
idf_build_get_property(output_sdkconfig __OUTPUT_SDKCONFIG)
|
|
|
|
if(output_sdkconfig)
|
2019-10-21 11:44:19 +00:00
|
|
|
execute_process(
|
|
|
|
COMMAND ${prepare_kconfig_files_command})
|
2019-04-26 05:42:10 +00: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 11:44:19 +00:00
|
|
|
execute_process(
|
|
|
|
COMMAND ${prepare_kconfig_files_command})
|
2019-04-26 05:42:10 +00: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 "${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-15 03:17:16 +00:00
|
|
|
idf_build_set_property(CONFIG_DIR ${config_dir})
|
2019-04-26 05:42:10 +00:00
|
|
|
|
2021-11-23 13:02:47 +00:00
|
|
|
set(MENUCONFIG_CMD ${python} -m menuconfig)
|
|
|
|
set(TERM_CHECK_CMD ${python} ${idf_path}/tools/check_term.py)
|
2019-04-15 03:46:50 +00:00
|
|
|
|
2019-09-10 07:58:52 +00:00
|
|
|
# Generate the menuconfig target
|
2018-02-27 04:45:30 +00:00
|
|
|
add_custom_target(menuconfig
|
2018-05-01 05:42:28 +00:00
|
|
|
${menuconfig_depends}
|
2018-02-27 04:45:30 +00:00
|
|
|
# create any missing config file, with defaults if necessary
|
2019-10-21 11:44:19 +00:00
|
|
|
COMMAND ${prepare_kconfig_files_command}
|
2019-11-08 13:40:28 +00:00
|
|
|
COMMAND ${confgen_basecommand}
|
|
|
|
--env "IDF_TARGET=${idf_target}"
|
2020-06-17 04:38:52 +00:00
|
|
|
--env "IDF_ENV_FPGA=${idf_env_fpga}"
|
2019-11-08 13:40:28 +00:00
|
|
|
--dont-write-deprecated
|
|
|
|
--output config ${sdkconfig}
|
2019-11-15 11:51:18 +00:00
|
|
|
COMMAND ${TERM_CHECK_CMD}
|
2018-02-27 04:45:30 +00:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E env
|
2019-09-10 07:58:52 +00:00
|
|
|
"COMPONENT_KCONFIGS_SOURCE_FILE=${kconfigs_path}"
|
|
|
|
"COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE=${kconfigs_projbuild_path}"
|
2019-04-26 05:42:10 +00:00
|
|
|
"KCONFIG_CONFIG=${sdkconfig}"
|
2019-06-15 03:20:43 +00:00
|
|
|
"IDF_TARGET=${idf_target}"
|
2020-06-17 04:38:52 +00:00
|
|
|
"IDF_ENV_FPGA=${idf_env_fpga}"
|
2019-09-10 07:58:52 +00:00
|
|
|
${MENUCONFIG_CMD} ${root_kconfig}
|
2019-03-14 08:54:04 +00:00
|
|
|
USES_TERMINAL
|
|
|
|
# additional run of confgen esures that the deprecated options will be inserted into sdkconfig (for backward
|
|
|
|
# compatibility)
|
2020-06-17 04:38:52 +00:00
|
|
|
COMMAND ${confgen_basecommand}
|
|
|
|
--env "IDF_TARGET=${idf_target}"
|
|
|
|
--env "IDF_ENV_FPGA=${idf_env_fpga}"
|
|
|
|
--output config ${sdkconfig}
|
2019-03-14 08:54:04 +00:00
|
|
|
)
|
2018-02-27 04:45:30 +00:00
|
|
|
|
2018-05-16 06:54:22 +00:00
|
|
|
# Custom target to run confserver.py from the build tool
|
|
|
|
add_custom_target(confserver
|
2019-10-21 11:44:19 +00:00
|
|
|
COMMAND ${prepare_kconfig_files_command}
|
2019-06-27 10:30:42 +00:00
|
|
|
COMMAND ${PYTHON} ${IDF_PATH}/tools/kconfig_new/confserver.py
|
|
|
|
--env-file ${config_env_path}
|
|
|
|
--kconfig ${IDF_PATH}/Kconfig
|
2019-07-16 14:39:12 +00:00
|
|
|
--sdkconfig-rename ${root_sdkconfig_rename}
|
2019-06-27 10:30:42 +00:00
|
|
|
--config ${sdkconfig}
|
2018-05-16 06:54:22 +00:00
|
|
|
VERBATIM
|
|
|
|
USES_TERMINAL)
|
2021-12-14 14:31:08 +00:00
|
|
|
|
|
|
|
add_custom_target(save-defconfig
|
|
|
|
COMMAND ${prepare_kconfig_files_command}
|
|
|
|
COMMAND ${confgen_basecommand}
|
|
|
|
--dont-write-deprecated
|
|
|
|
--output savedefconfig ${CMAKE_SOURCE_DIR}/sdkconfig.defaults
|
|
|
|
USES_TERMINAL
|
|
|
|
)
|
2019-03-14 08:54:04 +00:00
|
|
|
endfunction()
|