2020-04-24 23:52:27 +02:00
|
|
|
|
|
|
|
function(external_dependency)
|
2020-04-28 23:18:25 +02:00
|
|
|
cmake_parse_arguments(ARG "EXCLUDE_FROM_ALL;BUILD_ALWAYS" "VERSION;GIT_REPO;GIT_TAG" "" ${ARGN})
|
2020-04-24 23:52:27 +02:00
|
|
|
|
2020-04-28 22:23:27 +02:00
|
|
|
# -- Was dependency already found?
|
|
|
|
get_property(${ARGV0}_FOUND GLOBAL PROPERTY ${ARGV0}_FOUND)
|
2020-04-24 23:52:27 +02:00
|
|
|
if(${ARGV0}_FOUND)
|
2020-04-28 22:23:27 +02:00
|
|
|
message(STATUS "Dependency ${ARGV0} was already resolved.")
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# -- Try to find package in system.
|
2020-04-28 23:18:25 +02:00
|
|
|
if(NOT ARG_BUILD_ALWAYS AND NOT Build_Deps STREQUAL "Always")
|
2020-04-28 22:23:27 +02:00
|
|
|
find_package(${ARGV0} ${${ARGV0}_VERSION} QUIET)
|
2020-04-28 16:51:06 +02:00
|
|
|
if(${ARGV0}_FOUND)
|
2020-04-28 22:23:27 +02:00
|
|
|
message(STATUS "Found dependency ${ARGV0} in system.")
|
|
|
|
return()
|
|
|
|
elseif(Build_Deps STREQUAL "Never")
|
|
|
|
message(FATAL_ERROR "Could not find dependency ${ARGV0} in system.")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# -- Build package from source
|
|
|
|
message(STATUS " =============== Configuring Dependency ${ARGV0} =============== ")
|
|
|
|
if(ARG_EXCLUDE_FROM_ALL)
|
|
|
|
set(subdir_opts EXCLUDE_FROM_ALL)
|
|
|
|
endif()
|
|
|
|
if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${ARGV0})
|
|
|
|
message(STATUS "Found sources for dependency ${ARGV0} at ${CMAKE_CURRENT_SOURCE_DIR}/${ARGV0}.")
|
|
|
|
add_subdirectory(${ARGV0} ${subdir_opts})
|
|
|
|
elseif(ARG_GIT_REPO)
|
|
|
|
set(bin_dir ${CMAKE_CURRENT_BINARY_DIR}/${ARGV0})
|
|
|
|
set(src_dir ${bin_dir}_src)
|
|
|
|
if(NOT IS_DIRECTORY ${src_dir})
|
2020-04-28 22:25:28 +02:00
|
|
|
if(ARG_GIT_TAG)
|
|
|
|
set(clone_opts --branch ${ARG_GIT_TAG} -c advice.detachedHead=false)
|
2020-04-28 16:51:06 +02:00
|
|
|
endif()
|
2020-04-28 22:23:27 +02:00
|
|
|
execute_process(COMMAND git clone ${ARG_GIT_REPO} --depth 1 ${clone_opts} ${src_dir})
|
2020-04-24 23:52:27 +02:00
|
|
|
endif()
|
2020-04-28 22:23:27 +02:00
|
|
|
add_subdirectory(${src_dir} ${bin_dir} ${subdir_opts})
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Could not find or build dependency ${ARGV0}.")
|
2020-04-24 23:52:27 +02:00
|
|
|
endif()
|
2020-04-28 22:23:27 +02:00
|
|
|
|
|
|
|
set_property(GLOBAL PROPERTY ${ARGV0}_FOUND TRUE)
|
|
|
|
|
2020-04-24 23:52:27 +02:00
|
|
|
endfunction()
|