From 99f8a811fd335ef913fbc8e022293e423542f803 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Mon, 15 Apr 2019 11:15:58 +1000 Subject: [PATCH] cmake: Warn if something which looks like a component directory isn't Otherwise, fails build at the add_subdirectory stage --- CMakeLists.txt | 2 +- tools/cmake/component.cmake | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c98d3d8c5e..a65cb36fa0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/tools/cmake/component.cmake b/tools/cmake/component.cmake index ccb7bc02a1..2f65dca2ec 100644 --- a/tools/cmake/component.cmake +++ b/tools/cmake/component.cmake @@ -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.