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
This commit is contained in:
Renz Christian Bagaporo 2019-08-27 20:40:29 +08:00
parent 88320062b8
commit 826568a120
4 changed files with 25 additions and 11 deletions

View file

@ -987,7 +987,8 @@ For example, to get the Python interpreter used for the build:
message(STATUS "The Python intepreter is: ${python}") message(STATUS "The Python intepreter is: ${python}")
- BUILD_DIR - build directory; set from ``idf_build_process`` BUILD_DIR argument - 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 - 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_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 - COMPILE_DEFINITIONS - compile definitions applied to all component source files

View file

@ -220,11 +220,25 @@ function(__build_expand_requirements component_target)
idf_build_get_property(build_component_targets __BUILD_COMPONENT_TARGETS) idf_build_get_property(build_component_targets __BUILD_COMPONENT_TARGETS)
if(NOT component_target IN_LIST build_component_targets) if(NOT component_target IN_LIST build_component_targets)
idf_build_set_property(__BUILD_COMPONENT_TARGETS ${component_target} APPEND) idf_build_set_property(__BUILD_COMPONENT_TARGETS ${component_target} APPEND)
__component_get_property(component_lib ${component_target} COMPONENT_LIB) __component_get_property(component_lib ${component_target} COMPONENT_LIB)
idf_build_set_property(__BUILD_COMPONENTS ${component_lib} APPEND) 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) __component_get_property(component_alias ${component_target} COMPONENT_ALIAS)
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) idf_build_set_property(BUILD_COMPONENTS ${component_alias} APPEND)
endif() endif()
endif()
endfunction() endfunction()
# #

View file

@ -56,13 +56,8 @@ function(__component_get_target var name_or_alias)
foreach(component_target ${component_targets}) foreach(component_target ${component_targets})
__component_get_property(_component_name ${component_target} COMPONENT_NAME) __component_get_property(_component_name ${component_target} COMPONENT_NAME)
if(name_or_alias STREQUAL _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}) set(target ${component_target})
else() break()
message(FATAL_ERROR "Multiple components with name '${name_or_alias}' found.")
return()
endif()
endif() endif()
endforeach() endforeach()
set(${var} ${target} PARENT_SCOPE) 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_NAME ${component_name})
__component_set_property(${component_target} COMPONENT_DIR ${component_dir}) __component_set_property(${component_target} COMPONENT_DIR ${component_dir})
__component_set_property(${component_target} COMPONENT_ALIAS ${component_alias}) __component_set_property(${component_target} COMPONENT_ALIAS ${component_alias})
__component_set_property(${component_target} __PREFIX ${prefix}) __component_set_property(${component_target} __PREFIX ${prefix})
# Set Kconfig related properties on the component # Set Kconfig related properties on the component

View file

@ -352,13 +352,16 @@ macro(project project_name)
# so that it treats components equally. # so that it treats components equally.
# #
# This behavior should only be when user did not set REQUIRES/PRIV_REQUIRES manually. # 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) if(idf::main IN_LIST build_components)
__component_get_target(main_target idf::main) __component_get_target(main_target idf::main)
__component_get_property(reqs ${main_target} REQUIRES) __component_get_property(reqs ${main_target} REQUIRES)
__component_get_property(priv_reqs ${main_target} PRIV_REQUIRES) __component_get_property(priv_reqs ${main_target} PRIV_REQUIRES)
idf_build_get_property(common_reqs __COMPONENT_REQUIRES_COMMON) 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(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) list(REMOVE_ITEM build_components idf::main)
__component_get_property(lib ${main_target} COMPONENT_LIB) __component_get_property(lib ${main_target} COMPONENT_LIB)
set_property(TARGET ${lib} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${build_components}") 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") target_link_libraries(${project_elf} "-Wl,--no-whole-archive")
endif() endif()
idf_build_get_property(build_components BUILD_COMPONENTS) idf_build_get_property(build_components BUILD_COMPONENT_ALIASES)
if(test_components) if(test_components)
list(REMOVE_ITEM build_components ${test_components}) list(REMOVE_ITEM build_components ${test_components})
endif() endif()