Austin Schuh | 0cbef62 | 2015-09-06 17:34:52 -0700 | [diff] [blame^] | 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. |
| 10 | option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF) |
| 11 | |
| 12 | # When other libraries are using a shared version of runtime libraries, |
| 13 | # Google Test also has to use one. |
| 14 | option( |
| 15 | gtest_force_shared_crt |
| 16 | "Use shared (DLL) run-time lib even when Google Test is built as static lib." |
| 17 | OFF) |
| 18 | |
| 19 | option(gtest_build_tests "Build all of gtest's own tests." OFF) |
| 20 | |
| 21 | option(gtest_build_samples "Build gtest's sample programs." OFF) |
| 22 | |
| 23 | option(gtest_disable_pthreads "Disable uses of pthreads in gtest." OFF) |
| 24 | |
| 25 | # Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build(). |
| 26 | include(cmake/hermetic_build.cmake OPTIONAL) |
| 27 | |
| 28 | if (COMMAND pre_project_set_up_hermetic_build) |
| 29 | pre_project_set_up_hermetic_build() |
| 30 | endif() |
| 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). |
| 42 | project(gtest CXX C) |
| 43 | cmake_minimum_required(VERSION 2.6.2) |
| 44 | |
| 45 | if (COMMAND set_up_hermetic_build) |
| 46 | set_up_hermetic_build() |
| 47 | endif() |
| 48 | |
| 49 | # Define helper functions and macros used by Google Test. |
| 50 | include(cmake/internal_utils.cmake) |
| 51 | |
| 52 | config_compiler_and_linker() # Defined in internal_utils.cmake. |
| 53 | |
| 54 | # Where Google Test's .h files can be found. |
| 55 | include_directories( |
| 56 | ${gtest_SOURCE_DIR}/include |
| 57 | ${gtest_SOURCE_DIR}) |
| 58 | |
| 59 | # Where Google Test's libraries can be found. |
| 60 | link_directories(${gtest_BINARY_DIR}/src) |
| 61 | |
| 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 | if (MSVC AND MSVC_VERSION EQUAL 1700) |
| 69 | add_definitions(/D _VARIADIC_MAX=10) |
| 70 | endif() |
| 71 | |
| 72 | ######################################################################## |
| 73 | # |
| 74 | # Defines the gtest & gtest_main libraries. User tests should link |
| 75 | # with one of them. |
| 76 | |
| 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 | |
| 84 | ######################################################################## |
| 85 | # |
| 86 | # Samples on how to link user tests with gtest or gtest_main. |
| 87 | # |
| 88 | # They are not built by default. To build them, set the |
| 89 | # gtest_build_samples option to ON. You can do it by running ccmake |
| 90 | # or specifying the -Dgtest_build_samples=ON flag when running cmake. |
| 91 | |
| 92 | if (gtest_build_samples) |
| 93 | cxx_executable(sample1_unittest samples gtest_main samples/sample1.cc) |
| 94 | cxx_executable(sample2_unittest samples gtest_main samples/sample2.cc) |
| 95 | cxx_executable(sample3_unittest samples gtest_main) |
| 96 | cxx_executable(sample4_unittest samples gtest_main samples/sample4.cc) |
| 97 | cxx_executable(sample5_unittest samples gtest_main samples/sample1.cc) |
| 98 | cxx_executable(sample6_unittest samples gtest_main) |
| 99 | cxx_executable(sample7_unittest samples gtest_main) |
| 100 | cxx_executable(sample8_unittest samples gtest_main) |
| 101 | cxx_executable(sample9_unittest samples gtest) |
| 102 | cxx_executable(sample10_unittest samples gtest) |
| 103 | endif() |
| 104 | |
| 105 | ######################################################################## |
| 106 | # |
| 107 | # Google Test's own tests. |
| 108 | # |
| 109 | # You can skip this section if you aren't interested in testing |
| 110 | # Google Test itself. |
| 111 | # |
| 112 | # The tests are not built by default. To build them, set the |
| 113 | # gtest_build_tests option to ON. You can do it by running ccmake |
| 114 | # or specifying the -Dgtest_build_tests=ON flag when running cmake. |
| 115 | |
| 116 | if (gtest_build_tests) |
| 117 | # This must be set in the root directory for the tests to be run by |
| 118 | # 'make test' or ctest. |
| 119 | enable_testing() |
| 120 | |
| 121 | ############################################################ |
| 122 | # C++ tests built with standard compiler flags. |
| 123 | |
| 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 | ############################################################ |
| 153 | # C++ tests built with non-standard compiler flags. |
| 154 | |
| 155 | # MSVC 7.1 does not support STL with exceptions disabled. |
| 156 | if (NOT MSVC OR MSVC_VERSION GREATER 1310) |
| 157 | cxx_library(gtest_no_exception "${cxx_no_exception}" |
| 158 | src/gtest-all.cc) |
| 159 | cxx_library(gtest_main_no_exception "${cxx_no_exception}" |
| 160 | src/gtest-all.cc src/gtest_main.cc) |
| 161 | endif() |
| 162 | cxx_library(gtest_main_no_rtti "${cxx_no_rtti}" |
| 163 | src/gtest-all.cc src/gtest_main.cc) |
| 164 | |
| 165 | cxx_test_with_flags(gtest-death-test_ex_nocatch_test |
| 166 | "${cxx_exception} -DGTEST_ENABLE_CATCH_EXCEPTIONS_=0" |
| 167 | gtest test/gtest-death-test_ex_test.cc) |
| 168 | cxx_test_with_flags(gtest-death-test_ex_catch_test |
| 169 | "${cxx_exception} -DGTEST_ENABLE_CATCH_EXCEPTIONS_=1" |
| 170 | gtest test/gtest-death-test_ex_test.cc) |
| 171 | |
| 172 | cxx_test_with_flags(gtest_no_rtti_unittest "${cxx_no_rtti}" |
| 173 | gtest_main_no_rtti test/gtest_unittest.cc) |
| 174 | |
| 175 | cxx_shared_library(gtest_dll "${cxx_default}" |
| 176 | src/gtest-all.cc src/gtest_main.cc) |
| 177 | |
| 178 | cxx_executable_with_flags(gtest_dll_test_ "${cxx_default}" |
| 179 | gtest_dll test/gtest_all_test.cc) |
| 180 | set_target_properties(gtest_dll_test_ |
| 181 | PROPERTIES |
| 182 | COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1") |
| 183 | |
| 184 | if (NOT MSVC OR MSVC_VERSION LESS 1600) # 1600 is Visual Studio 2010. |
| 185 | # Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that |
| 186 | # conflict with our own definitions. Therefore using our own tuple does not |
| 187 | # work on those compilers. |
| 188 | cxx_library(gtest_main_use_own_tuple "${cxx_use_own_tuple}" |
| 189 | src/gtest-all.cc src/gtest_main.cc) |
| 190 | |
| 191 | cxx_test_with_flags(gtest-tuple_test "${cxx_use_own_tuple}" |
| 192 | gtest_main_use_own_tuple test/gtest-tuple_test.cc) |
| 193 | |
| 194 | cxx_test_with_flags(gtest_use_own_tuple_test "${cxx_use_own_tuple}" |
| 195 | gtest_main_use_own_tuple |
| 196 | test/gtest-param-test_test.cc test/gtest-param-test2_test.cc) |
| 197 | endif() |
| 198 | |
| 199 | ############################################################ |
| 200 | # Python tests. |
| 201 | |
| 202 | cxx_executable(gtest_break_on_failure_unittest_ test gtest) |
| 203 | py_test(gtest_break_on_failure_unittest) |
| 204 | |
| 205 | # Visual Studio .NET 2003 does not support STL with exceptions disabled. |
| 206 | if (NOT MSVC OR MSVC_VERSION GREATER 1310) # 1310 is Visual Studio .NET 2003 |
| 207 | cxx_executable_with_flags( |
| 208 | gtest_catch_exceptions_no_ex_test_ |
| 209 | "${cxx_no_exception}" |
| 210 | gtest_main_no_exception |
| 211 | test/gtest_catch_exceptions_test_.cc) |
| 212 | endif() |
| 213 | |
| 214 | cxx_executable_with_flags( |
| 215 | gtest_catch_exceptions_ex_test_ |
| 216 | "${cxx_exception}" |
| 217 | gtest_main |
| 218 | test/gtest_catch_exceptions_test_.cc) |
| 219 | py_test(gtest_catch_exceptions_test) |
| 220 | |
| 221 | cxx_executable(gtest_color_test_ test gtest) |
| 222 | py_test(gtest_color_test) |
| 223 | |
| 224 | cxx_executable(gtest_env_var_test_ test gtest) |
| 225 | py_test(gtest_env_var_test) |
| 226 | |
| 227 | cxx_executable(gtest_filter_unittest_ test gtest) |
| 228 | py_test(gtest_filter_unittest) |
| 229 | |
| 230 | cxx_executable(gtest_help_test_ test gtest_main) |
| 231 | py_test(gtest_help_test) |
| 232 | |
| 233 | cxx_executable(gtest_list_tests_unittest_ test gtest) |
| 234 | py_test(gtest_list_tests_unittest) |
| 235 | |
| 236 | cxx_executable(gtest_output_test_ test gtest) |
| 237 | py_test(gtest_output_test) |
| 238 | |
| 239 | cxx_executable(gtest_shuffle_test_ test gtest) |
| 240 | py_test(gtest_shuffle_test) |
| 241 | |
| 242 | # MSVC 7.1 does not support STL with exceptions disabled. |
| 243 | if (NOT MSVC OR MSVC_VERSION GREATER 1310) |
| 244 | cxx_executable(gtest_throw_on_failure_test_ test gtest_no_exception) |
| 245 | set_target_properties(gtest_throw_on_failure_test_ |
| 246 | PROPERTIES |
| 247 | COMPILE_FLAGS "${cxx_no_exception}") |
| 248 | py_test(gtest_throw_on_failure_test) |
| 249 | endif() |
| 250 | |
| 251 | cxx_executable(gtest_uninitialized_test_ test gtest) |
| 252 | py_test(gtest_uninitialized_test) |
| 253 | |
| 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 | |
| 258 | cxx_executable(gtest_xml_output_unittest_ test gtest) |
| 259 | py_test(gtest_xml_output_unittest) |
| 260 | endif() |