From: Renz Christian Bagaporo Date: Wed, 10 Jul 2019 08:28:44 +0000 (+0800) Subject: cmake: refactor finding components X-Git-Tag: v3.3~10^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d7569b586206fd0b0ebc7ad0785c051285566b6a;p=esp-idf cmake: refactor finding components --- diff --git a/tools/cmake/component_utils.cmake b/tools/cmake/component_utils.cmake index 6f07a040d9..f988d8f71a 100644 --- a/tools/cmake/component_utils.cmake +++ b/tools/cmake/component_utils.cmake @@ -28,49 +28,47 @@ endfunction() # earlier in the component_dirs list take precedence. function(components_find_all component_dirs component_paths component_names test_component_names) # component_dirs entries can be files or lists of files - set(paths "") - set(names "") - set(test_names "") + set(_paths "") + set(_names "") + set(_test_names "") # start by expanding the component_dirs list with all subdirectories foreach(dir ${component_dirs}) - # Iterate any subdirectories for values - file(GLOB subdirs LIST_DIRECTORIES true "${dir}/*") - foreach(subdir ${subdirs}) - set(component_dirs "${component_dirs};${subdir}") - endforeach() - endforeach() - - # Look for a component in each component_dirs entry - foreach(dir ${component_dirs}) - debug("Looking for CMakeLists.txt in ${dir}") - file(GLOB component "${dir}/CMakeLists.txt") - if(component) - debug("CMakeLists.txt file ${component}") - get_filename_component(component "${component}" DIRECTORY) - get_filename_component(name "${component}" NAME) + if(EXISTS ${dir}/CMakeLists.txt) + get_filename_component(_path "${dir}" ABSOLUTE) + get_filename_component(_name "${_path}" NAME) if(NOT name IN_LIST names) - list(APPEND names "${name}") - list(APPEND paths "${component}") + list(APPEND _names "${_name}") + list(APPEND _paths "${_path}") + endif() - # Look for test component directory - file(GLOB test "${component}/test/CMakeLists.txt") - if(test) - list(APPEND test_names "${name}") - endif() + if(EXISTS "${_path}/test/CMakeLists.txt") + list(APPEND _test_names "${_name}") endif() - else() # no CMakeLists.txt file - # test for legacy component.mk and warn - file(GLOB legacy_component "${dir}/component.mk") - if(legacy_component) + else() + if(EXISTS ${dir}/component.mk) get_filename_component(legacy_component "${legacy_component}" DIRECTORY) message(WARNING "Component ${legacy_component} contains old-style component.mk but no CMakeLists.txt. " "Component will be skipped.") + else() + if(NOT __recursing) # recurse only once + file(GLOB subdirs LIST_DIRECTORIES true "${dir}/*") + + set(__recursing 1) + components_find_all("${subdirs}" __paths __names __test_names) + set(__recursing 0) + + if(__paths) + list(APPEND _paths "${__paths}") + list(APPEND _names "${__names}") + list(APPEND _test_names "${__test_names}") + endif() + endif() endif() endif() endforeach() - set(${component_paths} ${paths} PARENT_SCOPE) - set(${component_names} ${names} PARENT_SCOPE) - set(${test_component_names} ${test_names} PARENT_SCOPE) + set(${test_component_names} "${_test_names}" PARENT_SCOPE) + set(${component_paths} "${_paths}" PARENT_SCOPE) + set(${component_names} "${_names}" PARENT_SCOPE) endfunction()