You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

287 line
10 KiB

  1. ########################################################################
  2. # CMake build script for Google Test.
  3. #
  4. # To run the tests for Google Test itself on Linux, use 'make test' or
  5. # ctest. You can select which tests to run using 'ctest -R regex'.
  6. # For more options, run 'ctest --help'.
  7. # BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to
  8. # make it prominent in the GUI.
  9. option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)
  10. # When other libraries are using a shared version of runtime libraries,
  11. # Google Test also has to use one.
  12. option(
  13. gtest_force_shared_crt
  14. "Use shared (DLL) run-time lib even when Google Test is built as static lib."
  15. OFF)
  16. option(gtest_build_tests "Build all of gtest's own tests." OFF)
  17. option(gtest_build_samples "Build gtest's sample programs." OFF)
  18. option(gtest_disable_pthreads "Disable uses of pthreads in gtest." OFF)
  19. option(
  20. gtest_hide_internal_symbols
  21. "Build gtest with internal symbols hidden in shared libraries."
  22. OFF)
  23. # Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build().
  24. include(cmake/hermetic_build.cmake OPTIONAL)
  25. if (COMMAND pre_project_set_up_hermetic_build)
  26. pre_project_set_up_hermetic_build()
  27. endif()
  28. ########################################################################
  29. #
  30. # Project-wide settings
  31. # Name of the project.
  32. #
  33. # CMake files in this project can refer to the root source directory
  34. # as ${gtest_SOURCE_DIR} and to the root binary directory as
  35. # ${gtest_BINARY_DIR}.
  36. # Language "C" is required for find_package(Threads).
  37. project(gtest CXX C)
  38. cmake_minimum_required(VERSION 2.6.4)
  39. if (COMMAND set_up_hermetic_build)
  40. set_up_hermetic_build()
  41. endif()
  42. if (gtest_hide_internal_symbols)
  43. set(CMAKE_CXX_VISIBILITY_PRESET hidden)
  44. set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
  45. endif()
  46. # Define helper functions and macros used by Google Test.
  47. include(cmake/internal_utils.cmake)
  48. config_compiler_and_linker() # Defined in internal_utils.cmake.
  49. # Where Google Test's .h files can be found.
  50. include_directories(
  51. ${gtest_SOURCE_DIR}/include
  52. ${gtest_SOURCE_DIR})
  53. # Where Google Test's libraries can be found.
  54. link_directories(${gtest_BINARY_DIR}/src)
  55. # Summary of tuple support for Microsoft Visual Studio:
  56. # Compiler version(MS) version(cmake) Support
  57. # ---------- ----------- -------------- -----------------------------
  58. # <= VS 2010 <= 10 <= 1600 Use Google Tests's own tuple.
  59. # VS 2012 11 1700 std::tr1::tuple + _VARIADIC_MAX=10
  60. # VS 2013 12 1800 std::tr1::tuple
  61. if (MSVC AND MSVC_VERSION EQUAL 1700)
  62. add_definitions(/D _VARIADIC_MAX=10)
  63. endif()
  64. ########################################################################
  65. #
  66. # Defines the gtest & gtest_main libraries. User tests should link
  67. # with one of them.
  68. # Google Test libraries. We build them using more strict warnings than what
  69. # are used for other targets, to ensure that gtest can be compiled by a user
  70. # aggressive about warnings.
  71. cxx_library(gtest "${cxx_strict}" src/gtest-all.cc)
  72. cxx_library(gtest_main "${cxx_strict}" src/gtest_main.cc)
  73. target_link_libraries(gtest_main gtest)
  74. # If the CMake version supports it, attach header directory information
  75. # to the targets for when we are part of a parent build (ie being pulled
  76. # in via add_subdirectory() rather than being a standalone build).
  77. if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")
  78. target_include_directories(gtest INTERFACE "${gtest_SOURCE_DIR}/include")
  79. target_include_directories(gtest_main INTERFACE "${gtest_SOURCE_DIR}/include")
  80. endif()
  81. ########################################################################
  82. #
  83. # Install rules
  84. install(TARGETS gtest gtest_main
  85. DESTINATION lib)
  86. install(DIRECTORY ${gtest_SOURCE_DIR}/include/gtest
  87. DESTINATION include)
  88. ########################################################################
  89. #
  90. # Samples on how to link user tests with gtest or gtest_main.
  91. #
  92. # They are not built by default. To build them, set the
  93. # gtest_build_samples option to ON. You can do it by running ccmake
  94. # or specifying the -Dgtest_build_samples=ON flag when running cmake.
  95. if (gtest_build_samples)
  96. cxx_executable(sample1_unittest samples gtest_main samples/sample1.cc)
  97. cxx_executable(sample2_unittest samples gtest_main samples/sample2.cc)
  98. cxx_executable(sample3_unittest samples gtest_main)
  99. cxx_executable(sample4_unittest samples gtest_main samples/sample4.cc)
  100. cxx_executable(sample5_unittest samples gtest_main samples/sample1.cc)
  101. cxx_executable(sample6_unittest samples gtest_main)
  102. cxx_executable(sample7_unittest samples gtest_main)
  103. cxx_executable(sample8_unittest samples gtest_main)
  104. cxx_executable(sample9_unittest samples gtest)
  105. cxx_executable(sample10_unittest samples gtest)
  106. endif()
  107. ########################################################################
  108. #
  109. # Google Test's own tests.
  110. #
  111. # You can skip this section if you aren't interested in testing
  112. # Google Test itself.
  113. #
  114. # The tests are not built by default. To build them, set the
  115. # gtest_build_tests option to ON. You can do it by running ccmake
  116. # or specifying the -Dgtest_build_tests=ON flag when running cmake.
  117. if (gtest_build_tests)
  118. # This must be set in the root directory for the tests to be run by
  119. # 'make test' or ctest.
  120. enable_testing()
  121. ############################################################
  122. # C++ tests built with standard compiler flags.
  123. cxx_test(gtest-death-test_test gtest_main)
  124. cxx_test(gtest_environment_test gtest)
  125. cxx_test(gtest-filepath_test gtest_main)
  126. cxx_test(gtest-linked_ptr_test gtest_main)
  127. cxx_test(gtest-listener_test gtest_main)
  128. cxx_test(gtest_main_unittest gtest_main)
  129. cxx_test(gtest-message_test gtest_main)
  130. cxx_test(gtest_no_test_unittest gtest)
  131. cxx_test(gtest-options_test gtest_main)
  132. cxx_test(gtest-param-test_test gtest
  133. test/gtest-param-test2_test.cc)
  134. cxx_test(gtest-port_test gtest_main)
  135. cxx_test(gtest_pred_impl_unittest gtest_main)
  136. cxx_test(gtest_premature_exit_test gtest
  137. test/gtest_premature_exit_test.cc)
  138. cxx_test(gtest-printers_test gtest_main)
  139. cxx_test(gtest_prod_test gtest_main
  140. test/production.cc)
  141. cxx_test(gtest_repeat_test gtest)
  142. cxx_test(gtest_sole_header_test gtest_main)
  143. cxx_test(gtest_stress_test gtest)
  144. cxx_test(gtest-test-part_test gtest_main)
  145. cxx_test(gtest_throw_on_failure_ex_test gtest)
  146. cxx_test(gtest-typed-test_test gtest_main
  147. test/gtest-typed-test2_test.cc)
  148. cxx_test(gtest_unittest gtest_main)
  149. cxx_test(gtest-unittest-api_test gtest)
  150. ############################################################
  151. # C++ tests built with non-standard compiler flags.
  152. # MSVC 7.1 does not support STL with exceptions disabled.
  153. if (NOT MSVC OR MSVC_VERSION GREATER 1310)
  154. cxx_library(gtest_no_exception "${cxx_no_exception}"
  155. src/gtest-all.cc)
  156. cxx_library(gtest_main_no_exception "${cxx_no_exception}"
  157. src/gtest-all.cc src/gtest_main.cc)
  158. endif()
  159. cxx_library(gtest_main_no_rtti "${cxx_no_rtti}"
  160. src/gtest-all.cc src/gtest_main.cc)
  161. cxx_test_with_flags(gtest-death-test_ex_nocatch_test
  162. "${cxx_exception} -DGTEST_ENABLE_CATCH_EXCEPTIONS_=0"
  163. gtest test/gtest-death-test_ex_test.cc)
  164. cxx_test_with_flags(gtest-death-test_ex_catch_test
  165. "${cxx_exception} -DGTEST_ENABLE_CATCH_EXCEPTIONS_=1"
  166. gtest test/gtest-death-test_ex_test.cc)
  167. cxx_test_with_flags(gtest_no_rtti_unittest "${cxx_no_rtti}"
  168. gtest_main_no_rtti test/gtest_unittest.cc)
  169. cxx_shared_library(gtest_dll "${cxx_default}"
  170. src/gtest-all.cc src/gtest_main.cc)
  171. cxx_executable_with_flags(gtest_dll_test_ "${cxx_default}"
  172. gtest_dll test/gtest_all_test.cc)
  173. set_target_properties(gtest_dll_test_
  174. PROPERTIES
  175. COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1")
  176. if (NOT MSVC OR MSVC_VERSION LESS 1600) # 1600 is Visual Studio 2010.
  177. # Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that
  178. # conflict with our own definitions. Therefore using our own tuple does not
  179. # work on those compilers.
  180. cxx_library(gtest_main_use_own_tuple "${cxx_use_own_tuple}"
  181. src/gtest-all.cc src/gtest_main.cc)
  182. cxx_test_with_flags(gtest-tuple_test "${cxx_use_own_tuple}"
  183. gtest_main_use_own_tuple test/gtest-tuple_test.cc)
  184. cxx_test_with_flags(gtest_use_own_tuple_test "${cxx_use_own_tuple}"
  185. gtest_main_use_own_tuple
  186. test/gtest-param-test_test.cc test/gtest-param-test2_test.cc)
  187. endif()
  188. ############################################################
  189. # Python tests.
  190. cxx_executable(gtest_break_on_failure_unittest_ test gtest)
  191. py_test(gtest_break_on_failure_unittest)
  192. # Visual Studio .NET 2003 does not support STL with exceptions disabled.
  193. if (NOT MSVC OR MSVC_VERSION GREATER 1310) # 1310 is Visual Studio .NET 2003
  194. cxx_executable_with_flags(
  195. gtest_catch_exceptions_no_ex_test_
  196. "${cxx_no_exception}"
  197. gtest_main_no_exception
  198. test/gtest_catch_exceptions_test_.cc)
  199. endif()
  200. cxx_executable_with_flags(
  201. gtest_catch_exceptions_ex_test_
  202. "${cxx_exception}"
  203. gtest_main
  204. test/gtest_catch_exceptions_test_.cc)
  205. py_test(gtest_catch_exceptions_test)
  206. cxx_executable(gtest_color_test_ test gtest)
  207. py_test(gtest_color_test)
  208. cxx_executable(gtest_env_var_test_ test gtest)
  209. py_test(gtest_env_var_test)
  210. cxx_executable(gtest_filter_unittest_ test gtest)
  211. py_test(gtest_filter_unittest)
  212. cxx_executable(gtest_help_test_ test gtest_main)
  213. py_test(gtest_help_test)
  214. cxx_executable(gtest_list_tests_unittest_ test gtest)
  215. py_test(gtest_list_tests_unittest)
  216. cxx_executable(gtest_output_test_ test gtest)
  217. py_test(gtest_output_test)
  218. cxx_executable(gtest_shuffle_test_ test gtest)
  219. py_test(gtest_shuffle_test)
  220. # MSVC 7.1 does not support STL with exceptions disabled.
  221. if (NOT MSVC OR MSVC_VERSION GREATER 1310)
  222. cxx_executable(gtest_throw_on_failure_test_ test gtest_no_exception)
  223. set_target_properties(gtest_throw_on_failure_test_
  224. PROPERTIES
  225. COMPILE_FLAGS "${cxx_no_exception}")
  226. py_test(gtest_throw_on_failure_test)
  227. endif()
  228. cxx_executable(gtest_uninitialized_test_ test gtest)
  229. py_test(gtest_uninitialized_test)
  230. cxx_executable(gtest_xml_outfile1_test_ test gtest_main)
  231. cxx_executable(gtest_xml_outfile2_test_ test gtest_main)
  232. py_test(gtest_xml_outfiles_test)
  233. cxx_executable(gtest_xml_output_unittest_ test gtest)
  234. py_test(gtest_xml_output_unittest)
  235. endif()