From 88320062b81bc4026dada134dcf90b2b27a83c81 Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Tue, 27 Aug 2019 15:24:31 +0800 Subject: [PATCH 1/3] cmake: make build components available before immediately Previous implementation only builds list of components included in the build during component registration. Since the build components is known as the requirements expansion is ongoing, update the list here instead. --- tools/cmake/build.cmake | 4 ++++ tools/cmake/component.cmake | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake index 9285a53e1c..1d11e04a56 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -220,6 +220,10 @@ 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) + __component_get_property(component_alias ${component_target} COMPONENT_ALIAS) + idf_build_set_property(BUILD_COMPONENTS ${component_alias} APPEND) endif() endfunction() diff --git a/tools/cmake/component.cmake b/tools/cmake/component.cmake index a7f099e4bf..aec650a605 100644 --- a/tools/cmake/component.cmake +++ b/tools/cmake/component.cmake @@ -481,10 +481,6 @@ function(idf_component_register) # Set dependencies __component_set_all_dependencies() - # Add the component to built components - idf_build_set_property(__BUILD_COMPONENTS ${component_lib} APPEND) - idf_build_set_property(BUILD_COMPONENTS ${component_alias} APPEND) - # Make the COMPONENT_LIB variable available in the component CMakeLists.txt set(COMPONENT_LIB ${component_lib} PARENT_SCOPE) # COMPONENT_TARGET is deprecated but is made available with same function From 826568a12065e84aadcce2ba833cdf70c3f613c5 Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Tue, 27 Aug 2019 20:40:29 +0800 Subject: [PATCH 2/3] 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 30d59bf8fa..3cca63ebe8 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 1d11e04a56..d4938b116e 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 aec650a605..426f494f18 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 a8e28a12d8..bdbef4a0c6 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() From fe9edc3ebe11f5c1505a62b35525e7ac569da790 Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Wed, 28 Aug 2019 14:52:09 +0800 Subject: [PATCH 3/3] docs: fix typo of build component aliases name --- docs/en/api-guides/build-system.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/api-guides/build-system.rst b/docs/en/api-guides/build-system.rst index 3cca63ebe8..1be2fe3a4c 100644 --- a/docs/en/api-guides/build-system.rst +++ b/docs/en/api-guides/build-system.rst @@ -988,7 +988,7 @@ For example, to get the Python interpreter used for the build: - BUILD_DIR - build directory; set from ``idf_build_process`` BUILD_DIR argument - 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`` + - BUILD_COMPONENT_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