CMakeLists.txt 8.9 KB

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