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.
 
 
 
 
 
 

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