1 ###############################################################################
2 # Top contributors (to current version):
5 # This file is part of the cvc5 project.
7 # Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
8 # in the top-level source directory and their institutional affiliations.
9 # All rights reserved. See the file COPYING in the top-level source
10 # directory for licensing information.
11 # #############################################################################
18 find_path(GTest_INCLUDE_DIR NAMES gtest/gtest.h)
19 find_library(GTest_LIBRARIES NAMES gtest)
20 find_library(GTest_MAIN_LIBRARIES NAMES gtest_main)
22 set(GTest_FOUND_SYSTEM FALSE)
23 if(GTest_INCLUDE_DIR AND GTest_LIBRARIES AND GTest_MAIN_LIBRARIES)
24 set(GTest_FOUND_SYSTEM TRUE)
27 if(NOT GTest_FOUND_SYSTEM)
28 check_ep_downloaded("GTest-EP")
29 if(NOT GTest-EP_DOWNLOADED)
30 check_auto_download("GTest" "")
33 include(ExternalProject)
35 set(GTest_VERSION "1.10.0")
40 URL https://github.com/google/googletest/archive/refs/tags/release-${GTest_VERSION}.tar.gz
41 URL_HASH SHA1=9c89be7df9c5e8cb0bc20b3c4b39bf7e82686770
42 DOWNLOAD_NAME gtest.tar.gz
44 -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
45 -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
46 BUILD_COMMAND ${CMAKE_COMMAND} --build .
47 --config ${CMAKE_BUILD_TYPE} --target gtest
48 COMMAND ${CMAKE_COMMAND} --build .
49 --config ${CMAKE_BUILD_TYPE} --target gtest_main
51 <INSTALL_DIR>/lib/libgtest.a
52 <INSTALL_DIR>/lib/libgtest_main.a
55 set(GTest_INCLUDE_DIR "${DEPS_BASE}/include/")
56 set(GTest_LIBRARIES "${DEPS_BASE}/lib/libgtest.a")
57 set(GTest_MAIN_LIBRARIES "${DEPS_BASE}/lib/libgtest_main.a")
62 add_library(GTest::GTest STATIC IMPORTED GLOBAL)
63 set_target_properties(GTest::GTest PROPERTIES
64 IMPORTED_LOCATION "${GTest_LIBRARIES}"
65 INTERFACE_INCLUDE_DIRECTORIES "${GTest_INCLUDE_DIR}"
68 add_library(GTest::Main STATIC IMPORTED GLOBAL)
69 set_target_properties(GTest::Main PROPERTIES
70 IMPORTED_LOCATION "${GTest_MAIN_LIBRARIES}"
71 INTERFACE_INCLUDE_DIRECTORIES "${GTest_INCLUDE_DIR}"
74 find_package(Threads QUIET)
75 if(TARGET Threads::Threads)
76 set_target_properties(GTest::GTest PROPERTIES
77 INTERFACE_LINK_LIBRARIES Threads::Threads)
80 mark_as_advanced(GTest_FOUND)
81 mark_as_advanced(GTest_FOUND_SYSTEM)
82 mark_as_advanced(GTest_INCLUDE_DIR)
83 mark_as_advanced(GTest_LIBRARIES)
84 mark_as_advanced(GTest_MAIN_LIBRARIES)
86 if(GTest_FOUND_SYSTEM)
87 message(STATUS "Found GTest ${GTest_VERSION}: ${GTest_LIBRARIES}")
89 message(STATUS "Building GTest ${GTest_VERSION}: ${GTest_LIBRARIES}")
90 add_dependencies(GTest::GTest GTest-EP)
91 add_dependencies(GTest::Main GTest-EP)