CMakeLists.txt 10 KB

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