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.

257 lines
9.1 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. MARK_AS_ADVANCED(gtest_build_tests gtest_build_samples gtest_disable_pthreads gtest_force_shared_crt)
  20. # Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build().
  21. include(cmake/hermetic_build.cmake OPTIONAL)
  22. if (COMMAND pre_project_set_up_hermetic_build)
  23. pre_project_set_up_hermetic_build()
  24. endif()
  25. ########################################################################
  26. #
  27. # Project-wide settings
  28. # Name of the project.
  29. #
  30. # CMake files in this project can refer to the root source directory
  31. # as ${gtest_SOURCE_DIR} and to the root binary directory as
  32. # ${gtest_BINARY_DIR}.
  33. # Language "C" is required for find_package(Threads).
  34. project(gtest CXX C)
  35. cmake_minimum_required(VERSION 2.6.2)
  36. if (COMMAND set_up_hermetic_build)
  37. set_up_hermetic_build()
  38. endif()
  39. # Define helper functions and macros used by Google Test.
  40. include(cmake/internal_utils.cmake)
  41. config_compiler_and_linker() # Defined in internal_utils.cmake.
  42. # Where Google Test's .h files can be found.
  43. include_directories(
  44. ${gtest_SOURCE_DIR}/include
  45. ${gtest_SOURCE_DIR})
  46. # Where Google Test's libraries can be found.
  47. link_directories(${gtest_BINARY_DIR}/src)
  48. ########################################################################
  49. #
  50. # Defines the gtest & gtest_main libraries. User tests should link
  51. # with one of them.
  52. # Google Test libraries. We build them using more strict warnings than what
  53. # are used for other targets, to ensure that gtest can be compiled by a user
  54. # aggressive about warnings.
  55. cxx_library(gtest "${cxx_strict}" src/gtest-all.cc)
  56. cxx_library(gtest_main "${cxx_strict}" src/gtest_main.cc)
  57. target_link_libraries(gtest_main gtest)
  58. ########################################################################
  59. #
  60. # Samples on how to link user tests with gtest or gtest_main.
  61. #
  62. # They are not built by default. To build them, set the
  63. # gtest_build_samples option to ON. You can do it by running ccmake
  64. # or specifying the -Dgtest_build_samples=ON flag when running cmake.
  65. if (gtest_build_samples)
  66. cxx_executable(sample1_unittest samples gtest_main samples/sample1.cc)
  67. cxx_executable(sample2_unittest samples gtest_main samples/sample2.cc)
  68. cxx_executable(sample3_unittest samples gtest_main)
  69. cxx_executable(sample4_unittest samples gtest_main samples/sample4.cc)
  70. cxx_executable(sample5_unittest samples gtest_main samples/sample1.cc)
  71. cxx_executable(sample6_unittest samples gtest_main)
  72. cxx_executable(sample7_unittest samples gtest_main)
  73. cxx_executable(sample8_unittest samples gtest_main)
  74. cxx_executable(sample9_unittest samples gtest)
  75. cxx_executable(sample10_unittest samples gtest)
  76. endif()
  77. ########################################################################
  78. #
  79. # Google Test's own tests.
  80. #
  81. # You can skip this section if you aren't interested in testing
  82. # Google Test itself.
  83. #
  84. # The tests are not built by default. To build them, set the
  85. # gtest_build_tests option to ON. You can do it by running ccmake
  86. # or specifying the -Dgtest_build_tests=ON flag when running cmake.
  87. if (gtest_build_tests)
  88. # This must be set in the root directory for the tests to be run by
  89. # 'make test' or ctest.
  90. enable_testing()
  91. ############################################################
  92. # C++ tests built with standard compiler flags.
  93. cxx_test(gtest-death-test_test gtest_main)
  94. cxx_test(gtest_environment_test gtest)
  95. cxx_test(gtest-filepath_test gtest_main)
  96. cxx_test(gtest-linked_ptr_test gtest_main)
  97. cxx_test(gtest-listener_test gtest_main)
  98. cxx_test(gtest_main_unittest gtest_main)
  99. cxx_test(gtest-message_test gtest_main)
  100. cxx_test(gtest_no_test_unittest gtest)
  101. cxx_test(gtest-options_test gtest_main)
  102. cxx_test(gtest-param-test_test gtest
  103. test/gtest-param-test2_test.cc)
  104. cxx_test(gtest-port_test gtest_main)
  105. cxx_test(gtest_pred_impl_unittest gtest_main)
  106. cxx_test(gtest_premature_exit_test gtest
  107. test/gtest_premature_exit_test.cc)
  108. cxx_test(gtest-printers_test gtest_main)
  109. cxx_test(gtest_prod_test gtest_main
  110. test/production.cc)
  111. cxx_test(gtest_repeat_test gtest)
  112. cxx_test(gtest_sole_header_test gtest_main)
  113. cxx_test(gtest_stress_test gtest)
  114. cxx_test(gtest-test-part_test gtest_main)
  115. cxx_test(gtest_throw_on_failure_ex_test gtest)
  116. cxx_test(gtest-typed-test_test gtest_main
  117. test/gtest-typed-test2_test.cc)
  118. cxx_test(gtest_unittest gtest_main)
  119. cxx_test(gtest-unittest-api_test gtest)
  120. ############################################################
  121. # C++ tests built with non-standard compiler flags.
  122. # MSVC 7.1 does not support STL with exceptions disabled.
  123. if (NOT MSVC OR MSVC_VERSION GREATER 1310)
  124. cxx_library(gtest_no_exception "${cxx_no_exception}"
  125. src/gtest-all.cc)
  126. cxx_library(gtest_main_no_exception "${cxx_no_exception}"
  127. src/gtest-all.cc src/gtest_main.cc)
  128. endif()
  129. cxx_library(gtest_main_no_rtti "${cxx_no_rtti}"
  130. src/gtest-all.cc src/gtest_main.cc)
  131. cxx_test_with_flags(gtest-death-test_ex_nocatch_test
  132. "${cxx_exception} -DGTEST_ENABLE_CATCH_EXCEPTIONS_=0"
  133. gtest test/gtest-death-test_ex_test.cc)
  134. cxx_test_with_flags(gtest-death-test_ex_catch_test
  135. "${cxx_exception} -DGTEST_ENABLE_CATCH_EXCEPTIONS_=1"
  136. gtest test/gtest-death-test_ex_test.cc)
  137. cxx_test_with_flags(gtest_no_rtti_unittest "${cxx_no_rtti}"
  138. gtest_main_no_rtti test/gtest_unittest.cc)
  139. cxx_shared_library(gtest_dll "${cxx_default}"
  140. src/gtest-all.cc src/gtest_main.cc)
  141. cxx_executable_with_flags(gtest_dll_test_ "${cxx_default}"
  142. gtest_dll test/gtest_all_test.cc)
  143. set_target_properties(gtest_dll_test_
  144. PROPERTIES
  145. COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1")
  146. if (NOT MSVC OR NOT MSVC_VERSION EQUAL 1600)
  147. # The C++ Standard specifies tuple_element<int, class>.
  148. # Yet MSVC 10's <utility> declares tuple_element<size_t, class>.
  149. # That declaration conflicts with our own standard-conforming
  150. # tuple implementation. Therefore using our own tuple with
  151. # MSVC 10 doesn't compile.
  152. cxx_library(gtest_main_use_own_tuple "${cxx_use_own_tuple}"
  153. src/gtest-all.cc src/gtest_main.cc)
  154. cxx_test_with_flags(gtest-tuple_test "${cxx_use_own_tuple}"
  155. gtest_main_use_own_tuple test/gtest-tuple_test.cc)
  156. cxx_test_with_flags(gtest_use_own_tuple_test "${cxx_use_own_tuple}"
  157. gtest_main_use_own_tuple
  158. test/gtest-param-test_test.cc test/gtest-param-test2_test.cc)
  159. endif()
  160. ############################################################
  161. # Python tests.
  162. cxx_executable(gtest_break_on_failure_unittest_ test gtest)
  163. py_test(gtest_break_on_failure_unittest)
  164. # MSVC 7.1 does not support STL with exceptions disabled.
  165. if (NOT MSVC OR MSVC_VERSION GREATER 1310)
  166. cxx_executable_with_flags(
  167. gtest_catch_exceptions_no_ex_test_
  168. "${cxx_no_exception}"
  169. gtest_main_no_exception
  170. test/gtest_catch_exceptions_test_.cc)
  171. endif()
  172. cxx_executable_with_flags(
  173. gtest_catch_exceptions_ex_test_
  174. "${cxx_exception}"
  175. gtest_main
  176. test/gtest_catch_exceptions_test_.cc)
  177. py_test(gtest_catch_exceptions_test)
  178. cxx_executable(gtest_color_test_ test gtest)
  179. py_test(gtest_color_test)
  180. cxx_executable(gtest_env_var_test_ test gtest)
  181. py_test(gtest_env_var_test)
  182. cxx_executable(gtest_filter_unittest_ test gtest)
  183. py_test(gtest_filter_unittest)
  184. cxx_executable(gtest_help_test_ test gtest_main)
  185. py_test(gtest_help_test)
  186. cxx_executable(gtest_list_tests_unittest_ test gtest)
  187. py_test(gtest_list_tests_unittest)
  188. cxx_executable(gtest_output_test_ test gtest)
  189. py_test(gtest_output_test)
  190. cxx_executable(gtest_shuffle_test_ test gtest)
  191. py_test(gtest_shuffle_test)
  192. # MSVC 7.1 does not support STL with exceptions disabled.
  193. if (NOT MSVC OR MSVC_VERSION GREATER 1310)
  194. cxx_executable(gtest_throw_on_failure_test_ test gtest_no_exception)
  195. set_target_properties(gtest_throw_on_failure_test_
  196. PROPERTIES
  197. COMPILE_FLAGS "${cxx_no_exception}")
  198. py_test(gtest_throw_on_failure_test)
  199. endif()
  200. cxx_executable(gtest_uninitialized_test_ test gtest)
  201. py_test(gtest_uninitialized_test)
  202. cxx_executable(gtest_xml_outfile1_test_ test gtest_main)
  203. cxx_executable(gtest_xml_outfile2_test_ test gtest_main)
  204. py_test(gtest_xml_outfiles_test)
  205. cxx_executable(gtest_xml_output_unittest_ test gtest)
  206. py_test(gtest_xml_output_unittest)
  207. endif()
  208. if( MSVC ) # VS2012 doesn't support correctly the tuples yet
  209. add_definitions( /D _VARIADIC_MAX=10 )
  210. endif()