-
Notifications
You must be signed in to change notification settings - Fork 16
/
FindGMock.cmake
163 lines (144 loc) · 4.69 KB
/
FindGMock.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# ============================================================================
# Copyright (c) 2011-2012 University of Pennsylvania
# Copyright (c) 2013-2014 Andreas Schuh
# All rights reserved.
#
# See COPYING file for license information or visit
# http://opensource.andreasschuh.com/cmake-basis/download.html#license
# ============================================================================
##############################################################################
# @file FindGMock.cmake
# @brief Find Google Mock package.
#
# @par Input variables:
# <table border="0">
# <tr>
# @tp @b GMock_DIR @endtp
# <td>The Google Mock package files are searched under the specified
# root directory. If they are not found there, the default search
# paths are considered. This variable can also be set as environment
# variable.</td>
# </tr>
# <tr>
# @tp @b GMOCK_DIR @endtp
# <td>Alternative environment variable for @p GMock_DIR.</td>
# </tr>
# <tr>
# @tp @b GMock_SHARED_LIBRARIES @endtp
# <td>Forces this module to search for shared libraries.
# Otherwise, static libraries are preferred.</td>
# </tr>
# </table>
#
# @par Output variables:
# <table border="0">
# <tr>
# @tp @b GMock_FOUND @endtp
# <td>Whether the package was found and the following CMake variables are valid.</td>
# </tr>
# <tr>
# @tp @b GMock_INCLUDE_DIR @endtp
# <td>Package include directories.</td>
# </tr>
# <tr>
# @tp @b GMock_INCLUDES @endtp
# <td>Include directories including prerequisite libraries.</td>
# </tr>
# <tr>
# @tp @b GMock_LIBRARY @endtp
# <td>Package libraries.</td>
# </tr>
# <tr>
# @tp @b GMock_LIBRARIES @endtp
# <td>Package ibraries and prerequisite libraries.</td>
# </tr>
# </table>
#
# @ingroup CMakeFindModules
##############################################################################
# ----------------------------------------------------------------------------
# initialize search
if (NOT GMock_DIR)
if ($ENV{GMOCK_DIR})
set (GMock_DIR "$ENV{GMOCK_DIR}" CACHE PATH "Installation prefix for Google Mock.")
else ()
set (GMock_DIR "$ENV{GMock_DIR}" CACHE PATH "Installation prefix for Google Mock.")
endif ()
endif ()
set (GMock_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
if (GMock_SHARED_LIBRARIES)
if (WIN32)
set (CMAKE_FIND_LIBRARY_SUFFIXES .dll)
else ()
set (CMAKE_FIND_LIBRARY_SUFFIXES .so)
endif()
else ()
if (WIN32)
set (CMAKE_FIND_LIBRARY_SUFFIXES .lib)
else ()
set (CMAKE_FIND_LIBRARY_SUFFIXES .a)
endif()
endif ()
# ----------------------------------------------------------------------------
# find paths/files
if (GMock_DIR)
find_path (
GMock_INCLUDE_DIR
NAMES gmock.h
HINTS "${GMock_DIR}"
PATH_SUFFIXES "include/gmock"
DOC "Include directory for Google Mock."
NO_DEFAULT_PATH
)
find_library (
GMock_LIBRARY
NAMES gmock
HINTS "${GMock_DIR}"
PATH_SUFFIXES "lib"
DOC "Link library for Google Mock (gmock)."
NO_DEFAULT_PATH
)
else ()
find_path (
GMock_INCLUDE_DIR
NAMES gmock.h
HINTS ENV C_INCLUDE_PATH ENV CXX_INCLUDE_PATH
DOC "Include directory for Google Mock."
)
find_library (
GMock_LIBRARY
NAMES gmock
HINTS ENV LD_LIBRARY_PATH
DOC "Link library for Google Mock (gmock)."
)
endif ()
mark_as_advanced (GMock_INCLUDE_DIR)
mark_as_advanced (GMock_LIBRARY)
# ----------------------------------------------------------------------------
# prerequisite libraries
set (GMock_INCLUDES "${GMock_INCLUDE_DIR}")
set (GMock_LIBRARIES "${GMock_LIBRARY}")
# ----------------------------------------------------------------------------
# reset CMake variables
set (CMAKE_FIND_LIBRARY_SUFFIXES ${GTest_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
# ----------------------------------------------------------------------------
# aliases / backwards compatibility
set (GMock_INCLUDE_DIRS "${GTest_INCLUDES}")
# ----------------------------------------------------------------------------
# handle the QUIETLY and REQUIRED arguments and set *_FOUND to TRUE
# if all listed variables are found or TRUE
include (FindPackageHandleStandardArgs)
find_package_handle_standard_args (
GMock
REQUIRED_VARS
GMock_INCLUDE_DIR
GMock_LIBRARY
)
set (GMock_FOUND "${GMOCK_FOUND}")
# ----------------------------------------------------------------------------
# set GMock_DIR
if (NOT GMock_DIR AND GMock_FOUND)
string (REGEX REPLACE "include(/gmock)?/?" "" GMock_PREFIX "${GMock_INCLUDE_DIR}")
set (GMock_DIR "${GMock_PREFIX}" CACHE PATH "Installation prefix for GMock." FORCE)
unset (GMock_PREFIX)
endif ()