OLD | NEW |
| (Empty) |
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 ######################################################################## | |
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. | |
70 cxx_library(gtest "${cxx_strict}" src/gtest-all.cc) | |
71 cxx_library(gtest_main "${cxx_strict}" src/gtest_main.cc) | |
72 target_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 -Dbuild_gtest_samples=ON flag when running cmake. | |
81 | |
82 if (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) | |
93 endif() | |
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 | |
106 if (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-printers_test gtest_main) | |
128 cxx_test(gtest_prod_test gtest_main | |
129 test/production.cc) | |
130 cxx_test(gtest_repeat_test gtest) | |
131 cxx_test(gtest_sole_header_test gtest_main) | |
132 cxx_test(gtest_stress_test gtest) | |
133 cxx_test(gtest-test-part_test gtest_main) | |
134 cxx_test(gtest_throw_on_failure_ex_test gtest) | |
135 cxx_test(gtest-typed-test_test gtest_main | |
136 test/gtest-typed-test2_test.cc) | |
137 cxx_test(gtest_unittest gtest_main) | |
138 cxx_test(gtest-unittest-api_test gtest) | |
139 | |
140 ############################################################ | |
141 # C++ tests built with non-standard compiler flags. | |
142 | |
143 cxx_library(gtest_no_exception "${cxx_no_exception}" | |
144 src/gtest-all.cc) | |
145 cxx_library(gtest_main_no_exception "${cxx_no_exception}" | |
146 src/gtest-all.cc src/gtest_main.cc) | |
147 cxx_library(gtest_main_no_rtti "${cxx_no_rtti}" | |
148 src/gtest-all.cc src/gtest_main.cc) | |
149 | |
150 cxx_test_with_flags(gtest-death-test_ex_nocatch_test | |
151 "${cxx_exception} -DGTEST_ENABLE_CATCH_EXCEPTIONS_=0" | |
152 gtest test/gtest-death-test_ex_test.cc) | |
153 cxx_test_with_flags(gtest-death-test_ex_catch_test | |
154 "${cxx_exception} -DGTEST_ENABLE_CATCH_EXCEPTIONS_=1" | |
155 gtest test/gtest-death-test_ex_test.cc) | |
156 | |
157 cxx_test_with_flags(gtest_no_rtti_unittest "${cxx_no_rtti}" | |
158 gtest_main_no_rtti test/gtest_unittest.cc) | |
159 | |
160 cxx_shared_library(gtest_dll "${cxx_default}" | |
161 src/gtest-all.cc src/gtest_main.cc) | |
162 | |
163 cxx_executable_with_flags(gtest_dll_test_ "${cxx_default}" | |
164 gtest_dll test/gtest_all_test.cc) | |
165 set_target_properties(gtest_dll_test_ | |
166 PROPERTIES | |
167 COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1") | |
168 | |
169 if (NOT MSVC OR NOT MSVC_VERSION EQUAL 1600) | |
170 # The C++ Standard specifies tuple_element<int, class>. | |
171 # Yet MSVC 10's <utility> declares tuple_element<size_t, class>. | |
172 # That declaration conflicts with our own standard-conforming | |
173 # tuple implementation. Therefore using our own tuple with | |
174 # MSVC 10 doesn't compile. | |
175 cxx_library(gtest_main_use_own_tuple "${cxx_use_own_tuple}" | |
176 src/gtest-all.cc src/gtest_main.cc) | |
177 | |
178 cxx_test_with_flags(gtest-tuple_test "${cxx_use_own_tuple}" | |
179 gtest_main_use_own_tuple test/gtest-tuple_test.cc) | |
180 | |
181 cxx_test_with_flags(gtest_use_own_tuple_test "${cxx_use_own_tuple}" | |
182 gtest_main_use_own_tuple | |
183 test/gtest-param-test_test.cc test/gtest-param-test2_test.cc) | |
184 endif() | |
185 | |
186 ############################################################ | |
187 # Python tests. | |
188 | |
189 cxx_executable(gtest_break_on_failure_unittest_ test gtest) | |
190 py_test(gtest_break_on_failure_unittest) | |
191 | |
192 cxx_executable_with_flags( | |
193 gtest_catch_exceptions_no_ex_test_ | |
194 "${cxx_no_exception}" | |
195 gtest_main_no_exception | |
196 test/gtest_catch_exceptions_test_.cc) | |
197 cxx_executable_with_flags( | |
198 gtest_catch_exceptions_ex_test_ | |
199 "${cxx_exception}" | |
200 gtest_main | |
201 test/gtest_catch_exceptions_test_.cc) | |
202 py_test(gtest_catch_exceptions_test) | |
203 | |
204 cxx_executable(gtest_color_test_ test gtest) | |
205 py_test(gtest_color_test) | |
206 | |
207 cxx_executable(gtest_env_var_test_ test gtest) | |
208 py_test(gtest_env_var_test) | |
209 | |
210 cxx_executable(gtest_filter_unittest_ test gtest) | |
211 py_test(gtest_filter_unittest) | |
212 | |
213 cxx_executable(gtest_help_test_ test gtest_main) | |
214 py_test(gtest_help_test) | |
215 | |
216 cxx_executable(gtest_list_tests_unittest_ test gtest) | |
217 py_test(gtest_list_tests_unittest) | |
218 | |
219 cxx_executable(gtest_output_test_ test gtest) | |
220 py_test(gtest_output_test) | |
221 | |
222 cxx_executable(gtest_shuffle_test_ test gtest) | |
223 py_test(gtest_shuffle_test) | |
224 | |
225 cxx_executable(gtest_throw_on_failure_test_ test gtest_no_exception) | |
226 set_target_properties(gtest_throw_on_failure_test_ | |
227 PROPERTIES | |
228 COMPILE_FLAGS "${cxx_no_exception}") | |
229 py_test(gtest_throw_on_failure_test) | |
230 | |
231 cxx_executable(gtest_uninitialized_test_ test gtest) | |
232 py_test(gtest_uninitialized_test) | |
233 | |
234 cxx_executable(gtest_xml_outfile1_test_ test gtest_main) | |
235 cxx_executable(gtest_xml_outfile2_test_ test gtest_main) | |
236 py_test(gtest_xml_outfiles_test) | |
237 | |
238 cxx_executable(gtest_xml_output_unittest_ test gtest) | |
239 py_test(gtest_xml_output_unittest) | |
240 endif() | |
OLD | NEW |