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.
|
||||
# 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 --
|
||||
external_dependency(GTest
|
||||
GIT_REPO github:google/googletest
|
||||
GIT_REPO https://github.com/google/googletest
|
||||
TAG release-1.10.0
|
||||
EXCLUDE_FROM_ALL
|
||||
)
|
||||
|
31
deps/external_dependency.cmake
vendored
31
deps/external_dependency.cmake
vendored
@ -2,16 +2,25 @@
|
||||
function(external_dependency)
|
||||
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)
|
||||
message(STATUS "Dependency ${ARGV0} was already resolved")
|
||||
else()
|
||||
if(NOT Build_Deps)
|
||||
find_package(${ARGV0} ${${ARGV0}_VERSION} QUIET)
|
||||
message(STATUS "Dependency ${ARGV0} was already resolved.")
|
||||
return()
|
||||
endif()
|
||||
|
||||
# -- Try to find package in system.
|
||||
if(NOT Build_Deps STREQUAL "Always")
|
||||
find_package(${ARGV0} ${${ARGV0}_VERSION} QUIET)
|
||||
if(${ARGV0}_FOUND)
|
||||
message(STATUS "Found dependency ${ARGV0} with find_package command")
|
||||
else()
|
||||
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)
|
||||
@ -30,9 +39,9 @@ function(external_dependency)
|
||||
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()
|
||||
message(FATAL_ERROR "Could not find or build dependency ${ARGV0}.")
|
||||
endif()
|
||||
|
||||
set_property(GLOBAL PROPERTY ${ARGV0}_FOUND TRUE)
|
||||
|
||||
endfunction()
|
||||
|
Loading…
Reference in New Issue
Block a user