cmake: refactor finding components

This commit is contained in:
Renz Christian Bagaporo
2019-07-10 17:40:13 +08:00
parent 2fa98e031c
commit 0138827492

View File

@@ -85,47 +85,45 @@ endfunction()
# earlier in the component_dirs list take precedence. # earlier in the component_dirs list take precedence.
function(components_find_all component_dirs component_paths component_names) function(components_find_all component_dirs component_paths component_names)
# component_dirs entries can be files or lists of files # component_dirs entries can be files or lists of files
set(paths "") set(_paths "")
set(names "") set(_names "")
# start by expanding the component_dirs list with all subdirectories # start by expanding the component_dirs list with all subdirectories
foreach(dir ${component_dirs}) foreach(dir ${component_dirs})
# Iterate any subdirectories for values if(EXISTS ${dir}/CMakeLists.txt)
file(GLOB subdirs LIST_DIRECTORIES true "${dir}/*") get_filename_component(_path "${dir}" ABSOLUTE)
foreach(subdir ${subdirs}) get_filename_component(_name "${_path}" NAME)
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(NOT name IN_LIST names) if(NOT name IN_LIST names)
set(names "${names};${name}") list(APPEND _names "${_name}")
set(paths "${paths};${component}") list(APPEND _paths "${_path}")
endif() endif()
else()
else() # no CMakeLists.txt file if(EXISTS ${dir}/component.mk)
# test for legacy component.mk and warn
file(GLOB legacy_component "${dir}/component.mk")
if(legacy_component)
get_filename_component(legacy_component "${legacy_component}" DIRECTORY) get_filename_component(legacy_component "${legacy_component}" DIRECTORY)
message(WARNING "Component ${legacy_component} contains old-style component.mk but no CMakeLists.txt. " message(WARNING "Component ${legacy_component} contains old-style component.mk but no CMakeLists.txt. "
"Component will be skipped.") "Component will be skipped.")
endif() else()
endif() if(NOT __recursing) # recurse only once
file(GLOB subdirs LIST_DIRECTORIES true "${dir}/*")
set(__recursing 1)
components_find_all("${subdirs}" __paths __names)
set(__recursing 0)
if(__paths)
list(APPEND _paths "${__paths}")
list(APPEND _names "${__names}")
endif()
endif()
endif()
endif()
endforeach() endforeach()
set(${component_paths} ${paths} PARENT_SCOPE) set(${component_paths} "${_paths}" PARENT_SCOPE)
set(${component_names} ${names} PARENT_SCOPE) set(${component_names} "${_names}" PARENT_SCOPE)
endfunction() endfunction()
# expand_component_requirements: Recursively expand a component's requirements, # expand_component_requirements: Recursively expand a component's requirements,
# setting global properties BUILD_COMPONENTS & BUILD_COMPONENT_PATHS and # setting global properties BUILD_COMPONENTS & BUILD_COMPONENT_PATHS and
# also invoking the components to call register_component() above, # also invoking the components to call register_component() above,