From 826568a12065e84aadcce2ba833cdf70c3f613c5 Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Tue, 27 Aug 2019 20:40:29 +0800 Subject: [PATCH] cmake: introduce BUILD_COMPONENT_ALIASES This commit makes it so that BUILD_COMPONENT holds only the component, and a new property BUILD_COMPONENT_ALIASES hold the full name of the component. This also removes erroneous check for duplicate components, as this can never happen: (1) if two components have the same name but different prefixes, the internal names are still unique between them (2)if two components happen to have the same name and same prefix, the latter would override the former --- docs/en/api-guides/build-system.rst | 3 ++- tools/cmake/build.cmake | 16 +++++++++++++++- tools/cmake/component.cmake | 10 +++------- tools/cmake/project.cmake | 7 +++++-- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/docs/en/api-guides/build-system.rst b/docs/en/api-guides/build-system.rst index 30d59bf8f..3cca63ebe 100644 --- a/docs/en/api-guides/build-system.rst +++ b/docs/en/api-guides/build-system.rst @@ -987,7 +987,8 @@ For example, to get the Python interpreter used for the build: message(STATUS "The Python intepreter is: ${python}") - BUILD_DIR - build directory; set from ``idf_build_process`` BUILD_DIR argument - - BUILD_COMPONENTS - list of components (more specifically, component aliases) included in the build; set by ``idf_build_process`` + - BUILD_COMPONENTS - list of components included in the build; set by ``idf_build_process`` + - BUILD_COMPONENTS_ALIASES - list of library alias of components included in the build; set by ``idf_build_process`` - C_COMPILE_OPTIONS - compile options applied to all components' C source files - COMPILE_OPTIONS - compile options applied to all components' source files, regardless of it being C or C++ - COMPILE_DEFINITIONS - compile definitions applied to all component source files diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake index 1d11e04a5..d4938b116 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -220,10 +220,24 @@ function(__build_expand_requirements component_target) 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) + __component_get_property(component_lib ${component_target} COMPONENT_LIB) idf_build_set_property(__BUILD_COMPONENTS ${component_lib} APPEND) + + idf_build_get_property(prefix __PREFIX) + __component_get_property(component_prefix ${component_target} __PREFIX) + __component_get_property(component_alias ${component_target} COMPONENT_ALIAS) - idf_build_set_property(BUILD_COMPONENTS ${component_alias} APPEND) + + 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() endif() endfunction() diff --git a/tools/cmake/component.cmake b/tools/cmake/component.cmake index aec650a60..426f494f1 100644 --- a/tools/cmake/component.cmake +++ b/tools/cmake/component.cmake @@ -56,13 +56,8 @@ function(__component_get_target var name_or_alias) foreach(component_target ${component_targets}) __component_get_property(_component_name ${component_target} COMPONENT_NAME) if(name_or_alias STREQUAL _component_name) - # There should only be one component of the same name - if(NOT target) - set(target ${component_target}) - else() - message(FATAL_ERROR "Multiple components with name '${name_or_alias}' found.") - return() - endif() + set(target ${component_target}) + break() endif() endforeach() set(${var} ${target} PARENT_SCOPE) @@ -191,6 +186,7 @@ function(__component_add component_dir prefix) __component_set_property(${component_target} COMPONENT_NAME ${component_name}) __component_set_property(${component_target} COMPONENT_DIR ${component_dir}) __component_set_property(${component_target} COMPONENT_ALIAS ${component_alias}) + __component_set_property(${component_target} __PREFIX ${prefix}) # Set Kconfig related properties on the component diff --git a/tools/cmake/project.cmake b/tools/cmake/project.cmake index a8e28a12d..bdbef4a0c 100644 --- a/tools/cmake/project.cmake +++ b/tools/cmake/project.cmake @@ -352,13 +352,16 @@ macro(project project_name) # so that it treats components equally. # # This behavior should only be when user did not set REQUIRES/PRIV_REQUIRES manually. - idf_build_get_property(build_components BUILD_COMPONENTS) + idf_build_get_property(build_components BUILD_COMPONENT_ALIASES) if(idf::main IN_LIST build_components) __component_get_target(main_target idf::main) __component_get_property(reqs ${main_target} REQUIRES) __component_get_property(priv_reqs ${main_target} PRIV_REQUIRES) idf_build_get_property(common_reqs __COMPONENT_REQUIRES_COMMON) if(reqs STREQUAL common_reqs AND NOT priv_reqs) #if user has not set any requirements + if(test_components) + list(REMOVE_ITEM build_components ${test_components}) + endif() list(REMOVE_ITEM build_components idf::main) __component_get_property(lib ${main_target} COMPONENT_LIB) set_property(TARGET ${lib} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${build_components}") @@ -391,7 +394,7 @@ macro(project project_name) target_link_libraries(${project_elf} "-Wl,--no-whole-archive") endif() - idf_build_get_property(build_components BUILD_COMPONENTS) + idf_build_get_property(build_components BUILD_COMPONENT_ALIASES) if(test_components) list(REMOVE_ITEM build_components ${test_components}) endif()