xref: /openbmc/boost-dbus/cmake/FindGMock.cmake (revision 377e76ab)
1*377e76abSEd Tanous# Locate the Google C++ Mocking Framework.
2*377e76abSEd Tanous# (This file is almost an identical copy of the original FindGTest.cmake file,
3*377e76abSEd Tanous#  feel free to use it as it is or modify it for your own needs.)
4*377e76abSEd Tanous#
5*377e76abSEd Tanous#
6*377e76abSEd Tanous# Defines the following variables:
7*377e76abSEd Tanous#
8*377e76abSEd Tanous#   GMOCK_FOUND - Found the Google Testing framework
9*377e76abSEd Tanous#   GMOCK_INCLUDE_DIRS - Include directories
10*377e76abSEd Tanous#
11*377e76abSEd Tanous# Also defines the library variables below as normal
12*377e76abSEd Tanous# variables. These contain debug/optimized keywords when
13*377e76abSEd Tanous# a debugging library is found.
14*377e76abSEd Tanous#
15*377e76abSEd Tanous#   GMOCK_BOTH_LIBRARIES - Both libgmock & libgmock-main
16*377e76abSEd Tanous#   GMOCK_LIBRARIES - libgmock
17*377e76abSEd Tanous#   GMOCK_MAIN_LIBRARIES - libgmock-main
18*377e76abSEd Tanous#
19*377e76abSEd Tanous# Accepts the following variables as input:
20*377e76abSEd Tanous#
21*377e76abSEd Tanous#   GMOCK_ROOT - (as a CMake or environment variable)
22*377e76abSEd Tanous#                The root directory of the gmock install prefix
23*377e76abSEd Tanous#
24*377e76abSEd Tanous#   GMOCK_MSVC_SEARCH - If compiling with MSVC, this variable can be set to
25*377e76abSEd Tanous#                       "MD" or "MT" to enable searching a gmock build tree
26*377e76abSEd Tanous#                       (defaults: "MD")
27*377e76abSEd Tanous#
28*377e76abSEd Tanous#-----------------------
29*377e76abSEd Tanous# Example Usage:
30*377e76abSEd Tanous#
31*377e76abSEd Tanous#    find_package(GMock REQUIRED)
32*377e76abSEd Tanous#    include_directories(${GMOCK_INCLUDE_DIRS})
33*377e76abSEd Tanous#
34*377e76abSEd Tanous#    add_executable(foo foo.cc)
35*377e76abSEd Tanous#    target_link_libraries(foo ${GMOCK_BOTH_LIBRARIES})
36*377e76abSEd Tanous#
37*377e76abSEd Tanous#=============================================================================
38*377e76abSEd Tanous# This file is released under the MIT licence:
39*377e76abSEd Tanous#
40*377e76abSEd Tanous# Copyright (c) 2011 Matej Svec
41*377e76abSEd Tanous#
42*377e76abSEd Tanous# Permission is hereby granted, free of charge, to any person obtaining a copy
43*377e76abSEd Tanous# of this software and associated documentation files (the "Software"), to
44*377e76abSEd Tanous# deal in the Software without restriction, including without limitation the
45*377e76abSEd Tanous# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
46*377e76abSEd Tanous# sell copies of the Software, and to permit persons to whom the Software is
47*377e76abSEd Tanous# furnished to do so, subject to the following conditions:
48*377e76abSEd Tanous#
49*377e76abSEd Tanous# The above copyright notice and this permission notice shall be included in
50*377e76abSEd Tanous# all copies or substantial portions of the Software.
51*377e76abSEd Tanous#
52*377e76abSEd Tanous# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
53*377e76abSEd Tanous# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
54*377e76abSEd Tanous# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
55*377e76abSEd Tanous# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
56*377e76abSEd Tanous# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
57*377e76abSEd Tanous# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
58*377e76abSEd Tanous# IN THE SOFTWARE.
59*377e76abSEd Tanous#=============================================================================
60*377e76abSEd Tanous
61*377e76abSEd Tanous
62*377e76abSEd Tanousfunction(_gmock_append_debugs _endvar _library)
63*377e76abSEd Tanous  if(${_library} AND ${_library}_DEBUG)
64*377e76abSEd Tanous    set(_output optimized ${${_library}} debug ${${_library}_DEBUG})
65*377e76abSEd Tanous  else()
66*377e76abSEd Tanous    set(_output ${${_library}})
67*377e76abSEd Tanous  endif()
68*377e76abSEd Tanous  set(${_endvar} ${_output} PARENT_SCOPE)
69*377e76abSEd Tanousendfunction()
70*377e76abSEd Tanous
71*377e76abSEd Tanousfunction(_gmock_find_library _name)
72*377e76abSEd Tanous  find_library(${_name}
73*377e76abSEd Tanous    NAMES ${ARGN}
74*377e76abSEd Tanous    HINTS
75*377e76abSEd Tanous      $ENV{GMOCK_ROOT}
76*377e76abSEd Tanous      ${GMOCK_ROOT}
77*377e76abSEd Tanous    PATH_SUFFIXES ${_gmock_libpath_suffixes}
78*377e76abSEd Tanous  )
79*377e76abSEd Tanous  mark_as_advanced(${_name})
80*377e76abSEd Tanousendfunction()
81*377e76abSEd Tanous
82*377e76abSEd Tanous
83*377e76abSEd Tanousif(NOT DEFINED GMOCK_MSVC_SEARCH)
84*377e76abSEd Tanous  set(GMOCK_MSVC_SEARCH MD)
85*377e76abSEd Tanousendif()
86*377e76abSEd Tanous
87*377e76abSEd Tanousset(_gmock_libpath_suffixes lib)
88*377e76abSEd Tanousif(MSVC)
89*377e76abSEd Tanous  if(GMOCK_MSVC_SEARCH STREQUAL "MD")
90*377e76abSEd Tanous    list(APPEND _gmock_libpath_suffixes
91*377e76abSEd Tanous      msvc/gmock-md/Debug
92*377e76abSEd Tanous      msvc/gmock-md/Release)
93*377e76abSEd Tanous  elseif(GMOCK_MSVC_SEARCH STREQUAL "MT")
94*377e76abSEd Tanous    list(APPEND _gmock_libpath_suffixes
95*377e76abSEd Tanous      msvc/gmock/Debug
96*377e76abSEd Tanous      msvc/gmock/Release)
97*377e76abSEd Tanous  endif()
98*377e76abSEd Tanousendif()
99*377e76abSEd Tanous
100*377e76abSEd Tanousfind_path(GMOCK_INCLUDE_DIR gmock/gmock.h
101*377e76abSEd Tanous  HINTS
102*377e76abSEd Tanous    $ENV{GMOCK_ROOT}/include
103*377e76abSEd Tanous    ${GMOCK_ROOT}/include
104*377e76abSEd Tanous)
105*377e76abSEd Tanousmark_as_advanced(GMOCK_INCLUDE_DIR)
106*377e76abSEd Tanous
107*377e76abSEd Tanousif(MSVC AND GMOCK_MSVC_SEARCH STREQUAL "MD")
108*377e76abSEd Tanous  # The provided /MD project files for Google Mock add -md suffixes to the
109*377e76abSEd Tanous  # library names.
110*377e76abSEd Tanous  _gmock_find_library(GMOCK_LIBRARY            gmock-md  gmock)
111*377e76abSEd Tanous  _gmock_find_library(GMOCK_LIBRARY_DEBUG      gmock-mdd gmockd)
112*377e76abSEd Tanous  _gmock_find_library(GMOCK_MAIN_LIBRARY       gmock_main-md  gmock_main)
113*377e76abSEd Tanous  _gmock_find_library(GMOCK_MAIN_LIBRARY_DEBUG gmock_main-mdd gmock_maind)
114*377e76abSEd Tanouselse()
115*377e76abSEd Tanous  _gmock_find_library(GMOCK_LIBRARY            gmock)
116*377e76abSEd Tanous  _gmock_find_library(GMOCK_LIBRARY_DEBUG      gmockd)
117*377e76abSEd Tanous  _gmock_find_library(GMOCK_MAIN_LIBRARY       gmock_main)
118*377e76abSEd Tanous  _gmock_find_library(GMOCK_MAIN_LIBRARY_DEBUG gmock_maind)
119*377e76abSEd Tanousendif()
120*377e76abSEd Tanous
121*377e76abSEd Tanousinclude(FindPackageHandleStandardArgs)
122*377e76abSEd TanousFIND_PACKAGE_HANDLE_STANDARD_ARGS(GMock DEFAULT_MSG GMOCK_LIBRARY GMOCK_INCLUDE_DIR GMOCK_MAIN_LIBRARY)
123*377e76abSEd Tanous
124*377e76abSEd Tanousif(GMOCK_FOUND)
125*377e76abSEd Tanous  set(GMOCK_INCLUDE_DIRS ${GMOCK_INCLUDE_DIR})
126*377e76abSEd Tanous  _gmock_append_debugs(GMOCK_LIBRARIES      GMOCK_LIBRARY)
127*377e76abSEd Tanous  _gmock_append_debugs(GMOCK_MAIN_LIBRARIES GMOCK_MAIN_LIBRARY)
128*377e76abSEd Tanous  set(GMOCK_BOTH_LIBRARIES ${GMOCK_LIBRARIES} ${GMOCK_MAIN_LIBRARIES})
129*377e76abSEd Tanousendif()
130