Merge branch 'bugfix/check_include_dirs' into 'master'

CMake: Check if component include dirs are directories

See merge request espressif/esp-idf!5701
This commit is contained in:
Angus Gratton
2019-08-12 12:45:11 +08:00
3 changed files with 21 additions and 10 deletions

View File

@@ -1,5 +1,5 @@
idf_component_register(SRCS "esp_tls.c"
INCLUDE_DIRS "."
PRIVATE_INCLUDE_DIRS "private_include"
PRIV_INCLUDE_DIRS "private_include"
REQUIRES mbedtls
PRIV_REQUIRES lwip nghttp)

View File

@@ -5,5 +5,5 @@ idf_component_register(SRCS "transport.c"
"transport_utils.c"
"transport_strcasestr.c"
INCLUDE_DIRS "include"
PRIVATE_INCLUDE_DIRS "private_include"
PRIV_INCLUDE_DIRS "private_include"
REQUIRES lwip esp-tls)

View File

@@ -232,10 +232,10 @@ function(__component_get_requirements)
file(REMOVE ${component_requires_file})
endfunction()
# __component_add_sources, __component_check_target
# __component_add_sources, __component_check_target, __component_add_include_dirs
#
# Utility macros for component registration. Adds source files and checks target requirements
# respectively.
# Utility macros for component registration. Adds source files and checks target requirements,
# and adds include directories respectively.
macro(__component_add_sources sources)
set(sources "")
if(__SRCS)
@@ -279,6 +279,16 @@ macro(__component_add_sources sources)
list(REMOVE_DUPLICATES sources)
endmacro()
macro(__component_add_include_dirs lib dirs type)
foreach(dir ${dirs})
get_filename_component(_dir ${dir} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_LIST_DIR})
if(NOT IS_DIRECTORY ${_dir})
message(FATAL_ERROR "Include directory '${_dir}' is not a directory.")
endif()
target_include_directories(${lib} ${type} ${_dir})
endforeach()
endmacro()
macro(__component_check_target)
if(__REQUIRED_IDF_TARGETS)
idf_build_get_property(idf_target IDF_TARGET)
@@ -324,6 +334,7 @@ macro(__component_set_all_dependencies)
endif()
endmacro()
# idf_component_get_property
#
# @brief Retrieve the value of the specified component property
@@ -436,16 +447,16 @@ function(idf_component_register)
if(sources OR __EMBED_FILES OR __EMBED_TXTFILES)
add_library(${component_lib} STATIC ${sources})
__component_set_property(${component_target} COMPONENT_TYPE LIBRARY)
target_include_directories(${component_lib} PUBLIC ${__INCLUDE_DIRS})
target_include_directories(${component_lib} PRIVATE ${__PRIV_INCLUDE_DIRS})
target_include_directories(${component_lib} PUBLIC ${config_dir})
__component_add_include_dirs(${component_lib} "${__INCLUDE_DIRS}" PUBLIC)
__component_add_include_dirs(${component_lib} "${__PRIV_INCLUDE_DIRS}" PRIVATE)
__component_add_include_dirs(${component_lib} "${config_dir}" PUBLIC)
set_target_properties(${component_lib} PROPERTIES OUTPUT_NAME ${COMPONENT_NAME})
__ldgen_add_component(${component_lib})
else()
add_library(${component_lib} INTERFACE)
__component_set_property(${component_target} COMPONENT_TYPE CONFIG_ONLY)
target_include_directories(${component_lib} INTERFACE ${__INCLUDE_DIRS})
target_include_directories(${component_lib} INTERFACE ${config_dir})
__component_add_include_dirs(${component_lib} "${__INCLUDE_DIRS}" INTERFACE)
__component_add_include_dirs(${component_lib} "${config_dir}" INTERFACE)
endif()
# Alias the static/interface library created for linking to external targets.