2018-11-11 02:36:10 -05:00
|
|
|
function(debug message)
|
|
|
|
if(DEBUG)
|
|
|
|
message(STATUS "${message}")
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2018-10-18 23:51:51 -04:00
|
|
|
# Given a component name (find_name) and a list of component paths (component_paths),
|
|
|
|
# return the path to the component in 'variable'
|
|
|
|
#
|
|
|
|
# Fatal error is printed if the component is not found.
|
|
|
|
function(find_component_path find_name components component_paths variable)
|
|
|
|
list(FIND components ${find_name} idx)
|
|
|
|
if(NOT idx EQUAL -1)
|
|
|
|
list(GET component_paths ${idx} path)
|
|
|
|
set("${variable}" "${path}" PARENT_SCOPE)
|
|
|
|
return()
|
|
|
|
else()
|
|
|
|
endif()
|
|
|
|
# TODO: find a way to print the dependency chain that lead to this not-found component
|
2019-06-20 00:10:41 -04:00
|
|
|
message(FATAL_ERROR "Required component ${find_name} is not found in any of the provided COMPONENT_DIRS")
|
2018-10-18 23:51:51 -04:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# components_find_all: Search 'component_dirs' for components and return them
|
|
|
|
# as a list of names in 'component_names' and a list of full paths in
|
|
|
|
# 'component_paths'
|
|
|
|
#
|
|
|
|
# component_paths contains only unique component names. Directories
|
|
|
|
# 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
|
2019-07-10 04:28:44 -04:00
|
|
|
set(_paths "")
|
|
|
|
set(_names "")
|
|
|
|
set(_test_names "")
|
2018-10-18 23:51:51 -04:00
|
|
|
|
|
|
|
# start by expanding the component_dirs list with all subdirectories
|
|
|
|
foreach(dir ${component_dirs})
|
2019-07-10 04:28:44 -04:00
|
|
|
if(EXISTS ${dir}/CMakeLists.txt)
|
|
|
|
get_filename_component(_path "${dir}" ABSOLUTE)
|
|
|
|
get_filename_component(_name "${_path}" NAME)
|
2018-10-18 23:51:51 -04:00
|
|
|
if(NOT name IN_LIST names)
|
2019-07-10 04:28:44 -04:00
|
|
|
list(APPEND _names "${_name}")
|
|
|
|
list(APPEND _paths "${_path}")
|
|
|
|
endif()
|
2018-10-18 23:51:51 -04:00
|
|
|
|
2019-07-10 04:28:44 -04:00
|
|
|
if(EXISTS "${_path}/test/CMakeLists.txt")
|
|
|
|
list(APPEND _test_names "${_name}")
|
2018-10-18 23:51:51 -04:00
|
|
|
endif()
|
2019-07-10 04:28:44 -04:00
|
|
|
else()
|
|
|
|
if(EXISTS ${dir}/component.mk)
|
2018-10-18 23:51:51 -04:00
|
|
|
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.")
|
2019-07-10 04:28:44 -04:00
|
|
|
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()
|
2018-10-18 23:51:51 -04:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
2019-07-10 04:28:44 -04:00
|
|
|
set(${test_component_names} "${_test_names}" PARENT_SCOPE)
|
|
|
|
set(${component_paths} "${_paths}" PARENT_SCOPE)
|
|
|
|
set(${component_names} "${_names}" PARENT_SCOPE)
|
2018-10-18 23:51:51 -04:00
|
|
|
endfunction()
|