FindGMock.cmake 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. function(_gmock_append_debugs _endvar _library)
  61. if(${_library} AND ${_library}_DEBUG)
  62. set(_output optimized ${${_library}} debug ${${_library}_DEBUG})
  63. else()
  64. set(_output ${${_library}})
  65. endif()
  66. set(${_endvar} ${_output} PARENT_SCOPE)
  67. endfunction()
  68. function(_gmock_find_library _name)
  69. find_library(${_name}
  70. NAMES ${ARGN}
  71. HINTS
  72. $ENV{GMOCK_ROOT}
  73. ${GMOCK_ROOT}
  74. PATH_SUFFIXES ${_gmock_libpath_suffixes}
  75. )
  76. mark_as_advanced(${_name})
  77. endfunction()
  78. if(NOT DEFINED GMOCK_MSVC_SEARCH)
  79. set(GMOCK_MSVC_SEARCH MD)
  80. endif()
  81. set(_gmock_libpath_suffixes lib)
  82. if(MSVC)
  83. if(GMOCK_MSVC_SEARCH STREQUAL "MD")
  84. list(APPEND _gmock_libpath_suffixes
  85. msvc/gmock-md/Debug
  86. msvc/gmock-md/Release)
  87. elseif(GMOCK_MSVC_SEARCH STREQUAL "MT")
  88. list(APPEND _gmock_libpath_suffixes
  89. msvc/gmock/Debug
  90. msvc/gmock/Release)
  91. endif()
  92. endif()
  93. find_path(GMOCK_INCLUDE_DIR gmock/gmock.h
  94. HINTS
  95. $ENV{GMOCK_ROOT}/include
  96. ${GMOCK_ROOT}/include
  97. )
  98. mark_as_advanced(GMOCK_INCLUDE_DIR)
  99. if(MSVC AND GMOCK_MSVC_SEARCH STREQUAL "MD")
  100. # The provided /MD project files for Google Mock add -md suffixes to the
  101. # library names.
  102. _gmock_find_library(GMOCK_LIBRARY gmock-md gmock)
  103. _gmock_find_library(GMOCK_LIBRARY_DEBUG gmock-mdd gmockd)
  104. _gmock_find_library(GMOCK_MAIN_LIBRARY gmock_main-md gmock_main)
  105. _gmock_find_library(GMOCK_MAIN_LIBRARY_DEBUG gmock_main-mdd gmock_maind)
  106. else()
  107. _gmock_find_library(GMOCK_LIBRARY gmock)
  108. _gmock_find_library(GMOCK_LIBRARY_DEBUG gmockd)
  109. _gmock_find_library(GMOCK_MAIN_LIBRARY gmock_main)
  110. _gmock_find_library(GMOCK_MAIN_LIBRARY_DEBUG gmock_maind)
  111. endif()
  112. FIND_PACKAGE_HANDLE_STANDARD_ARGS(GMock DEFAULT_MSG GMOCK_LIBRARY GMOCK_INCLUDE_DIR GMOCK_MAIN_LIBRARY)
  113. if(GMOCK_FOUND)
  114. set(GMOCK_INCLUDE_DIRS ${GMOCK_INCLUDE_DIR})
  115. _gmock_append_debugs(GMOCK_LIBRARIES GMOCK_LIBRARY)
  116. _gmock_append_debugs(GMOCK_MAIN_LIBRARIES GMOCK_MAIN_LIBRARY)
  117. set(GMOCK_BOTH_LIBRARIES ${GMOCK_LIBRARIES} ${GMOCK_MAIN_LIBRARIES})
  118. endif()