cmake: Warn if something which looks like a component directory isn't

Otherwise, fails build at the add_subdirectory stage
This commit is contained in:
Angus Gratton 2019-04-15 11:15:58 +10:00 committed by Renz Christian Bagaporo
parent 3cf56ea6b6
commit 99f8a811fd
2 changed files with 13 additions and 1 deletions

View file

@ -110,7 +110,7 @@ foreach(component_target ${build_component_targets})
set(COMPONENT_NAME ${_name})
set(COMPONENT_DIR ${dir})
set(COMPONENT_ALIAS ${alias})
set(COMPONENT_PATH ${dir}) # same deprecation situation here
set(COMPONENT_PATH ${dir}) # also deprecated, see comment in previous loop
idf_build_get_property(build_prefix __PREFIX)
set(__idf_component_context 1)
if(NOT prefix STREQUAL build_prefix)

View file

@ -112,6 +112,18 @@ function(__component_add component_dir prefix)
get_filename_component(abs_dir ${component_dir} ABSOLUTE)
get_filename_component(base_dir ${abs_dir} NAME)
# Check this is really a directory and that a CMakeLists.txt file for this component exists
# - warn and skip anything which isn't valid looking (probably cruft)
if(NOT IS_DIRECTORY "${abs_dir}")
message(WARNING "Unexpected file in components directory: ${abs_dir}")
return()
endif()
if(NOT EXISTS "${abs_dir}/CMakeLists.txt")
message(WARNING "Component directory ${abs_dir} does not contain a CMakeLists.txt file. "
"No component will be added")
return()
endif()
set(component_name ${base_dir})
# The component target has three underscores as a prefix. The corresponding component library
# only has two.