diff --git a/tools/cmakev2/compat.cmake b/tools/cmakev2/compat.cmake index 62edfdfb2f8..55cd384f44c 100644 --- a/tools/cmakev2/compat.cmake +++ b/tools/cmakev2/compat.cmake @@ -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) diff --git a/tools/cmakev2/component.cmake b/tools/cmakev2/component.cmake index a3bf07c7b16..27e9481149f 100644 --- a/tools/cmakev2/component.cmake +++ b/tools/cmakev2/component.cmake @@ -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() diff --git a/tools/cmakev2/project.cmake b/tools/cmakev2/project.cmake index fdd754d9c4c..4e0a6352310 100644 --- a/tools/cmakev2/project.cmake +++ b/tools/cmakev2/project.cmake @@ -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)