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