FindGMock.cmake 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # Locate the Google C++ Mocking Framework.
  2. #
  3. # Defines the following variables:
  4. #
  5. # GMOCK_FOUND - Found the Google Mocking framework
  6. # GMOCK_INCLUDE_DIRS - Include directories
  7. #
  8. # Also defines the library variables below as normal
  9. # variables. These contain debug/optimized keywords when
  10. # a debugging library is found.
  11. #
  12. # GMOCK_BOTH_LIBRARIES - Both libgmock & libgmock-main
  13. # GMOCK_LIBRARIES - libgmock
  14. # GMOCK_MAIN_LIBRARIES - libgmock-main
  15. #
  16. # Accepts the following variables as input:
  17. #
  18. # GMOCK_ROOT - (as CMake or env. variable)
  19. # The root directory of the gmock install prefix
  20. #
  21. #-----------------------
  22. # Example Usage:
  23. #
  24. # enable_testing(true)
  25. # find_package(GMock REQUIRED)
  26. # include_directories(${GMOCK_INCLUDE_DIRS})
  27. #
  28. # add_executable(foo foo.cc)
  29. # target_link_libraries(foo ${GMOCK_BOTH_LIBRARIES})
  30. #
  31. # add_test(AllTestsInFoo foo)
  32. #
  33. set (GMOCK_FOUND FALSE)
  34. set (GMOCK_ROOT $ENV{GMOCK_ROOT} CACHE PATH "Path to the gmock root directory.")
  35. if (NOT EXISTS ${GMOCK_ROOT})
  36. message (FATAL_ERROR "GMOCK_ROOT does not exist.")
  37. endif ()
  38. set (GMOCK_BUILD ${GMOCK_ROOT}/build CACHE PATH "Path to the gmock build directory.")
  39. if (NOT EXISTS ${GMOCK_BUILD})
  40. message (FATAL_ERROR "GMOCK_BUILD does not exist.")
  41. endif ()
  42. # Find the include directory
  43. find_path(GMOCK_INCLUDE_DIRS gmock/gmock.h
  44. HINTS
  45. ${GMOCK_ROOT}/include
  46. )
  47. mark_as_advanced(GMOCK_INCLUDE_DIRS)
  48. function(_gmock_find_library _name)
  49. find_library(${_name}
  50. NAMES ${ARGN}
  51. HINTS
  52. $ENV{GMOCK_ROOT}
  53. ${GMOCK_ROOT}
  54. )
  55. mark_as_advanced(${_name})
  56. endfunction()
  57. # Find the gmock libraries
  58. if (MSVC)
  59. find_library (GMOCK_LIBRARIES_DEBUG gmock ${GMOCK_BUILD}/Debug)
  60. find_library (GMOCK_LIBRARIES_RELEASE gmock ${GMOCK_BUILD}/Release)
  61. find_library (GMOCK_MAIN_LIBRARIES_DEBUG gmock_main ${GMOCK_BUILD}/Debug)
  62. find_library (GMOCK_MAIN_LIBRARIES_RELEASE gmock_main ${GMOCK_BUILD}/Release)
  63. set (GMOCK_LIBRARIES
  64. debug ${GMOCK_LIBRARIES_DEBUG}
  65. optimized ${GMOCK_LIBRARIES_RELEASE}
  66. )
  67. set (GMOCK_MAIN_LIBRARIES
  68. debug ${GMOCK_MAIN_LIBRARIES_DEBUG}
  69. optimized ${GMOCK_MAIN_LIBRARIES_RELEASE}
  70. )
  71. # message (STATUS "GMOCK_BOTH_LIBRARIES ARE ${GMOCK_BOTH_LIBRARIES}")
  72. else ()
  73. find_library (GMOCK_LIBRARIES gmock ${GMOCK_BUILD})
  74. find_library (GMOCK_MAIN_LIBRARIES gmock_main ${GMOCK_BUILD})
  75. find_library (GTEST_LIBRARIES gtest ${GMOCK_BUILD}/gtest)
  76. find_library (GTEST_MAIN_LIBRARIES gtest_main ${GMOCK_BUILD})
  77. endif ()
  78. set (GMOCK_BOTH_LIBRARIES
  79. ${GMOCK_LIBRARIES}
  80. ${GMOCK_MAIN_LIBRARIES}
  81. ${GTEST_LIBRARIES}
  82. ${GTEST_MAIN_LIBRARIES}
  83. )