mirror of
https://github.com/triqs/dft_tools
synced 2024-12-31 16:45:49 +01:00
[cmake] Handle dependencies with external_dependency(...) function + doc
This commit is contained in:
parent
1ff66fd1f3
commit
c99ee1820e
@ -55,9 +55,6 @@ if(NOT IS_SUBPROJECT)
|
|||||||
endif()
|
endif()
|
||||||
set(APP4TRIQS_BINARY_DIR ${PROJECT_BINARY_DIR} CACHE STRING "Binary directory of the APP4TRIQS Project")
|
set(APP4TRIQS_BINARY_DIR ${PROJECT_BINARY_DIR} CACHE STRING "Binary directory of the APP4TRIQS Project")
|
||||||
|
|
||||||
# ############
|
|
||||||
# Dependencies
|
|
||||||
add_subdirectory(deps)
|
|
||||||
|
|
||||||
# ############
|
# ############
|
||||||
# Options
|
# Options
|
||||||
@ -102,6 +99,9 @@ install(TARGETS project_warnings EXPORT app4triqs-targets)
|
|||||||
# #############
|
# #############
|
||||||
# Build Project
|
# Build Project
|
||||||
|
|
||||||
|
# Find / Build dependencies
|
||||||
|
add_subdirectory(deps)
|
||||||
|
|
||||||
# Build and install the app4triqs library
|
# Build and install the app4triqs library
|
||||||
add_subdirectory(c++/app4triqs)
|
add_subdirectory(c++/app4triqs)
|
||||||
|
|
||||||
|
53
deps/CMakeLists.txt
vendored
53
deps/CMakeLists.txt
vendored
@ -1,18 +1,39 @@
|
|||||||
# Each dependency should be either
|
include(external_dependency.cmake)
|
||||||
# * a cmake subproject in this directory
|
|
||||||
# * found in the system using find_package
|
|
||||||
# Provide either a download.sh script to get all sources
|
|
||||||
# or use e.g. git subtree/submodule or softlinks
|
|
||||||
|
|
||||||
# Add all subdirectories as CMake Sub-Projects
|
# Add your dependencies with the function
|
||||||
file(GLOB allfiles CONFIGURE_DEPENDS *)
|
#
|
||||||
foreach(file ${allfiles})
|
# external_dependency(name
|
||||||
if(IS_DIRECTORY ${file})
|
# [VERSION <version-number>]
|
||||||
add_subdirectory(${file})
|
# [GIT_REPO <url>]
|
||||||
endif()
|
# [TAG <tag>]
|
||||||
endforeach()
|
# [EXCLUDE_FROM_ALL]
|
||||||
|
# )
|
||||||
|
#
|
||||||
|
# Resolve the dependency using the following steps in order.
|
||||||
|
# If a step was successful, skip the remaining ones.
|
||||||
|
#
|
||||||
|
# 1. Use find_package(name [<version-number>])
|
||||||
|
# to locate the package in the system.
|
||||||
|
# Skip this step if Build_Deps option is set.
|
||||||
|
# 2. Try to find a directory containing the sources
|
||||||
|
# at ${CMAKE_SOURCE_DIR}/deps/name. If found
|
||||||
|
# build it as a cmake sub-project.
|
||||||
|
# 3. If GIT_REPO is provided, git clone the sources,
|
||||||
|
# and build them as a cmake sub-project.
|
||||||
|
#
|
||||||
|
# Addtional options:
|
||||||
|
#
|
||||||
|
# TAG - Use this keyword to specify the git tag or branch
|
||||||
|
#
|
||||||
|
# EXCLUDE_FROM_ALL - If set, targets of the dependency cmake subproject
|
||||||
|
# will not be included in the ALL target of the project.
|
||||||
|
# In particular the dependency will not be installed.
|
||||||
|
|
||||||
# -- googletest --
|
option(Build_Deps "Build dependencies from source" OFF)
|
||||||
if(NOT TARGET gtest)
|
|
||||||
find_package(GTest REQUIRED)
|
# -- GTest --
|
||||||
endif()
|
external_dependency(GTest
|
||||||
|
GIT_REPO github:google/googletest
|
||||||
|
TAG release-1.10.0
|
||||||
|
EXCLUDE_FROM_ALL
|
||||||
|
)
|
||||||
|
1
deps/download.sh
vendored
1
deps/download.sh
vendored
@ -1 +0,0 @@
|
|||||||
[ ! -d 'googletest' ] && git clone https://github.com/google/googletest --branch v1.10.x --depth 1
|
|
39
deps/external_dependency.cmake
vendored
Normal file
39
deps/external_dependency.cmake
vendored
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
|
||||||
|
function(external_dependency)
|
||||||
|
cmake_parse_arguments(ARG "EXCLUDE_FROM_ALL" "VERSION;GIT_REPO;TAG" "" ${ARGN})
|
||||||
|
|
||||||
|
# Was dependency already found?
|
||||||
|
if(${ARGV0}_FOUND)
|
||||||
|
message(STATUS "Dependency ${ARGV0} was already resolved")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT Build_Deps)
|
||||||
|
find_package(${ARGV0} ${${ARGV0}_VERSION} QUIET)
|
||||||
|
endif()
|
||||||
|
if(${ARGV0}_FOUND)
|
||||||
|
message(STATUS "Found dependency ${ARGV0} with find_package command")
|
||||||
|
else()
|
||||||
|
message(STATUS "Building Dependency ${ARGV0} from source.")
|
||||||
|
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})
|
||||||
|
set(${ARGV0}_FOUND TRUE CACHE BOOL "Was dependency ${ARGV0} found?")
|
||||||
|
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})
|
||||||
|
set(${ARGV0}_FOUND TRUE CACHE BOOL "Was dependency ${ARGV0} found?")
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "Could not find dependency ${ARGV0}")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endfunction()
|
Loading…
Reference in New Issue
Block a user