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