mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-01 18:50:34 +03:00
feat(cmakev2/compat): initialize common components within idf_component_register
Currently, the common components are initialized in the idf_project_init macro, which means they are included even for cmakev2 components. However, cmakev2 components are expected to explicitly specify all their dependencies instead of relying on common components being automatically linked. Therefore, common components are only relevant within the context of cmakev1 components. To address this, move the __init_common_components function call to idf_component_register and include common components only when they are truly needed for a cmakev1 component. Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
This commit is contained in:
@@ -159,6 +159,59 @@ function(idf_component_optional_requires req_type)
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
#[[
|
||||
__init_common_components()
|
||||
|
||||
Identify the commonly required components based on the target and
|
||||
architecture, and store them in the __COMPONENT_REQUIRES_COMMON build
|
||||
property. Their interfaces are stored in the __COMMON_COMPONENT_INTERFACES
|
||||
build property. The commonly required component interfaces are automatically
|
||||
linked to each cmakev1 component added through the idf_component_register
|
||||
function.
|
||||
|
||||
This function is called from the idf_component_register function and is
|
||||
evaluated only once per project, as ensured by the
|
||||
__COMMON_COMPONENTS_INITIALIZED build property. The cmakev2 components are
|
||||
expected to properly specify all their dependencies, rather than relying on
|
||||
common components to be automatically linked to them. Therefore, the common
|
||||
components are relevant only within the context of cmakev1 components.
|
||||
#]]
|
||||
function(__init_common_components)
|
||||
idf_build_get_property(common_components_initialized __COMMON_COMPONENTS_INITIALIZED)
|
||||
if(common_components_initialized)
|
||||
return()
|
||||
endif()
|
||||
|
||||
idf_build_get_property(idf_target IDF_TARGET)
|
||||
idf_build_get_property(idf_target_arch IDF_TARGET_ARCH)
|
||||
|
||||
# Define common components that are included as dependencies for each
|
||||
# component.
|
||||
if("${idf_target}" STREQUAL "linux")
|
||||
set(requires_common freertos esp_hw_support heap log soc hal esp_rom esp_common esp_system linux)
|
||||
else()
|
||||
set(requires_common cxx newlib freertos esp_hw_support heap log soc hal esp_rom esp_common
|
||||
esp_system ${idf_target_arch})
|
||||
endif()
|
||||
idf_build_set_property(__COMPONENT_REQUIRES_COMMON "${requires_common}")
|
||||
|
||||
# Set the common component interfaces first, before including them, so the
|
||||
# idf_component_include function can see the complete list of common
|
||||
# component interfaces.
|
||||
set(common_component_interfaces "")
|
||||
foreach(component_name IN LISTS requires_common)
|
||||
idf_component_get_property(component_interface "${component_name}" COMPONENT_INTERFACE)
|
||||
list(APPEND common_component_interfaces "${component_interface}")
|
||||
endforeach()
|
||||
idf_build_set_property(__COMMON_COMPONENT_INTERFACES "${common_component_interfaces}")
|
||||
|
||||
foreach(component_name IN LISTS requires_common)
|
||||
idf_component_include("${component_name}")
|
||||
endforeach()
|
||||
|
||||
idf_build_set_property(__COMMON_COMPONENTS_INITIALIZED YES)
|
||||
endfunction()
|
||||
|
||||
#[[api
|
||||
.. cmakev2:function:: idf_component_register
|
||||
|
||||
@@ -212,6 +265,9 @@ function(idf_component_register)
|
||||
PRIV_REQUIRES REQUIRED_IDF_TARGETS EMBED_FILES EMBED_TXTFILES)
|
||||
cmake_parse_arguments(ARG "${options}" "${one_value}" "${multi_value}" ${ARGN})
|
||||
|
||||
# Initialize and include commonly required components.
|
||||
__init_common_components()
|
||||
|
||||
if(ARG_REQUIRED_IDF_TARGETS)
|
||||
idf_build_get_property(idf_target IDF_TARGET)
|
||||
if(NOT idf_target IN_LIST ARG_REQUIRED_IDF_TARGETS)
|
||||
|
||||
@@ -663,6 +663,4 @@ function(idf_component_include name)
|
||||
|
||||
__get_compile_options(OUTPUT compile_options)
|
||||
target_compile_options("${component_real_target}" BEFORE PRIVATE "${compile_options}")
|
||||
|
||||
# FIXME: We likely still need to link the common component requirements here.
|
||||
endfunction()
|
||||
|
||||
@@ -505,44 +505,6 @@ function(__init_project_configuration)
|
||||
idf_build_set_property(LINKER_TYPE "${linker_type}")
|
||||
endfunction()
|
||||
|
||||
#[[
|
||||
__init_common_components()
|
||||
|
||||
Identify the commonly required components based on the target and
|
||||
architecture, and store them in the __COMPONENT_REQUIRES_COMMON build
|
||||
property. These components are automatically included, and their interfaces
|
||||
are stored in the __COMMON_COMPONENT_INTERFACES build property. The commonly
|
||||
required component interfaces are automatically linked to each component.
|
||||
#]]
|
||||
function(__init_common_components)
|
||||
idf_build_get_property(idf_target IDF_TARGET)
|
||||
idf_build_get_property(idf_target_arch IDF_TARGET_ARCH)
|
||||
|
||||
# Define common components that are included as dependencies for each
|
||||
# component.
|
||||
if("${idf_target}" STREQUAL "linux")
|
||||
set(requires_common freertos esp_hw_support heap log soc hal esp_rom esp_common esp_system linux)
|
||||
else()
|
||||
set(requires_common cxx newlib freertos esp_hw_support heap log soc hal esp_rom esp_common
|
||||
esp_system ${idf_target_arch})
|
||||
endif()
|
||||
idf_build_set_property(__COMPONENT_REQUIRES_COMMON "${requires_common}")
|
||||
|
||||
# Set the common component interfaces first, before including them, so the
|
||||
# idf_component_include function can see the complete list of common
|
||||
# component interfaces.
|
||||
set(common_component_interfaces "")
|
||||
foreach(component_name IN LISTS requires_common)
|
||||
idf_component_get_property(component_interface "${component_name}" COMPONENT_INTERFACE)
|
||||
list(APPEND common_component_interfaces "${component_interface}")
|
||||
endforeach()
|
||||
idf_build_set_property(__COMMON_COMPONENT_INTERFACES "${common_component_interfaces}")
|
||||
|
||||
foreach(component_name IN LISTS requires_common)
|
||||
idf_component_include("${component_name}")
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
#[[api
|
||||
.. cmakev2:macro:: idf_project_init
|
||||
|
||||
@@ -598,9 +560,6 @@ macro(idf_project_init)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# Initialize and include commonly required components.
|
||||
__init_common_components()
|
||||
|
||||
idf_build_set_property(__PROJECT_INITIALIZED YES)
|
||||
endif()
|
||||
unset(project_initialized)
|
||||
|
||||
Reference in New Issue
Block a user