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