-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathFindGTestSources.cmake
95 lines (83 loc) · 3.36 KB
/
FindGTestSources.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Find the GTest headers and sources.
#
# Sets the following variables:
#
# * GTestSources_FOUND - system has GTest sources
# * GTestSources_SOURCE_DIR - GTest source dir (with CMakeLists.txt)
# * GTestSources_INCLUDE_DIR - GTest include directory (public headers)
# * GTestSources_VERSION - GTest version (if supported)
#
# You can set the GTEST_ROOT environment variable to be used as a
# hint by FindGTestSources to locate googletest source directory.
#
# Tested with the Ubuntu package `libgtest-dev` and the googletest
# repository hosted on GitHub and cloned to the local machine.
#
# Supported versions: v1.6, v1.7, v1.8.
#
# Also, this module adds the following macros:
#
# * gtest_add_tests (as in FindGTest.cmake)
find_package(GTest QUIET)
if(NOT GTestSources_SOURCE_DIR)
find_path(GTestSources_SOURCE_DIR src/gtest.cc
HINTS $ENV{GTEST_ROOT}
${GTEST_ROOT}
PATHS /usr/src/gtest
/usr/src/googletest
PATH_SUFFIXES googletest)
endif()
if(NOT GTestSources_INCLUDE_DIR)
# Look for local headers *before* /usr/include (hence the NO_X_PATH params)
find_path(GTestSources_INCLUDE_DIR gtest/gtest.h
HINTS ${GTestSources_SOURCE_DIR}
$ENV{GTEST_ROOT}
${GTEST_ROOT}
PATH_SUFFIXES include
NO_CMAKE_PATH
NO_CMAKE_ENVIRONMENT_PATH)
endif()
set(_cmake_include_dirs ${CMAKE_REQUIRED_INCLUDES})
include(CheckCXXSourceCompiles)
list(APPEND CMAKE_REQUIRED_INCLUDES ${GTestSources_INCLUDE_DIR})
check_cxx_source_compiles("
#include <gtest/gtest.h>
int main() {
typedef const char* (testing::TestInfo::*fun)() const;
fun f = &testing::TestInfo::type_param;
return 0;
}"
_gtest_compatible_1_6_0)
check_cxx_source_compiles("
#include <gtest/gtest.h>
int main() {
typedef bool (testing::TestInfo::*fun)() const;
fun f = &testing::TestInfo::is_reportable;
return 0;
}"
_gtest_compatible_1_7_0)
check_cxx_source_compiles("
#include <gtest/gtest.h>
int main() {
typedef const char* (testing::TestInfo::*fun)() const;
fun f = &testing::TestInfo::file;
return 0;
}"
_gtest_compatible_1_8_0)
if(_gtest_compatible_1_8_0)
set(GTestSources_VERSION 1.8.0)
elseif(_gtest_compatible_1_7_0)
set(GTestSources_VERSION 1.7.0)
elseif(_gtest_compatible_1_6_0)
set(GTestSources_VERSION 1.6.0)
else()
message(STATUS "FindGTestSources.cmake reports unhandled GTest version (<1.6.0)")
set(GTestSources_VERSION GTestSources_VERSION-NOT_FOUND)
endif()
set(CMAKE_REQUIRED_INCLUDES "${_cmake_include_dirs}")
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GTestSources REQUIRED_VARS GTestSources_SOURCE_DIR
GTestSources_INCLUDE_DIR
VERSION_VAR GTestSources_VERSION)
mark_as_advanced(GTestSources_SOURCE_DIR
GTestSources_INCLUDE_DIR)