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