Guest User

Untitled

a guest
Jun 18th, 2018
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.49 KB | None | 0 0
  1. # Locate the Google C++ Testing Framework.
  2. #
  3. # Defines the following variables:
  4. #
  5. # GTEST_FOUND - Found the Google Testing framework
  6. # GTEST_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. # GTEST_BOTH_LIBRARIES - Both libgtest & libgtest-main
  13. # GTEST_LIBRARIES - libgtest
  14. # GTEST_MAIN_LIBRARIES - libgtest-main
  15. #
  16. # Accepts the following variables as input:
  17. #
  18. # GTEST_ROOT - (as a CMake or environment variable)
  19. # The root directory of the gtest install prefix
  20. #
  21. # GTEST_MSVC_SEARCH - If compiling with MSVC, this variable can be set to
  22. # "MD" or "MT" to enable searching a GTest build tree
  23. # (defaults: "MD")
  24. #
  25. #-----------------------
  26. # Example Usage:
  27. #
  28. # enable_testing()
  29. # find_package(GTest REQUIRED)
  30. # include_directories(${GTEST_INCLUDE_DIRS})
  31. #
  32. # add_executable(foo foo.cc)
  33. # target_link_libraries(foo ${GTEST_BOTH_LIBRARIES})
  34. #
  35. # add_test(AllTestsInFoo foo)
  36. #
  37. #-----------------------
  38. #
  39. # If you would like each Google test to show up in CTest as
  40. # a test you may use the following macro.
  41. # NOTE: It will slow down your tests by running an executable
  42. # for each test and test fixture. You will also have to rerun
  43. # CMake after adding or removing tests or test fixtures.
  44. #
  45. # GTEST_ADD_TESTS(executable extra_args ARGN)
  46. # executable = The path to the test executable
  47. # extra_args = Pass a list of extra arguments to be passed to
  48. # executable enclosed in quotes (or "" for none)
  49. # ARGN = A list of source files to search for tests & test
  50. # fixtures.
  51. #
  52. # Example:
  53. # set(FooTestArgs --foo 1 --bar 2)
  54. # add_executable(FooTest FooUnitTest.cc)
  55. # GTEST_ADD_TESTS(FooTest "${FooTestArgs}" FooUnitTest.cc)
  56.  
  57. #=============================================================================
  58. # Copyright 2009 Kitware, Inc.
  59. # Copyright 2009 Philip Lowman <philip@yhbt.com>
  60. # Copyright 2009 Daniel Blezek <blezek@gmail.com>
  61. #
  62. # Distributed under the OSI-approved BSD License (the "License");
  63. # see accompanying file Copyright.txt for details.
  64. #
  65. # This software is distributed WITHOUT ANY WARRANTY; without even the
  66. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  67. # See the License for more information.
  68. #=============================================================================
  69. # (To distributed this file outside of CMake, substitute the full
  70. # License text for the above reference.)
  71. #
  72. # Thanks to Daniel Blezek <blezek@gmail.com> for the GTEST_ADD_TESTS code
  73.  
  74. function(GTEST_ADD_TESTS executable extra_args)
  75. if(NOT ARGN)
  76. message(FATAL_ERROR "Missing ARGN: Read the documentation for GTEST_ADD_TESTS")
  77. endif()
  78. foreach(source ${ARGN})
  79. file(READ "${source}" contents)
  80. string(REGEX MATCHALL "TEST_?F?\\(([A-Za-z_0-9 ,]+)\\)" found_tests ${contents})
  81. foreach(hit ${found_tests})
  82. string(REGEX REPLACE ".*\\( *([A-Za-z_0-9]+), *([A-Za-z_0-9]+) *\\).*" "\\1.\\2" test_name ${hit})
  83. add_test(${test_name} ${executable} --gtest_filter=${test_name} ${extra_args})
  84. list(APPEND _test_names ${test_name})
  85. endforeach()
  86. endforeach()
  87. set(GTEST_ADD_TEST_NAMES ${_test_names} PARENT_SCOPE)
  88. endfunction()
  89.  
  90. function(_gtest_append_debugs _endvar _library)
  91. if(${_library} AND ${_library}_DEBUG)
  92. set(_output optimized ${${_library}} debug ${${_library}_DEBUG})
  93. else()
  94. set(_output ${${_library}})
  95. endif()
  96. set(${_endvar} ${_output} PARENT_SCOPE)
  97. endfunction()
  98.  
  99. function(_gtest_find_library _name)
  100. find_library(${_name}
  101. NAMES ${ARGN}
  102. HINTS
  103. $ENV{GTEST_ROOT}
  104. ${GTEST_ROOT}
  105. PATH_SUFFIXES ${_gtest_libpath_suffixes}
  106. )
  107. mark_as_advanced(${_name})
  108. endfunction()
  109.  
  110. #
  111.  
  112. if(NOT DEFINED GTEST_MSVC_SEARCH)
  113. set(GTEST_MSVC_SEARCH MD)
  114. endif()
  115.  
  116. set(_gtest_libpath_suffixes lib)
  117. if(MSVC)
  118. if(GTEST_MSVC_SEARCH STREQUAL "MD")
  119. list(APPEND _gtest_libpath_suffixes
  120. msvc/gtest-md/Debug
  121. msvc/gtest-md/Release)
  122. elseif(GTEST_MSVC_SEARCH STREQUAL "MT")
  123. list(APPEND _gtest_libpath_suffixes
  124. msvc/gtest/Debug
  125. msvc/gtest/Release)
  126. endif()
  127. endif()
  128.  
  129.  
  130. find_path(GTEST_INCLUDE_DIR gtest/gtest.h
  131. HINTS
  132. $ENV{GTEST_ROOT}/include
  133. ${GTEST_ROOT}/include
  134. )
  135. mark_as_advanced(GTEST_INCLUDE_DIR)
  136.  
  137. if(MSVC AND GTEST_MSVC_SEARCH STREQUAL "MD")
  138. # The provided /MD project files for Google Test add -md suffixes to the
  139. # library names.
  140. _gtest_find_library(GTEST_LIBRARY gtest-md gtest)
  141. _gtest_find_library(GTEST_LIBRARY_DEBUG gtest-mdd gtestd)
  142. _gtest_find_library(GTEST_MAIN_LIBRARY gtest_main-md gtest_main)
  143. _gtest_find_library(GTEST_MAIN_LIBRARY_DEBUG gtest_main-mdd gtest_maind)
  144. else()
  145. _gtest_find_library(GTEST_LIBRARY gtest)
  146. _gtest_find_library(GTEST_LIBRARY_DEBUG gtestd)
  147. _gtest_find_library(GTEST_MAIN_LIBRARY gtest_main)
  148. _gtest_find_library(GTEST_MAIN_LIBRARY_DEBUG gtest_maind)
  149. endif()
  150.  
  151. include(FindPackageHandleStandardArgs)
  152. FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTest DEFAULT_MSG GTEST_LIBRARY GTEST_INCLUDE_DIR GTEST_MAIN_LIBRARY)
  153.  
  154. if(GTEST_FOUND)
  155. set(GTEST_INCLUDE_DIRS ${GTEST_INCLUDE_DIR})
  156. _gtest_append_debugs(GTEST_LIBRARIES GTEST_LIBRARY)
  157. _gtest_append_debugs(GTEST_MAIN_LIBRARIES GTEST_MAIN_LIBRARY)
  158. set(GTEST_BOTH_LIBRARIES ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES})
  159. endif()
Add Comment
Please, Sign In to add comment