-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImportGTest.cmake
41 lines (40 loc) · 1.45 KB
/
ImportGTest.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#
# This file is licensed under the 3-clause BSD license.
# Copyright ETH Zurich, Laboratory for Physical Chemistry, Reiher Group.
# See LICENSE.txt for details.
#
macro(import_gtest)
# If the target already exists, do nothing
if(NOT TARGET gtest)
# Try to find the package locally
find_package(GTest 1.8.1 QUIET)
if(TARGET gtest)
message(STATUS "GTest 1.8.1 found locally at ${GTest_DIR}.")
else()
# Download it instead
include(DownloadProject)
download_project(
PROJ googletest
GIT_REPOSITORY https://gitlab.chab.ethz.ch/scine/googletest.git
GIT_TAG release-1.8.1
QUIET
UPDATE_DISCONNECTED 1
)
# Prevent GoogleTest from overriding our compiler/linker options when
# building with Visual Studio
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
# Final check if all went well
if(TARGET gtest)
message(STATUS "GTest was not found in your PATH, so it was downloaded.")
else()
string(CONCAT error_msg
"GTest was not found in your PATH and could not be established through "
"a download. Try specifying GTest_DIR or altering CMAKE_PREFIX_PATH to "
"point to a candidate GTest installation base directory."
)
message(FATAL_ERROR ${error_msg})
endif()
endif()
endif()
endmacro()