mirror of
https://github.com/triqs/dft_tools
synced 2024-12-31 16:45:49 +01:00
[cmake] Change Build_Deps option to take either Never/Always/IfNotFound, cleaning
- Use Global Properties to check if a package has been found. This information should not go in the cmake cache
This commit is contained in:
parent
8c407831c8
commit
cce7b5cd2f
12
deps/CMakeLists.txt
vendored
12
deps/CMakeLists.txt
vendored
@ -29,11 +29,19 @@ include(external_dependency.cmake)
|
|||||||
# will not be included in the ALL target of the project.
|
# will not be included in the ALL target of the project.
|
||||||
# In particular the dependency will not be installed.
|
# In particular the dependency will not be installed.
|
||||||
|
|
||||||
option(Build_Deps "Build dependencies from source" OFF)
|
if(NOT DEFINED Build_Deps)
|
||||||
|
set(Build_Deps "Never" CACHE STRING "Do we build dependencies from source? [Never/Always/IfNotFound]")
|
||||||
|
else()
|
||||||
|
set(Build_Deps_Opts "Never" "Always" "IfNotFound")
|
||||||
|
if(NOT ${Build_Deps} IN_LIST Build_Deps_Opts)
|
||||||
|
message(FATAL_ERROR "Build_Deps option should be either 'Never', 'Always' or 'IfNotFound'")
|
||||||
|
endif()
|
||||||
|
set(Build_Deps ${Build_Deps} CACHE STRING "Do we build dependencies from source? [Never/Always/IfNotFound]")
|
||||||
|
endif()
|
||||||
|
|
||||||
# -- GTest --
|
# -- GTest --
|
||||||
external_dependency(GTest
|
external_dependency(GTest
|
||||||
GIT_REPO github:google/googletest
|
GIT_REPO https://github.com/google/googletest
|
||||||
TAG release-1.10.0
|
TAG release-1.10.0
|
||||||
EXCLUDE_FROM_ALL
|
EXCLUDE_FROM_ALL
|
||||||
)
|
)
|
||||||
|
67
deps/external_dependency.cmake
vendored
67
deps/external_dependency.cmake
vendored
@ -2,37 +2,46 @@
|
|||||||
function(external_dependency)
|
function(external_dependency)
|
||||||
cmake_parse_arguments(ARG "EXCLUDE_FROM_ALL" "VERSION;GIT_REPO;TAG" "" ${ARGN})
|
cmake_parse_arguments(ARG "EXCLUDE_FROM_ALL" "VERSION;GIT_REPO;TAG" "" ${ARGN})
|
||||||
|
|
||||||
# Was dependency already found?
|
# -- Was dependency already found?
|
||||||
|
get_property(${ARGV0}_FOUND GLOBAL PROPERTY ${ARGV0}_FOUND)
|
||||||
if(${ARGV0}_FOUND)
|
if(${ARGV0}_FOUND)
|
||||||
message(STATUS "Dependency ${ARGV0} was already resolved")
|
message(STATUS "Dependency ${ARGV0} was already resolved.")
|
||||||
else()
|
return()
|
||||||
if(NOT Build_Deps)
|
endif()
|
||||||
find_package(${ARGV0} ${${ARGV0}_VERSION} QUIET)
|
|
||||||
endif()
|
# -- Try to find package in system.
|
||||||
|
if(NOT Build_Deps STREQUAL "Always")
|
||||||
|
find_package(${ARGV0} ${${ARGV0}_VERSION} QUIET)
|
||||||
if(${ARGV0}_FOUND)
|
if(${ARGV0}_FOUND)
|
||||||
message(STATUS "Found dependency ${ARGV0} with find_package command")
|
message(STATUS "Found dependency ${ARGV0} in system.")
|
||||||
else()
|
return()
|
||||||
message(STATUS " =============== Configuring Dependency ${ARGV0} =============== ")
|
elseif(Build_Deps STREQUAL "Never")
|
||||||
if(ARG_EXCLUDE_FROM_ALL)
|
message(FATAL_ERROR "Could not find dependency ${ARGV0} in system.")
|
||||||
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})
|
|
||||||
if(ARG_TAG)
|
|
||||||
set(clone_opts --branch ${ARG_TAG} -c advice.detachedHead=false)
|
|
||||||
endif()
|
|
||||||
execute_process(COMMAND git clone ${ARG_GIT_REPO} --depth 1 ${clone_opts} ${src_dir})
|
|
||||||
endif()
|
|
||||||
add_subdirectory(${src_dir} ${bin_dir} ${subdir_opts})
|
|
||||||
else()
|
|
||||||
message(FATAL_ERROR "Could not find dependency ${ARGV0}")
|
|
||||||
endif()
|
|
||||||
set(${ARGV0}_FOUND TRUE PARENT_SCOPE)
|
|
||||||
endif()
|
endif()
|
||||||
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})
|
||||||
|
if(ARG_TAG)
|
||||||
|
set(clone_opts --branch ${ARG_TAG} -c advice.detachedHead=false)
|
||||||
|
endif()
|
||||||
|
execute_process(COMMAND git clone ${ARG_GIT_REPO} --depth 1 ${clone_opts} ${src_dir})
|
||||||
|
endif()
|
||||||
|
add_subdirectory(${src_dir} ${bin_dir} ${subdir_opts})
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "Could not find or build dependency ${ARGV0}.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set_property(GLOBAL PROPERTY ${ARGV0}_FOUND TRUE)
|
||||||
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
Loading…
Reference in New Issue
Block a user