2019-04-26 01:42:10 -04:00
|
|
|
# idf_build_get_property
|
|
|
|
#
|
|
|
|
# @brief Retrieve the value of the specified property related to ESP-IDF build.
|
|
|
|
#
|
|
|
|
# @param[out] var the variable to store the value in
|
|
|
|
# @param[in] property the property to get the value of
|
|
|
|
#
|
|
|
|
# @param[in, optional] GENERATOR_EXPRESSION (option) retrieve the generator expression for the property
|
|
|
|
# instead of actual value
|
|
|
|
function(idf_build_get_property var property)
|
|
|
|
cmake_parse_arguments(_ "GENERATOR_EXPRESSION" "" "" ${ARGN})
|
|
|
|
if(__GENERATOR_EXPRESSION)
|
|
|
|
set(val "$<TARGET_PROPERTY:__idf_build_target,${property}>")
|
|
|
|
else()
|
|
|
|
get_property(val TARGET __idf_build_target PROPERTY ${property})
|
|
|
|
endif()
|
|
|
|
set(${var} ${val} PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# idf_build_set_property
|
|
|
|
#
|
|
|
|
# @brief Set the value of the specified property related to ESP-IDF build. The property is
|
|
|
|
# also added to the internal list of build properties if it isn't there already.
|
|
|
|
#
|
|
|
|
# @param[in] property the property to set the value of
|
2023-12-21 05:30:57 -05:00
|
|
|
# @param[in] value value of the property
|
2019-04-26 01:42:10 -04:00
|
|
|
#
|
|
|
|
# @param[in, optional] APPEND (option) append the value to the current value of the
|
|
|
|
# property instead of replacing it
|
|
|
|
function(idf_build_set_property property value)
|
|
|
|
cmake_parse_arguments(_ "APPEND" "" "" ${ARGN})
|
|
|
|
|
2022-08-28 16:16:23 -04:00
|
|
|
# Fixup property value, e.g. for compatibility. (Overwrites variable 'value'.)
|
|
|
|
__build_fixup_property("${property}" "${value}" value)
|
|
|
|
|
2019-04-26 01:42:10 -04:00
|
|
|
if(__APPEND)
|
|
|
|
set_property(TARGET __idf_build_target APPEND PROPERTY ${property} ${value})
|
|
|
|
else()
|
|
|
|
set_property(TARGET __idf_build_target PROPERTY ${property} ${value})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Keep track of set build properties so that they can be exported to a file that
|
|
|
|
# will be included in early expansion script.
|
|
|
|
idf_build_get_property(build_properties __BUILD_PROPERTIES)
|
|
|
|
if(NOT property IN_LIST build_properties)
|
|
|
|
idf_build_set_property(__BUILD_PROPERTIES "${property}" APPEND)
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# idf_build_unset_property
|
|
|
|
#
|
|
|
|
# @brief Unset the value of the specified property related to ESP-IDF build. Equivalent
|
|
|
|
# to setting the property to an empty string; though it also removes the property
|
|
|
|
# from the internal list of build properties.
|
|
|
|
#
|
|
|
|
# @param[in] property the property to unset the value of
|
|
|
|
function(idf_build_unset_property property)
|
|
|
|
idf_build_set_property(${property} "") # set to an empty value
|
|
|
|
idf_build_get_property(build_properties __BUILD_PROPERTIES) # remove from tracked properties
|
|
|
|
list(REMOVE_ITEM build_properties ${property})
|
|
|
|
idf_build_set_property(__BUILD_PROPERTIES "${build_properties}")
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
#
|
|
|
|
# Retrieve the IDF_PATH repository's version, either using a version
|
|
|
|
# file or Git revision. Sets the IDF_VER build property.
|
|
|
|
#
|
|
|
|
function(__build_get_idf_git_revision)
|
|
|
|
idf_build_get_property(idf_path IDF_PATH)
|
2021-02-26 01:39:23 -05:00
|
|
|
git_describe(idf_ver_git "${idf_path}" "--match=v*.*")
|
2019-04-26 01:42:10 -04:00
|
|
|
if(EXISTS "${idf_path}/version.txt")
|
|
|
|
file(STRINGS "${idf_path}/version.txt" idf_ver_t)
|
|
|
|
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${idf_path}/version.txt")
|
|
|
|
else()
|
|
|
|
set(idf_ver_t ${idf_ver_git})
|
|
|
|
endif()
|
|
|
|
# cut IDF_VER to required 32 characters.
|
|
|
|
string(SUBSTRING "${idf_ver_t}" 0 31 idf_ver)
|
2022-08-28 15:20:48 -04:00
|
|
|
idf_build_set_property(COMPILE_DEFINITIONS "IDF_VER=\"${idf_ver}\"" APPEND)
|
2019-04-26 01:42:10 -04:00
|
|
|
git_submodule_check("${idf_path}")
|
|
|
|
idf_build_set_property(IDF_VER ${idf_ver})
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
#
|
|
|
|
# Sets initial list of build specifications (compile options, definitions, etc.) common across
|
|
|
|
# all library targets built under the ESP-IDF build system. These build specifications are added
|
|
|
|
# privately using the directory-level CMake commands (add_compile_options, include_directories, etc.)
|
|
|
|
# during component registration.
|
|
|
|
#
|
|
|
|
function(__build_set_default_build_specifications)
|
|
|
|
unset(compile_definitions)
|
|
|
|
unset(compile_options)
|
|
|
|
unset(c_compile_options)
|
|
|
|
unset(cxx_compile_options)
|
|
|
|
|
2023-05-05 01:37:49 -04:00
|
|
|
list(APPEND compile_definitions "_GLIBCXX_USE_POSIX_SEMAPHORE" # These two lines enable libstd++ to use
|
|
|
|
"_GLIBCXX_HAVE_POSIX_SEMAPHORE" # posix-semaphores from components/pthread
|
|
|
|
"_GNU_SOURCE")
|
2019-04-26 01:42:10 -04:00
|
|
|
|
|
|
|
list(APPEND compile_options "-ffunction-sections"
|
|
|
|
"-fdata-sections"
|
|
|
|
# warning-related flags
|
|
|
|
"-Wall"
|
|
|
|
"-Werror=all"
|
|
|
|
"-Wno-error=unused-function"
|
|
|
|
"-Wno-error=unused-variable"
|
2022-11-18 07:29:39 -05:00
|
|
|
"-Wno-error=unused-but-set-variable"
|
2019-04-26 01:42:10 -04:00
|
|
|
"-Wno-error=deprecated-declarations"
|
|
|
|
"-Wextra"
|
|
|
|
"-Wno-unused-parameter"
|
|
|
|
"-Wno-sign-compare"
|
2022-01-19 21:28:42 -05:00
|
|
|
# ignore multiple enum conversion warnings since gcc 11
|
|
|
|
# TODO: IDF-5163
|
|
|
|
"-Wno-enum-conversion"
|
2022-01-20 01:40:46 -05:00
|
|
|
# Default is dwarf-5 since GCC 11, fallback to dwarf-4 because of binary size
|
|
|
|
# TODO: IDF-5160
|
|
|
|
"-gdwarf-4"
|
2019-04-26 01:42:10 -04:00
|
|
|
# always generate debug symbols (even in release mode, these don't
|
|
|
|
# go into the final binary so have no impact on size
|
|
|
|
"-ggdb")
|
|
|
|
|
|
|
|
idf_build_set_property(COMPILE_DEFINITIONS "${compile_definitions}" APPEND)
|
|
|
|
idf_build_set_property(COMPILE_OPTIONS "${compile_options}" APPEND)
|
|
|
|
idf_build_set_property(C_COMPILE_OPTIONS "${c_compile_options}" APPEND)
|
|
|
|
idf_build_set_property(CXX_COMPILE_OPTIONS "${cxx_compile_options}" APPEND)
|
|
|
|
endfunction()
|
|
|
|
|
2022-06-03 09:28:31 -04:00
|
|
|
function(__build_set_lang_version)
|
|
|
|
if(NOT IDF_TARGET STREQUAL "linux")
|
|
|
|
# Building for chip targets: we use a known version of the toolchain.
|
|
|
|
# Use latest supported versions.
|
2023-10-30 23:28:06 -04:00
|
|
|
# Please update docs/en/api-guides/c.rst, docs/en/api-guides/cplusplus.rst and
|
2023-04-28 03:01:15 -04:00
|
|
|
# tools/test_apps/system/cxx_build_test/main/test_cxx_standard.cpp when changing this.
|
2022-06-03 09:28:31 -04:00
|
|
|
set(c_std gnu17)
|
2023-04-28 03:01:15 -04:00
|
|
|
set(cxx_std gnu++2b)
|
2022-06-03 09:28:31 -04:00
|
|
|
else()
|
|
|
|
enable_language(C CXX)
|
|
|
|
# Building for Linux target, fall back to an older version of the standard
|
|
|
|
# if the preferred one is not supported by the compiler.
|
|
|
|
set(preferred_c_versions gnu17 gnu11 gnu99)
|
|
|
|
set(ver_found FALSE)
|
|
|
|
foreach(c_version ${preferred_c_versions})
|
|
|
|
check_c_compiler_flag("-std=${c_version}" ver_${c_version}_supported)
|
|
|
|
if(ver_${c_version}_supported)
|
|
|
|
set(c_std ${c_version})
|
|
|
|
set(ver_found TRUE)
|
|
|
|
break()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
if(NOT ver_found)
|
|
|
|
message(FATAL_ERROR "Failed to set C language standard to one of the supported versions: "
|
|
|
|
"${preferred_c_versions}. Please upgrade the host compiler.")
|
|
|
|
endif()
|
|
|
|
|
2023-04-28 03:01:15 -04:00
|
|
|
set(preferred_cxx_versions gnu++2b gnu++20 gnu++2a gnu++17 gnu++14)
|
2022-06-03 09:28:31 -04:00
|
|
|
set(ver_found FALSE)
|
|
|
|
foreach(cxx_version ${preferred_cxx_versions})
|
|
|
|
check_cxx_compiler_flag("-std=${cxx_version}" ver_${cxx_version}_supported)
|
|
|
|
if(ver_${cxx_version}_supported)
|
|
|
|
set(cxx_std ${cxx_version})
|
|
|
|
set(ver_found TRUE)
|
|
|
|
break()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
if(NOT ver_found)
|
|
|
|
message(FATAL_ERROR "Failed to set C++ language standard to one of the supported versions: "
|
|
|
|
"${preferred_cxx_versions}. Please upgrade the host compiler.")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
idf_build_set_property(C_COMPILE_OPTIONS "-std=${c_std}" APPEND)
|
|
|
|
idf_build_set_property(CXX_COMPILE_OPTIONS "-std=${cxx_std}" APPEND)
|
|
|
|
endfunction()
|
|
|
|
|
2022-08-28 16:16:23 -04:00
|
|
|
#
|
|
|
|
# Perform any fixes or adjustments to the values stored in IDF build properties.
|
|
|
|
# This function only gets called from 'idf_build_set_property' and doesn't affect
|
|
|
|
# the properties set directly via 'set_property'.
|
|
|
|
#
|
|
|
|
function(__build_fixup_property property value out_var)
|
|
|
|
|
|
|
|
# Fixup COMPILE_DEFINITIONS property to support -D prefix, which had to be used in IDF v4.x projects.
|
|
|
|
if(property STREQUAL "COMPILE_DEFINITIONS" AND NOT "${value}" STREQUAL "")
|
|
|
|
string(REGEX REPLACE "^-D" "" stripped_value "${value}")
|
|
|
|
set("${out_var}" "${stripped_value}" PARENT_SCOPE)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
endfunction()
|
|
|
|
|
2019-04-26 01:42:10 -04:00
|
|
|
#
|
|
|
|
# Initialize the build. This gets called upon inclusion of idf.cmake to set internal
|
|
|
|
# properties used for the processing phase of the build.
|
|
|
|
#
|
|
|
|
function(__build_init idf_path)
|
2021-08-11 03:22:50 -04:00
|
|
|
|
|
|
|
set(target ${IDF_TARGET})
|
|
|
|
|
2020-05-18 04:38:07 -04:00
|
|
|
# Create the build target, to which the ESP-IDF build properties, dependencies are attached to.
|
|
|
|
# Must be global so as to be accessible from any subdirectory in custom projects.
|
2020-05-13 03:38:20 -04:00
|
|
|
add_library(__idf_build_target STATIC IMPORTED GLOBAL)
|
2019-04-26 01:42:10 -04:00
|
|
|
|
2021-03-31 02:35:00 -04:00
|
|
|
# Set the Python path (which may be passed in via -DPYTHON=) and store in a build property
|
|
|
|
set_default(PYTHON "python")
|
|
|
|
file(TO_CMAKE_PATH ${PYTHON} PYTHON)
|
|
|
|
idf_build_set_property(PYTHON ${PYTHON})
|
2019-04-26 01:42:10 -04:00
|
|
|
|
|
|
|
idf_build_set_property(IDF_PATH ${idf_path})
|
|
|
|
|
|
|
|
idf_build_set_property(__PREFIX idf)
|
|
|
|
idf_build_set_property(__CHECK_PYTHON 1)
|
2022-05-25 11:56:59 -04:00
|
|
|
idf_build_set_property(IDF_COMPONENT_MANAGER 0)
|
2019-04-26 01:42:10 -04:00
|
|
|
|
|
|
|
__build_set_default_build_specifications()
|
2022-06-03 09:28:31 -04:00
|
|
|
__build_set_lang_version()
|
2019-04-26 01:42:10 -04:00
|
|
|
|
|
|
|
# Add internal components to the build
|
|
|
|
idf_build_get_property(idf_path IDF_PATH)
|
|
|
|
idf_build_get_property(prefix __PREFIX)
|
|
|
|
file(GLOB component_dirs ${idf_path}/components/*)
|
2021-07-08 19:46:06 -04:00
|
|
|
list(SORT component_dirs)
|
2019-04-26 01:42:10 -04:00
|
|
|
foreach(component_dir ${component_dirs})
|
2021-09-23 07:50:42 -04:00
|
|
|
# A potential component must be a directory
|
|
|
|
if(IS_DIRECTORY ${component_dir})
|
|
|
|
__component_dir_quick_check(is_component ${component_dir})
|
|
|
|
if(is_component)
|
|
|
|
__component_add(${component_dir} ${prefix})
|
|
|
|
endif()
|
2019-05-20 02:36:55 -04:00
|
|
|
endif()
|
2019-04-26 01:42:10 -04:00
|
|
|
endforeach()
|
|
|
|
|
2021-08-11 03:22:50 -04:00
|
|
|
if("${target}" STREQUAL "linux")
|
2022-12-02 01:54:27 -05:00
|
|
|
set(requires_common freertos esp_hw_support heap log soc hal esp_rom esp_common esp_system linux)
|
2021-08-11 03:22:50 -04:00
|
|
|
idf_build_set_property(__COMPONENT_REQUIRES_COMMON "${requires_common}")
|
|
|
|
else()
|
2020-08-10 00:29:05 -04:00
|
|
|
# Set components required by all other components in the build
|
|
|
|
#
|
|
|
|
# - esp_hw_support is here for backward compatibility
|
2022-04-14 14:03:56 -04:00
|
|
|
set(requires_common cxx newlib freertos esp_hw_support heap log soc hal esp_rom esp_common esp_system)
|
2020-08-10 00:29:05 -04:00
|
|
|
idf_build_set_property(__COMPONENT_REQUIRES_COMMON "${requires_common}")
|
|
|
|
endif()
|
2019-04-26 01:42:10 -04:00
|
|
|
|
|
|
|
__build_get_idf_git_revision()
|
|
|
|
__kconfig_init()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# idf_build_component
|
|
|
|
#
|
2019-06-17 00:14:02 -04:00
|
|
|
# @brief Present a directory that contains a component to the build system.
|
2019-04-26 01:42:10 -04:00
|
|
|
# Relative paths are converted to absolute paths with respect to current directory.
|
2019-06-17 00:14:02 -04:00
|
|
|
# All calls to this command must be performed before idf_build_process.
|
2019-04-26 01:42:10 -04:00
|
|
|
#
|
2019-06-17 00:14:02 -04:00
|
|
|
# @note This command does not guarantee that the component will be processed
|
|
|
|
# during build (see the COMPONENTS argument description for command idf_build_process)
|
|
|
|
#
|
|
|
|
# @param[in] component_dir directory of the component
|
2019-04-26 01:42:10 -04:00
|
|
|
function(idf_build_component component_dir)
|
|
|
|
idf_build_get_property(prefix __PREFIX)
|
|
|
|
__component_add(${component_dir} ${prefix} 0)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
#
|
|
|
|
# Resolve the requirement component to the component target created for that component.
|
|
|
|
#
|
|
|
|
function(__build_resolve_and_add_req var component_target req type)
|
|
|
|
__component_get_target(_component_target ${req})
|
2019-08-05 23:14:44 -04:00
|
|
|
__component_get_property(_component_registered ${component_target} __COMPONENT_REGISTERED)
|
|
|
|
if(NOT _component_target OR NOT _component_registered)
|
2019-04-26 01:42:10 -04:00
|
|
|
message(FATAL_ERROR "Failed to resolve component '${req}'.")
|
|
|
|
endif()
|
|
|
|
__component_set_property(${component_target} ${type} ${_component_target} APPEND)
|
|
|
|
set(${var} ${_component_target} PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
#
|
|
|
|
# Build a list of components (in the form of component targets) to be added to the build
|
|
|
|
# based on public and private requirements. This list is saved in an internal property,
|
|
|
|
# __BUILD_COMPONENT_TARGETS.
|
|
|
|
#
|
|
|
|
function(__build_expand_requirements component_target)
|
|
|
|
# Since there are circular dependencies, make sure that we do not infinitely
|
|
|
|
# expand requirements for each component.
|
|
|
|
idf_build_get_property(component_targets_seen __COMPONENT_TARGETS_SEEN)
|
2019-05-28 09:43:03 -04:00
|
|
|
__component_get_property(component_registered ${component_target} __COMPONENT_REGISTERED)
|
|
|
|
if(component_target IN_LIST component_targets_seen OR NOT component_registered)
|
2019-04-26 01:42:10 -04:00
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
idf_build_set_property(__COMPONENT_TARGETS_SEEN ${component_target} APPEND)
|
|
|
|
|
|
|
|
get_property(reqs TARGET ${component_target} PROPERTY REQUIRES)
|
|
|
|
get_property(priv_reqs TARGET ${component_target} PROPERTY PRIV_REQUIRES)
|
2021-12-01 17:00:01 -05:00
|
|
|
__component_get_property(component_name ${component_target} COMPONENT_NAME)
|
2022-05-11 09:20:01 -04:00
|
|
|
__component_get_property(component_alias ${component_target} COMPONENT_ALIAS)
|
|
|
|
idf_build_get_property(common_reqs __COMPONENT_REQUIRES_COMMON)
|
|
|
|
list(APPEND reqs ${common_reqs})
|
|
|
|
|
|
|
|
if(reqs)
|
|
|
|
list(REMOVE_DUPLICATES reqs)
|
|
|
|
list(REMOVE_ITEM reqs ${component_alias} ${component_name})
|
|
|
|
endif()
|
2019-04-26 01:42:10 -04:00
|
|
|
|
|
|
|
foreach(req ${reqs})
|
2021-12-01 17:00:01 -05:00
|
|
|
depgraph_add_edge(${component_name} ${req} REQUIRES)
|
2019-04-26 01:42:10 -04:00
|
|
|
__build_resolve_and_add_req(_component_target ${component_target} ${req} __REQUIRES)
|
|
|
|
__build_expand_requirements(${_component_target})
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
foreach(req ${priv_reqs})
|
2021-12-01 17:00:01 -05:00
|
|
|
depgraph_add_edge(${component_name} ${req} PRIV_REQUIRES)
|
2019-04-26 01:42:10 -04:00
|
|
|
__build_resolve_and_add_req(_component_target ${component_target} ${req} __PRIV_REQUIRES)
|
|
|
|
__build_expand_requirements(${_component_target})
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
idf_build_get_property(build_component_targets __BUILD_COMPONENT_TARGETS)
|
|
|
|
if(NOT component_target IN_LIST build_component_targets)
|
|
|
|
idf_build_set_property(__BUILD_COMPONENT_TARGETS ${component_target} APPEND)
|
2019-08-27 08:40:29 -04:00
|
|
|
|
2019-08-27 03:24:31 -04:00
|
|
|
__component_get_property(component_lib ${component_target} COMPONENT_LIB)
|
|
|
|
idf_build_set_property(__BUILD_COMPONENTS ${component_lib} APPEND)
|
2019-08-27 08:40:29 -04:00
|
|
|
|
|
|
|
idf_build_get_property(prefix __PREFIX)
|
|
|
|
__component_get_property(component_prefix ${component_target} __PREFIX)
|
|
|
|
|
2019-08-27 03:24:31 -04:00
|
|
|
__component_get_property(component_alias ${component_target} COMPONENT_ALIAS)
|
2019-08-27 08:40:29 -04:00
|
|
|
|
|
|
|
idf_build_set_property(BUILD_COMPONENT_ALIASES ${component_alias} APPEND)
|
|
|
|
|
|
|
|
# Only put in the prefix in the name if it is not the default one
|
|
|
|
if(component_prefix STREQUAL prefix)
|
|
|
|
__component_get_property(component_name ${component_target} COMPONENT_NAME)
|
|
|
|
idf_build_set_property(BUILD_COMPONENTS ${component_name} APPEND)
|
|
|
|
else()
|
|
|
|
idf_build_set_property(BUILD_COMPONENTS ${component_alias} APPEND)
|
|
|
|
endif()
|
2019-04-26 01:42:10 -04:00
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
#
|
|
|
|
# Write a CMake file containing set build properties, owing to the fact that an internal
|
|
|
|
# list of properties is maintained in idf_build_set_property() call. This is used to convert
|
|
|
|
# those set properties to variables in the scope the output file is included in.
|
|
|
|
#
|
|
|
|
function(__build_write_properties output_file)
|
|
|
|
idf_build_get_property(build_properties __BUILD_PROPERTIES)
|
|
|
|
foreach(property ${build_properties})
|
|
|
|
idf_build_get_property(val ${property})
|
2020-10-05 18:14:48 -04:00
|
|
|
set(build_properties_text "${build_properties_text}\nset(${property} \"${val}\")")
|
2019-04-26 01:42:10 -04:00
|
|
|
endforeach()
|
|
|
|
file(WRITE ${output_file} "${build_properties_text}")
|
|
|
|
endfunction()
|
|
|
|
|
2022-01-24 08:53:37 -05:00
|
|
|
#
|
|
|
|
# Check if the Python interpreter used for the build has all the required modules.
|
|
|
|
#
|
|
|
|
function(__build_check_python)
|
|
|
|
idf_build_get_property(check __CHECK_PYTHON)
|
|
|
|
if(check)
|
|
|
|
idf_build_get_property(python PYTHON)
|
|
|
|
idf_build_get_property(idf_path IDF_PATH)
|
|
|
|
message(STATUS "Checking Python dependencies...")
|
|
|
|
execute_process(COMMAND "${python}" "${idf_path}/tools/idf_tools.py" "check-python-dependencies"
|
|
|
|
RESULT_VARIABLE result)
|
|
|
|
if(result EQUAL 1)
|
|
|
|
# check_python_dependencies returns error code 1 on failure
|
|
|
|
message(FATAL_ERROR "Some Python dependencies must be installed. Check above message for details.")
|
|
|
|
elseif(NOT result EQUAL 0)
|
|
|
|
# means check_python_dependencies.py failed to run at all, result should be an error message
|
|
|
|
message(FATAL_ERROR "Failed to run Python dependency check. Python: ${python}, Error: ${result}")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2019-05-09 06:17:16 -04:00
|
|
|
#
|
|
|
|
# Prepare for component processing expanding each component's project include
|
|
|
|
#
|
|
|
|
macro(__build_process_project_includes)
|
|
|
|
# Include the sdkconfig cmake file, since the following operations require
|
|
|
|
# knowledge of config values.
|
|
|
|
idf_build_get_property(sdkconfig_cmake SDKCONFIG_CMAKE)
|
|
|
|
include(${sdkconfig_cmake})
|
|
|
|
|
|
|
|
# Make each build property available as a read-only variable
|
|
|
|
idf_build_get_property(build_properties __BUILD_PROPERTIES)
|
|
|
|
foreach(build_property ${build_properties})
|
|
|
|
idf_build_get_property(val ${build_property})
|
|
|
|
set(${build_property} "${val}")
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
idf_build_get_property(build_component_targets __BUILD_COMPONENT_TARGETS)
|
|
|
|
|
|
|
|
# Include each component's project_include.cmake
|
|
|
|
foreach(component_target ${build_component_targets})
|
|
|
|
__component_get_property(dir ${component_target} COMPONENT_DIR)
|
|
|
|
__component_get_property(_name ${component_target} COMPONENT_NAME)
|
|
|
|
set(COMPONENT_NAME ${_name})
|
|
|
|
set(COMPONENT_DIR ${dir})
|
|
|
|
set(COMPONENT_PATH ${dir}) # this is deprecated, users are encouraged to use COMPONENT_DIR;
|
|
|
|
# retained for compatibility
|
|
|
|
if(EXISTS ${COMPONENT_DIR}/project_include.cmake)
|
|
|
|
include(${COMPONENT_DIR}/project_include.cmake)
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endmacro()
|
|
|
|
|
2019-04-26 01:42:10 -04:00
|
|
|
#
|
|
|
|
# Utility macro for setting default property value if argument is not specified
|
|
|
|
# for idf_build_process().
|
|
|
|
#
|
|
|
|
macro(__build_set_default var default)
|
|
|
|
set(_var __${var})
|
2020-04-29 02:07:23 -04:00
|
|
|
if(NOT "${${_var}}" STREQUAL "")
|
2019-04-26 01:42:10 -04:00
|
|
|
idf_build_set_property(${var} "${${_var}}")
|
|
|
|
else()
|
|
|
|
idf_build_set_property(${var} "${default}")
|
|
|
|
endif()
|
|
|
|
unset(_var)
|
|
|
|
endmacro()
|
|
|
|
|
2019-05-09 03:19:59 -04:00
|
|
|
#
|
|
|
|
# Import configs as build instance properties so that they are accessible
|
|
|
|
# using idf_build_get_config(). Config has to have been generated before calling
|
|
|
|
# this command.
|
|
|
|
#
|
|
|
|
function(__build_import_configs)
|
|
|
|
# Include the sdkconfig cmake file, since the following operations require
|
|
|
|
# knowledge of config values.
|
|
|
|
idf_build_get_property(sdkconfig_cmake SDKCONFIG_CMAKE)
|
|
|
|
include(${sdkconfig_cmake})
|
|
|
|
|
|
|
|
idf_build_set_property(__CONFIG_VARIABLES "${CONFIGS_LIST}")
|
|
|
|
foreach(config ${CONFIGS_LIST})
|
|
|
|
set_property(TARGET __idf_build_target PROPERTY ${config} "${${config}}")
|
|
|
|
endforeach()
|
|
|
|
endfunction()
|
|
|
|
|
2019-04-26 01:42:10 -04:00
|
|
|
# idf_build_process
|
|
|
|
#
|
|
|
|
# @brief Main processing step for ESP-IDF build: config generation, adding components to the build,
|
|
|
|
# dependency resolution, etc.
|
|
|
|
#
|
|
|
|
# @param[in] target ESP-IDF target
|
|
|
|
#
|
|
|
|
# @param[in, optional] PROJECT_DIR (single value) directory of the main project the buildsystem
|
|
|
|
# is processed for; defaults to CMAKE_SOURCE_DIR
|
|
|
|
# @param[in, optional] PROJECT_VER (single value) version string of the main project; defaults
|
2019-08-21 00:43:19 -04:00
|
|
|
# to 1
|
2019-04-26 01:42:10 -04:00
|
|
|
# @param[in, optional] PROJECT_NAME (single value) main project name, defaults to CMAKE_PROJECT_NAME
|
|
|
|
# @param[in, optional] SDKCONFIG (single value) sdkconfig output path, defaults to PROJECT_DIR/sdkconfig
|
|
|
|
# if PROJECT_DIR is set and CMAKE_SOURCE_DIR/sdkconfig if not
|
|
|
|
# @param[in, optional] SDKCONFIG_DEFAULTS (single value) config defaults file to use for the build; defaults
|
|
|
|
# to none (Kconfig defaults or previously generated config are used)
|
|
|
|
# @param[in, optional] BUILD_DIR (single value) directory for build artifacts; defautls to CMAKE_BINARY_DIR
|
2019-06-17 00:14:02 -04:00
|
|
|
# @param[in, optional] COMPONENTS (multivalue) select components to process among the components
|
|
|
|
# known by the build system
|
|
|
|
# (added via `idf_build_component`). This argument is used to trim the build.
|
|
|
|
# Other components are automatically added if they are required
|
|
|
|
# in the dependency chain, i.e.
|
|
|
|
# the public and private requirements of the components in this list
|
|
|
|
# are automatically added, and in
|
|
|
|
# turn the public and private requirements of those requirements,
|
|
|
|
# so on and so forth. If not specified, all components known to the build system
|
|
|
|
# are processed.
|
2019-05-09 06:17:16 -04:00
|
|
|
macro(idf_build_process target)
|
2019-04-26 01:42:10 -04:00
|
|
|
set(options)
|
2019-10-22 01:01:13 -04:00
|
|
|
set(single_value PROJECT_DIR PROJECT_VER PROJECT_NAME BUILD_DIR SDKCONFIG)
|
|
|
|
set(multi_value COMPONENTS SDKCONFIG_DEFAULTS)
|
2019-04-26 01:42:10 -04:00
|
|
|
cmake_parse_arguments(_ "${options}" "${single_value}" "${multi_value}" ${ARGN})
|
|
|
|
|
|
|
|
idf_build_set_property(BOOTLOADER_BUILD "${BOOTLOADER_BUILD}")
|
|
|
|
|
2022-11-23 07:00:11 -05:00
|
|
|
idf_build_set_property(IDF_TOOLCHAIN "${IDF_TOOLCHAIN}")
|
|
|
|
|
2019-04-26 01:42:10 -04:00
|
|
|
# Check build target is specified. Since this target corresponds to a component
|
|
|
|
# name, the target component is automatically added to the list of common component
|
|
|
|
# requirements.
|
2019-05-09 06:17:16 -04:00
|
|
|
if(target STREQUAL "")
|
2019-04-26 01:42:10 -04:00
|
|
|
message(FATAL_ERROR "Build target not specified.")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
idf_build_set_property(IDF_TARGET ${target})
|
|
|
|
|
2022-05-17 03:13:30 -04:00
|
|
|
if("${target}" STREQUAL "esp32" OR "${target}" STREQUAL "esp32s2" OR "${target}" STREQUAL "esp32s3")
|
|
|
|
idf_build_set_property(IDF_TARGET_ARCH "xtensa")
|
|
|
|
elseif("${target}" STREQUAL "linux")
|
|
|
|
# No arch specified for linux host builds at the moment
|
|
|
|
idf_build_set_property(IDF_TARGET_ARCH "")
|
|
|
|
else()
|
|
|
|
idf_build_set_property(IDF_TARGET_ARCH "riscv")
|
|
|
|
endif()
|
|
|
|
|
2019-04-26 01:42:10 -04:00
|
|
|
__build_set_default(PROJECT_DIR ${CMAKE_SOURCE_DIR})
|
|
|
|
__build_set_default(PROJECT_NAME ${CMAKE_PROJECT_NAME})
|
2019-08-21 00:43:19 -04:00
|
|
|
__build_set_default(PROJECT_VER 1)
|
2019-04-26 01:42:10 -04:00
|
|
|
__build_set_default(BUILD_DIR ${CMAKE_BINARY_DIR})
|
|
|
|
|
|
|
|
idf_build_get_property(project_dir PROJECT_DIR)
|
|
|
|
__build_set_default(SDKCONFIG "${project_dir}/sdkconfig")
|
|
|
|
|
|
|
|
__build_set_default(SDKCONFIG_DEFAULTS "")
|
|
|
|
|
2022-01-24 08:53:37 -05:00
|
|
|
# Check for required Python modules
|
|
|
|
__build_check_python()
|
|
|
|
|
2020-08-10 00:29:05 -04:00
|
|
|
idf_build_get_property(target IDF_TARGET)
|
2022-05-17 03:13:30 -04:00
|
|
|
idf_build_get_property(arch IDF_TARGET_ARCH)
|
2020-08-10 00:29:05 -04:00
|
|
|
|
2021-08-11 03:22:50 -04:00
|
|
|
if(NOT "${target}" STREQUAL "linux")
|
2022-05-17 03:13:30 -04:00
|
|
|
idf_build_set_property(__COMPONENT_REQUIRES_COMMON ${arch} APPEND)
|
2020-08-10 00:29:05 -04:00
|
|
|
endif()
|
2019-04-26 01:42:10 -04:00
|
|
|
|
2020-08-25 10:36:40 -04:00
|
|
|
# Call for component manager to download dependencies for all components
|
2022-05-25 11:56:59 -04:00
|
|
|
idf_build_get_property(idf_component_manager IDF_COMPONENT_MANAGER)
|
|
|
|
if(idf_component_manager EQUAL 1)
|
2022-04-08 11:58:05 -04:00
|
|
|
idf_build_get_property(build_dir BUILD_DIR)
|
|
|
|
set(managed_components_list_file ${build_dir}/managed_components_list.temp.cmake)
|
|
|
|
set(local_components_list_file ${build_dir}/local_components_list.temp.yml)
|
2020-08-25 10:36:40 -04:00
|
|
|
|
2022-04-08 11:58:05 -04:00
|
|
|
set(__contents "components:\n")
|
2024-01-30 08:56:58 -05:00
|
|
|
idf_build_get_property(build_component_targets BUILD_COMPONENT_TARGETS)
|
|
|
|
foreach(__build_component_target ${build_component_targets})
|
|
|
|
__component_get_property(__component_name ${__build_component_target} COMPONENT_NAME)
|
|
|
|
__component_get_property(__component_dir ${__build_component_target} COMPONENT_DIR)
|
|
|
|
|
|
|
|
# Exclude components could be passed with -DEXCLUDE_COMPONENTS
|
|
|
|
# after the call to __component_add finished in the last run.
|
|
|
|
# Need to check if the component is excluded again
|
|
|
|
if(NOT __component_name IN_LIST EXCLUDE_COMPONENTS)
|
|
|
|
set(__contents "${__contents} - name: \"${__component_name}\"\n path: \"${__component_dir}\"\n")
|
|
|
|
endif()
|
2022-04-08 11:58:05 -04:00
|
|
|
endforeach()
|
2020-08-25 10:36:40 -04:00
|
|
|
|
2022-04-08 11:58:05 -04:00
|
|
|
file(WRITE ${local_components_list_file} "${__contents}")
|
2020-08-25 10:36:40 -04:00
|
|
|
|
2022-04-08 11:58:05 -04:00
|
|
|
# Call for the component manager to prepare remote dependencies
|
|
|
|
idf_build_get_property(python PYTHON)
|
2022-05-13 13:21:30 -04:00
|
|
|
idf_build_get_property(component_manager_interface_version __COMPONENT_MANAGER_INTERFACE_VERSION)
|
2022-08-31 04:47:36 -04:00
|
|
|
idf_build_get_property(dependencies_lock_file DEPENDENCIES_LOCK)
|
|
|
|
|
2022-04-08 11:58:05 -04:00
|
|
|
execute_process(COMMAND ${python}
|
|
|
|
"-m"
|
|
|
|
"idf_component_manager.prepare_components"
|
|
|
|
"--project_dir=${project_dir}"
|
2022-08-31 04:47:36 -04:00
|
|
|
"--lock_path=${dependencies_lock_file}"
|
2022-05-13 13:21:30 -04:00
|
|
|
"--interface_version=${component_manager_interface_version}"
|
2022-04-08 11:58:05 -04:00
|
|
|
"prepare_dependencies"
|
|
|
|
"--local_components_list_file=${local_components_list_file}"
|
|
|
|
"--managed_components_list_file=${managed_components_list_file}"
|
|
|
|
RESULT_VARIABLE result
|
|
|
|
ERROR_VARIABLE error)
|
|
|
|
|
|
|
|
if(NOT result EQUAL 0)
|
|
|
|
message(FATAL_ERROR "${error}")
|
2020-08-25 10:36:40 -04:00
|
|
|
endif()
|
2022-04-08 11:58:05 -04:00
|
|
|
|
|
|
|
include(${managed_components_list_file})
|
|
|
|
|
|
|
|
# Add managed components to list of all components
|
|
|
|
# `managed_components` contains the list of components installed by the component manager
|
|
|
|
# It is defined in the temporary managed_components_list_file file
|
|
|
|
set(__COMPONENTS "${__COMPONENTS};${managed_components}")
|
|
|
|
|
|
|
|
file(REMOVE ${managed_components_list_file})
|
|
|
|
file(REMOVE ${local_components_list_file})
|
2020-08-25 10:36:40 -04:00
|
|
|
else()
|
2022-04-08 11:58:05 -04:00
|
|
|
message(VERBOSE "IDF Component manager was explicitly disabled by setting IDF_COMPONENT_MANAGER=0")
|
|
|
|
|
2020-08-25 10:36:40 -04:00
|
|
|
idf_build_get_property(__component_targets __COMPONENT_TARGETS)
|
|
|
|
set(__components_with_manifests "")
|
|
|
|
foreach(__component_target ${__component_targets})
|
|
|
|
__component_get_property(__component_dir ${__component_target} COMPONENT_DIR)
|
|
|
|
if(EXISTS "${__component_dir}/idf_component.yml")
|
|
|
|
set(__components_with_manifests "${__components_with_manifests}\t${__component_dir}\n")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
if(NOT "${__components_with_manifests}" STREQUAL "")
|
|
|
|
message(WARNING "\"idf_component.yml\" file was found for components:\n${__components_with_manifests}"
|
|
|
|
"However, the component manager is not enabled.")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2019-04-26 01:42:10 -04:00
|
|
|
# Perform early expansion of component CMakeLists.txt in CMake scripting mode.
|
|
|
|
# It is here we retrieve the public and private requirements of each component.
|
|
|
|
# It is also here we add the common component requirements to each component's
|
|
|
|
# own requirements.
|
2019-06-14 23:26:32 -04:00
|
|
|
__component_get_requirements()
|
|
|
|
|
|
|
|
idf_build_get_property(component_targets __COMPONENT_TARGETS)
|
2019-05-24 06:32:42 -04:00
|
|
|
|
2019-04-26 01:42:10 -04:00
|
|
|
# Finally, do component expansion. In this case it simply means getting a final list
|
|
|
|
# of build component targets given the requirements set by each component.
|
2019-06-14 23:26:32 -04:00
|
|
|
|
|
|
|
# Check if we need to trim the components first, and build initial components list
|
|
|
|
# from that.
|
2019-04-26 01:42:10 -04:00
|
|
|
if(__COMPONENTS)
|
|
|
|
unset(component_targets)
|
|
|
|
foreach(component ${__COMPONENTS})
|
|
|
|
__component_get_target(component_target ${component})
|
|
|
|
if(NOT component_target)
|
|
|
|
message(FATAL_ERROR "Failed to resolve component '${component}'.")
|
|
|
|
endif()
|
|
|
|
list(APPEND component_targets ${component_target})
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
foreach(component_target ${component_targets})
|
|
|
|
__build_expand_requirements(${component_target})
|
|
|
|
endforeach()
|
2019-06-14 23:26:32 -04:00
|
|
|
idf_build_unset_property(__COMPONENT_TARGETS_SEEN)
|
2019-04-26 01:42:10 -04:00
|
|
|
|
|
|
|
# Get a list of common component requirements in component targets form (previously
|
|
|
|
# we just have a list of component names)
|
2019-05-28 09:43:03 -04:00
|
|
|
idf_build_get_property(common_reqs __COMPONENT_REQUIRES_COMMON)
|
2019-04-26 01:42:10 -04:00
|
|
|
foreach(common_req ${common_reqs})
|
|
|
|
__component_get_target(component_target ${common_req})
|
|
|
|
__component_get_property(lib ${component_target} COMPONENT_LIB)
|
|
|
|
idf_build_set_property(___COMPONENT_REQUIRES_COMMON ${lib} APPEND)
|
|
|
|
endforeach()
|
|
|
|
|
2019-05-24 06:32:42 -04:00
|
|
|
# Generate config values in different formats
|
|
|
|
idf_build_get_property(sdkconfig SDKCONFIG)
|
|
|
|
idf_build_get_property(sdkconfig_defaults SDKCONFIG_DEFAULTS)
|
|
|
|
__kconfig_generate_config("${sdkconfig}" "${sdkconfig_defaults}")
|
|
|
|
__build_import_configs()
|
|
|
|
|
2019-05-20 03:07:15 -04:00
|
|
|
# All targets built under this scope is with the ESP-IDF build system
|
|
|
|
set(ESP_PLATFORM 1)
|
2022-08-28 15:20:48 -04:00
|
|
|
idf_build_set_property(COMPILE_DEFINITIONS "ESP_PLATFORM" APPEND)
|
2019-05-20 03:07:15 -04:00
|
|
|
|
2019-04-26 01:42:10 -04:00
|
|
|
# Perform component processing (inclusion of project_include.cmake, adding component
|
|
|
|
# subdirectories, creating library targets, linking libraries, etc.)
|
2019-04-14 23:45:08 -04:00
|
|
|
__build_process_project_includes()
|
|
|
|
|
2019-04-26 01:42:10 -04:00
|
|
|
idf_build_get_property(idf_path IDF_PATH)
|
|
|
|
add_subdirectory(${idf_path} ${build_dir}/esp-idf)
|
2019-05-20 03:07:15 -04:00
|
|
|
|
|
|
|
unset(ESP_PLATFORM)
|
2019-05-09 06:17:16 -04:00
|
|
|
endmacro()
|
2019-04-26 01:42:10 -04:00
|
|
|
|
|
|
|
# idf_build_executable
|
|
|
|
#
|
|
|
|
# @brief Specify the executable the build system can attach dependencies to (for generating
|
|
|
|
# files used for linking, targets which should execute before creating the specified executable,
|
|
|
|
# generating additional binary files, generating files related to flashing, etc.)
|
|
|
|
function(idf_build_executable elf)
|
2019-11-20 08:18:28 -05:00
|
|
|
# Set additional link flags for the executable
|
|
|
|
idf_build_get_property(link_options LINK_OPTIONS)
|
2022-08-28 11:07:49 -04:00
|
|
|
set_property(TARGET ${elf} APPEND PROPERTY LINK_OPTIONS "${link_options}")
|
2019-11-20 08:18:28 -05:00
|
|
|
|
2019-04-26 01:42:10 -04:00
|
|
|
# Propagate link dependencies from component library targets to the executable
|
2019-06-04 07:05:33 -04:00
|
|
|
idf_build_get_property(link_depends __LINK_DEPENDS)
|
|
|
|
set_property(TARGET ${elf} APPEND PROPERTY LINK_DEPENDS "${link_depends}")
|
2019-04-26 01:42:10 -04:00
|
|
|
|
|
|
|
# Set the EXECUTABLE_NAME and EXECUTABLE properties since there are generator expression
|
|
|
|
# from components that depend on it
|
2023-08-07 10:21:56 -04:00
|
|
|
get_filename_component(elf_name ${elf} NAME_WLE)
|
2020-03-29 22:01:39 -04:00
|
|
|
get_target_property(elf_dir ${elf} BINARY_DIR)
|
|
|
|
|
2019-04-26 01:42:10 -04:00
|
|
|
idf_build_set_property(EXECUTABLE_NAME ${elf_name})
|
|
|
|
idf_build_set_property(EXECUTABLE ${elf})
|
2020-03-29 22:01:39 -04:00
|
|
|
idf_build_set_property(EXECUTABLE_DIR "${elf_dir}")
|
2019-04-26 01:42:10 -04:00
|
|
|
|
|
|
|
# Add dependency of the build target to the executable
|
|
|
|
add_dependencies(${elf} __idf_build_target)
|
2019-05-09 03:19:59 -04:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# idf_build_get_config
|
|
|
|
#
|
|
|
|
# @brief Get value of specified config variable
|
|
|
|
function(idf_build_get_config var config)
|
|
|
|
cmake_parse_arguments(_ "GENERATOR_EXPRESSION" "" "" ${ARGN})
|
|
|
|
if(__GENERATOR_EXPRESSION)
|
|
|
|
set(val "$<TARGET_PROPERTY:__idf_build_target,${config}>")
|
|
|
|
else()
|
|
|
|
get_property(val TARGET __idf_build_target PROPERTY ${config})
|
|
|
|
endif()
|
|
|
|
set(${var} ${val} PARENT_SCOPE)
|
2019-10-30 22:39:17 -04:00
|
|
|
endfunction()
|