From 8439bc1fa20eec1bd649876be6fdbb0695a4de5c Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Sun, 24 Aug 2025 13:42:31 +0200 Subject: [PATCH] feat(cmakev2/build): track components linked to library There may be multiple libraries, each linking a different set of components. Introduce a new library property, LIBRARY_COMPONENTS_LINKED, to track the components linked with a specific library. This property can be used, for example, by menuconfig to distinguish between included and excluded components on a per-library or per-executable basis, or by ldgen to identify linker scripts for the linked components. Signed-off-by: Frantisek Hrbata --- tools/cmakev2/build.cmake | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tools/cmakev2/build.cmake b/tools/cmakev2/build.cmake index a3d6e98bd25..4245aab22af 100644 --- a/tools/cmakev2/build.cmake +++ b/tools/cmakev2/build.cmake @@ -228,6 +228,14 @@ endfunction() ``INTERFACE`` option and link component targets to it based on the component names provided in the ``COMPONENTS`` option. If ``COMPONENTS`` option is not set, link component targets of all discovered components. + + List of library properties + + :LIBRARY_COMPONENTS: List of component as specified by the ``COMPONENTS`` + option. + :LIBRARY_COMPONENTS_LINKED: List of components linked to the library based + on recursive evaluations of the INTERFACE_LINK_LIBRARIES + and LINK_LIBRARIES target properties. #]] function(idf_build_library) set(options) @@ -271,4 +279,23 @@ function(idf_build_library) idf_component_get_property(component_interface "${component_name}" COMPONENT_INTERFACE) target_link_libraries("${ARG_INTERFACE}" INTERFACE "${component_interface}") endforeach() + + # Identify the components linked to the library by obtaining all targets + # that are transitively linked to the library and mapping these targets to + # components. + __get_target_dependencies(TARGET "${ARG_INTERFACE}" OUTPUT dependencies) + set(dep_component_interfaces) + foreach(dep IN LISTS dependencies) + __get_component_interface(COMPONENT "${dep}" OUTPUT component_interface) + if(NOT component_interface) + continue() + endif() + if("${component_interface}" IN_LIST dep_component_interfaces) + continue() + endif() + + list(APPEND dep_component_interfaces "${component_interface}") + idf_component_get_property(component_name "${component_interface}" COMPONENT_NAME) + idf_library_set_property("${ARG_INTERFACE}" LIBRARY_COMPONENTS_LINKED "${component_name}" APPEND) + endforeach() endfunction()