FindGMock.cmake
Go to the documentation of this file.
1 ##############################################################################
2 # @file FindGMock.cmake
3 # @brief Find Google Mock package.
4 #
5 # @par Input variables:
6 # <table border="0">
7 # <tr>
8 # @tp @b GMock_DIR @endtp
9 # <td>The Google Mock package files are searched under the specified
10 # root directory. If they are not found there, the default search
11 # paths are considered. This variable can also be set as environment
12 # variable.</td>
13 # </tr>
14 # <tr>
15 # @tp @b GMOCK_DIR @endtp
16 # <td>Alternative environment variable for @p GMock_DIR.</td>
17 # </tr>
18 # <tr>
19 # @tp @b GMock_SHARED_LIBRARIES @endtp
20 # <td>Forces this module to search for shared libraries.
21 # Otherwise, static libraries are preferred.</td>
22 # </tr>
23 # </table>
24 #
25 # @par Output variables:
26 # <table border="0">
27 # <tr>
28 # @tp @b GMock_FOUND @endtp
29 # <td>Whether the package was found and the following CMake variables are valid.</td>
30 # </tr>
31 # <tr>
32 # @tp @b GMock_INCLUDE_DIR @endtp
33 # <td>Package include directories.</td>
34 # </tr>
35 # <tr>
36 # @tp @b GMock_INCLUDES @endtp
37 # <td>Include directories including prerequisite libraries.</td>
38 # </tr>
39 # <tr>
40 # @tp @b GMock_LIBRARY @endtp
41 # <td>Package libraries.</td>
42 # </tr>
43 # <tr>
44 # @tp @b GMock_LIBRARIES @endtp
45 # <td>Package ibraries and prerequisite libraries.</td>
46 # </tr>
47 # </table>
48 #
49 # @ingroup CMakeFindModules
50 ##############################################################################
51 
52 #=============================================================================
53 # Copyright 2011-2012 University of Pennsylvania
54 # Copyright 2013-2016 Andreas Schuh <andreas.schuh.84@gmail.com>
55 #
56 # Distributed under the OSI-approved BSD License (the "License");
57 # see accompanying file Copyright.txt for details.
58 #
59 # This software is distributed WITHOUT ANY WARRANTY; without even the
60 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
61 # See the License for more information.
62 #=============================================================================
63 # (To distribute this file outside of CMake, substitute the full
64 # License text for the above reference.)
65 
66 # ----------------------------------------------------------------------------
67 # initialize search
68 if (NOT GMock_DIR)
69  if ($ENV{GMOCK_DIR})
70  set (GMock_DIR "$ENV{GMOCK_DIR}" CACHE PATH "Installation prefix for Google Mock.")
71  else ()
72  set (GMock_DIR "$ENV{GMock_DIR}" CACHE PATH "Installation prefix for Google Mock.")
73  endif ()
74 endif ()
75 
77 
78 if (GMock_SHARED_LIBRARIES)
79  if (WIN32)
81  else ()
83  endif()
84 else ()
85  if (WIN32)
87  else ()
89  endif()
90 endif ()
91 
92 # ----------------------------------------------------------------------------
93 # find paths/files
94 if (GMock_DIR)
95 
96  find_path (
97  GMock_INCLUDE_DIR
98  NAMES gmock.h
99  HINTS "${GMock_DIR}"
100  PATH_SUFFIXES "include/gmock"
101  DOC "Include directory for Google Mock."
102  NO_DEFAULT_PATH
103  )
104 
105  find_library (
106  GMock_LIBRARY
107  NAMES gmock
108  HINTS "${GMock_DIR}"
109  PATH_SUFFIXES "lib"
110  DOC "Link library for Google Mock (gmock)."
111  NO_DEFAULT_PATH
112  )
113 
114 else ()
115 
116  find_path (
117  GMock_INCLUDE_DIR
118  NAMES gmock.h
119  HINTS ENV C_INCLUDE_PATH ENV CXX_INCLUDE_PATH
120  DOC "Include directory for Google Mock."
121  )
122 
123  find_library (
124  GMock_LIBRARY
125  NAMES gmock
126  HINTS ENV LD_LIBRARY_PATH
127  DOC "Link library for Google Mock (gmock)."
128  )
129 
130 endif ()
131 
132 mark_as_advanced (GMock_INCLUDE_DIR)
133 mark_as_advanced (GMock_LIBRARY)
134 
135 # ----------------------------------------------------------------------------
136 # prerequisite libraries
137 set (GMock_INCLUDES "${GMock_INCLUDE_DIR}")
138 set (GMock_LIBRARIES "${GMock_LIBRARY}")
139 
140 # ----------------------------------------------------------------------------
141 # reset CMake variables
142 set (CMAKE_FIND_LIBRARY_SUFFIXES ${GTest_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
143 
144 # ----------------------------------------------------------------------------
145 # aliases / backwards compatibility
146 set (GMock_INCLUDE_DIRS "${GTest_INCLUDES}")
147 
148 # ----------------------------------------------------------------------------
149 # handle the QUIETLY and REQUIRED arguments and set *_FOUND to TRUE
150 # if all listed variables are found or TRUE
151 include (FindPackageHandleStandardArgs)
152 
153 find_package_handle_standard_args (
154  GMock
155  REQUIRED_VARS
156  GMock_INCLUDE_DIR
157  GMock_LIBRARY
158 )
159 
160 set (GMock_FOUND "${GMOCK_FOUND}")
161 
162 # ----------------------------------------------------------------------------
163 # set GMock_DIR
164 if (NOT GMock_DIR AND GMock_FOUND)
165  string (REGEX REPLACE "include(/gmock)?/?" "" GMock_PREFIX "${GMock_INCLUDE_DIR}")
166  set (GMock_DIR "${GMock_PREFIX}" CACHE PATH "Installation prefix for GMock." FORCE)
167  unset (GMock_PREFIX)
168 endif ()
cmake CMAKE_FIND_LIBRARY_SUFFIXES
Definition: FindGMock.cmake:80
cmake GMock_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES
Definition: FindGMock.cmake:76
cmake GMock_INCLUDES
cmake GMock_LIBRARIES
cmake GMock_FOUND
cmake GMock_INCLUDE_DIRS
cmake GMock_DIR
Definition: FindGMock.cmake:52