Merge branch 'bugfix/cmake_component_names' into 'master'

CMake: Component name related bugfixes

See merge request espressif/esp-idf!5921
This commit is contained in:
Angus Gratton 2019-09-17 11:16:25 +08:00
commit 96b96ae244
4 changed files with 28 additions and 14 deletions

View file

@ -1130,7 +1130,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_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 - 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,6 +220,24 @@ 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)
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_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() 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 set(target ${component_target})
if(NOT target) break()
set(target ${component_target})
else()
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
@ -482,10 +478,6 @@ function(idf_component_register)
# Set dependencies # Set dependencies
__component_set_all_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 # Make the COMPONENT_LIB variable available in the component CMakeLists.txt
set(COMPONENT_LIB ${component_lib} PARENT_SCOPE) set(COMPONENT_LIB ${component_lib} PARENT_SCOPE)
# COMPONENT_TARGET is deprecated but is made available with same function # COMPONENT_TARGET is deprecated but is made available with same function

View file

@ -353,13 +353,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}")
@ -392,7 +395,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()