Debian Codegraph @

Modules/ThirdParty/GoogleTest/src/itkgoogletest/googletest/CMakeLists.txt

raw
1 ########################################################################
2 # Note: CMake support is community-based. The maintainers do not use CMake
3 # internally.
4 #
5 # CMake build script for Google Test.
6 #
7 # To run the tests for Google Test itself on Linux, use 'make test' or
8 # ctest. You can select which tests to run using 'ctest -R regex'.
9 # For more options, run 'ctest --help'.
10
11 # When other libraries are using a shared version of runtime libraries,
12 # Google Test also has to use one.
13 option(
14 gtest_force_shared_crt
15 "Use shared (DLL) run-time lib even when Google Test is built as static lib."
16 ON) # ITK handles whether to build static CRT
17 # See how gtest_force_shared_crt is used in cmake/internal_utils.cmake
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
48 # Project version:
49
50 cmake_minimum_required(VERSION 3.5)
51 cmake_policy(SET CMP0048 NEW)
52 project(gtest VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C)
53
54 if (POLICY CMP0063) # Visibility
55 cmake_policy(SET CMP0063 NEW)
56 endif (POLICY CMP0063)
57
58 if (COMMAND set_up_hermetic_build)
59 set_up_hermetic_build()
60 endif()
61
62 # These commands only run if this is the main project
63 if(CMAKE_PROJECT_NAME STREQUAL "gtest" OR CMAKE_PROJECT_NAME STREQUAL "googletest-distribution")
64
65 # BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to
66 # make it prominent in the GUI.
67 option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)
68
69 else()
70
71 mark_as_advanced(
72 gtest_force_shared_crt
73 gtest_build_tests
74 gtest_build_samples
75 gtest_disable_pthreads
76 gtest_hide_internal_symbols)
77
78 endif()
79
80
81 if (gtest_hide_internal_symbols)
82 set(CMAKE_CXX_VISIBILITY_PRESET hidden)
83 set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
84 endif()
85
86 # Define helper functions and macros used by Google Test.
87 include(cmake/internal_utils.cmake)
88
89 config_compiler_and_linker() # Defined in internal_utils.cmake.
90
91 # Needed to set the namespace for both the export targets and the
92 # alias libraries
93 set(cmake_package_name GTest CACHE INTERNAL "")
94
95 # Create the CMake package file descriptors.
96 if (INSTALL_GTEST)
97 include(CMakePackageConfigHelpers)
98 set(targets_export_name ${cmake_package_name}Targets CACHE INTERNAL "")
99 set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated" CACHE INTERNAL "")
100 set(cmake_files_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${cmake_package_name}")
101 set(version_file "${generated_dir}/${cmake_package_name}ConfigVersion.cmake")
102 write_basic_package_version_file(${version_file} VERSION ${GOOGLETEST_VERSION} COMPATIBILITY AnyNewerVersion)
103 install(EXPORT ${targets_export_name}
104 NAMESPACE ${cmake_package_name}::
105 DESTINATION ${cmake_files_install_dir})
106 set(config_file "${generated_dir}/${cmake_package_name}Config.cmake")
107 configure_package_config_file("${gtest_SOURCE_DIR}/cmake/Config.cmake.in"
108 "${config_file}" INSTALL_DESTINATION ${cmake_files_install_dir})
109 install(FILES ${version_file} ${config_file}
110 DESTINATION ${cmake_files_install_dir})
111 endif()
112
113 # Where Google Test's .h files can be found.
114 set(gtest_build_include_dirs
115 "${gtest_SOURCE_DIR}/include"
116 "${gtest_SOURCE_DIR}")
117 include_directories(${gtest_build_include_dirs})
118
119 ########################################################################
120 #
121 # Defines the gtest & gtest_main libraries. User tests should link
122 # with one of them.
123
124 # Google Test libraries. We build them using more strict warnings than what
125 # are used for other targets, to ensure that gtest can be compiled by a user
126 # aggressive about warnings.
127 cxx_library(gtest "${cxx_strict}" src/gtest-all.cc)
128 set_target_properties(gtest PROPERTIES VERSION ${GOOGLETEST_VERSION})
129 if(GTEST_HAS_ABSL)
130 target_compile_definitions(gtest PUBLIC GTEST_HAS_ABSL=1)
131 target_link_libraries(gtest PUBLIC
132 absl::failure_signal_handler
133 absl::stacktrace
134 absl::symbolize
135 absl::flags_parse
136 absl::flags_reflection
137 absl::flags_usage
138 absl::strings
139 absl::any
140 absl::optional
141 absl::variant
142 re2::re2
143 )
144 endif()
145 cxx_library(gtest_main "${cxx_strict}" src/gtest_main.cc)
146 set_target_properties(gtest_main PROPERTIES VERSION ${GOOGLETEST_VERSION})
147 # If the CMake version supports it, attach header directory information
148 # to the targets for when we are part of a parent build (ie being pulled
149 # in via add_subdirectory() rather than being a standalone build).
150 if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")
151 string(REPLACE ";" "$<SEMICOLON>" dirs "${gtest_build_include_dirs}")
152 target_include_directories(gtest SYSTEM INTERFACE
153 "$<BUILD_INTERFACE:${dirs}>"
154 "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
155 target_include_directories(gtest_main SYSTEM INTERFACE
156 "$<BUILD_INTERFACE:${dirs}>"
157 "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
158 endif()
159 if(CMAKE_SYSTEM_NAME MATCHES "QNX")
160 target_link_libraries(gtest PUBLIC regex)
161 endif()
162 target_link_libraries(gtest_main PUBLIC gtest)
163
164 ########################################################################
165 #
166 # Install rules
167 install_project(gtest gtest_main)
168
169 ########################################################################
170 #
171 # Samples on how to link user tests with gtest or gtest_main.
172 #
173 # They are not built by default. To build them, set the
174 # gtest_build_samples option to ON. You can do it by running ccmake
175 # or specifying the -Dgtest_build_samples=ON flag when running cmake.
176
177 if (gtest_build_samples)
178 cxx_executable(sample1_unittest samples gtest_main samples/sample1.cc)
179 cxx_executable(sample2_unittest samples gtest_main samples/sample2.cc)
180 cxx_executable(sample3_unittest samples gtest_main)
181 cxx_executable(sample4_unittest samples gtest_main samples/sample4.cc)
182 cxx_executable(sample5_unittest samples gtest_main samples/sample1.cc)
183 cxx_executable(sample6_unittest samples gtest_main)
184 cxx_executable(sample7_unittest samples gtest_main)
185 cxx_executable(sample8_unittest samples gtest_main)
186 cxx_executable(sample9_unittest samples gtest)
187 cxx_executable(sample10_unittest samples gtest)
188 endif()
189
190 ########################################################################
191 #
192 # Google Test's own tests.
193 #
194 # You can skip this section if you aren't interested in testing
195 # Google Test itself.
196 #
197 # The tests are not built by default. To build them, set the
198 # gtest_build_tests option to ON. You can do it by running ccmake
199 # or specifying the -Dgtest_build_tests=ON flag when running cmake.
200
201 if (gtest_build_tests)
202 # This must be set in the root directory for the tests to be run by
203 # 'make test' or ctest.
204 enable_testing()
205
206 ############################################################
207 # C++ tests built with standard compiler flags.
208
209 cxx_test(googletest-death-test-test gtest_main)
210 cxx_test(gtest_environment_test gtest)
211 cxx_test(googletest-filepath-test gtest_main)
212 cxx_test(googletest-listener-test gtest_main)
213 cxx_test(gtest_main_unittest gtest_main)
214 cxx_test(googletest-message-test gtest_main)
215 cxx_test(gtest_no_test_unittest gtest)
216 cxx_test(googletest-options-test gtest_main)
217 cxx_test(googletest-param-test-test gtest
218 test/googletest-param-test2-test.cc)
219 cxx_test(googletest-port-test gtest_main)
220 cxx_test(gtest_pred_impl_unittest gtest_main)
221 cxx_test(gtest_premature_exit_test gtest
222 test/gtest_premature_exit_test.cc)
223 cxx_test(googletest-printers-test gtest_main)
224 cxx_test(gtest_prod_test gtest_main
225 test/production.cc)
226 cxx_test(gtest_repeat_test gtest)
227 cxx_test(gtest_sole_header_test gtest_main)
228 cxx_test(gtest_stress_test gtest)
229 cxx_test(googletest-test-part-test gtest_main)
230 cxx_test(gtest_throw_on_failure_ex_test gtest)
231 cxx_test(gtest-typed-test_test gtest_main
232 test/gtest-typed-test2_test.cc)
233 cxx_test(gtest_unittest gtest_main)
234 cxx_test(gtest-unittest-api_test gtest)
235 cxx_test(gtest_skip_in_environment_setup_test gtest_main)
236 cxx_test(gtest_skip_test gtest_main)
237
238 ############################################################
239 # C++ tests built with non-standard compiler flags.
240
241 # MSVC 7.1 does not support STL with exceptions disabled.
242 if (NOT MSVC OR MSVC_VERSION GREATER 1310)
243 cxx_library(gtest_no_exception "${cxx_no_exception}"
244 src/gtest-all.cc)
245 cxx_library(gtest_main_no_exception "${cxx_no_exception}"
246 src/gtest-all.cc src/gtest_main.cc)
247 endif()
248 cxx_library(gtest_main_no_rtti "${cxx_no_rtti}"
249 src/gtest-all.cc src/gtest_main.cc)
250
251 cxx_test_with_flags(gtest-death-test_ex_nocatch_test
252 "${cxx_exception} -DGTEST_ENABLE_CATCH_EXCEPTIONS_=0"
253 gtest test/googletest-death-test_ex_test.cc)
254 cxx_test_with_flags(gtest-death-test_ex_catch_test
255 "${cxx_exception} -DGTEST_ENABLE_CATCH_EXCEPTIONS_=1"
256 gtest test/googletest-death-test_ex_test.cc)
257
258 cxx_test_with_flags(gtest_no_rtti_unittest "${cxx_no_rtti}"
259 gtest_main_no_rtti test/gtest_unittest.cc)
260
261 cxx_shared_library(gtest_dll "${cxx_default}"
262 src/gtest-all.cc src/gtest_main.cc)
263
264 cxx_executable_with_flags(gtest_dll_test_ "${cxx_default}"
265 gtest_dll test/gtest_all_test.cc)
266 set_target_properties(gtest_dll_test_
267 PROPERTIES
268 COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1")
269
270 ############################################################
271 # Python tests.
272
273 cxx_executable(googletest-break-on-failure-unittest_ test gtest)
274 py_test(googletest-break-on-failure-unittest)
275
276 py_test(gtest_skip_check_output_test)
277 py_test(gtest_skip_environment_check_output_test)
278
279 # Visual Studio .NET 2003 does not support STL with exceptions disabled.
280 if (NOT MSVC OR MSVC_VERSION GREATER 1310) # 1310 is Visual Studio .NET 2003
281 cxx_executable_with_flags(
282 googletest-catch-exceptions-no-ex-test_
283 "${cxx_no_exception}"
284 gtest_main_no_exception
285 test/googletest-catch-exceptions-test_.cc)
286 endif()
287
288 cxx_executable_with_flags(
289 googletest-catch-exceptions-ex-test_
290 "${cxx_exception}"
291 gtest_main
292 test/googletest-catch-exceptions-test_.cc)
293 py_test(googletest-catch-exceptions-test)
294
295 cxx_executable(googletest-color-test_ test gtest)
296 py_test(googletest-color-test)
297
298 cxx_executable(googletest-env-var-test_ test gtest)
299 py_test(googletest-env-var-test)
300
301 cxx_executable(googletest-filter-unittest_ test gtest)
302 py_test(googletest-filter-unittest)
303
304 cxx_executable(gtest_help_test_ test gtest_main)
305 py_test(gtest_help_test)
306
307 cxx_executable(googletest-list-tests-unittest_ test gtest)
308 py_test(googletest-list-tests-unittest)
309
310 cxx_executable(googletest-output-test_ test gtest)
311 py_test(googletest-output-test --no_stacktrace_support)
312
313 cxx_executable(googletest-shuffle-test_ test gtest)
314 py_test(googletest-shuffle-test)
315
316 # MSVC 7.1 does not support STL with exceptions disabled.
317 if (NOT MSVC OR MSVC_VERSION GREATER 1310)
318 cxx_executable(googletest-throw-on-failure-test_ test gtest_no_exception)
319 set_target_properties(googletest-throw-on-failure-test_
320 PROPERTIES
321 COMPILE_FLAGS "${cxx_no_exception}")
322 py_test(googletest-throw-on-failure-test)
323 endif()
324
325 cxx_executable(googletest-uninitialized-test_ test gtest)
326 py_test(googletest-uninitialized-test)
327
328 cxx_executable(gtest_list_output_unittest_ test gtest)
329 py_test(gtest_list_output_unittest)
330
331 cxx_executable(gtest_xml_outfile1_test_ test gtest_main)
332 cxx_executable(gtest_xml_outfile2_test_ test gtest_main)
333 py_test(gtest_xml_outfiles_test)
334 py_test(googletest-json-outfiles-test)
335
336 cxx_executable(gtest_xml_output_unittest_ test gtest)
337 py_test(gtest_xml_output_unittest --no_stacktrace_support)
338 py_test(googletest-json-output-unittest --no_stacktrace_support)
339 endif()