Debian Codegraph @

tests/CMakeLists.txt

raw ◀ ▶
Source reconstructed at patch state 0 of 3 — not the installed (fully patched) source.
3 Debian patches touch this file
1 cmake_minimum_required(VERSION 3.14...3.16)
2
3 project(GSLTests LANGUAGES CXX)
4
5 set(GSL_CXX_STANDARD ${CMAKE_CXX_STANDARD_DEFAULT} CACHE STRING "Use C++ standard")
6
7 set(CMAKE_CXX_STANDARD ${GSL_CXX_STANDARD})
8 set(CMAKE_CXX_EXTENSIONS OFF)
9 set(CMAKE_CXX_STANDARD_REQUIRED ON)
10
11 include(FindPkgConfig)
12 include(ExternalProject)
13
14 # will make visual studio generated project group files
15 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
16
17 if(CI_TESTING AND GSL_CXX_STANDARD EQUAL 20)
18 add_compile_definitions(FORCE_STD_SPAN_TESTS=1)
19 endif()
20
21 if(IOS)
22 add_compile_definitions(GTEST_HAS_DEATH_TEST=1 IOS_PROCESS_DELAY_WORKAROUND=1)
23 endif()
24
25 pkg_search_module(GTestMain gtest_main)
26 if (NOT GTestMain_FOUND)
27 # No pre-installed GTest is available, try to download it using Git.
28 find_package(Git REQUIRED QUIET)
29
30 configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
31 execute_process(
32 COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
33 RESULT_VARIABLE result
34 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download
35 )
36 if(result)
37 message(FATAL_ERROR "CMake step for googletest failed: ${result}")
38 endif()
39
40 execute_process(
41 COMMAND ${CMAKE_COMMAND} --build .
42 RESULT_VARIABLE result
43 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download
44 )
45 if(result)
46 message(FATAL_ERROR "CMake step for googletest failed: ${result}")
47 endif()
48
49 set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
50 set(GTestMain_LIBRARIES gtest_main)
51
52 add_subdirectory(
53 ${CMAKE_CURRENT_BINARY_DIR}/googletest-src
54 ${CMAKE_CURRENT_BINARY_DIR}/googletest-build
55 EXCLUDE_FROM_ALL
56 )
57 endif()
58
59 if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
60 find_package(Microsoft.GSL CONFIG REQUIRED)
61 enable_testing()
62
63 if (NOT DEFINED Microsoft.GSL_VERSION)
64 message(FATAL_ERROR "Microsoft.GSL_VERSION not defined!")
65 endif()
66
67 message(STATUS "Microsoft.GSL_VERSION = ${Microsoft.GSL_VERSION}")
68 endif()
69
70 if (MSVC AND (GSL_CXX_STANDARD GREATER_EQUAL 17))
71 set(GSL_CPLUSPLUS_OPT -Zc:__cplusplus -permissive-)
72 endif()
73
74 include(CheckCXXCompilerFlag)
75 # this interface adds compile options to how the tests are run
76 # please try to keep entries ordered =)
77 add_library(gsl_tests_config INTERFACE)
78 if(MSVC) # MSVC or simulating MSVC
79 target_compile_options(gsl_tests_config INTERFACE
80 ${GSL_CPLUSPLUS_OPT}
81 /EHsc
82 /W4
83 /WX
84 $<$<CXX_COMPILER_ID:MSVC>:
85 /wd4996 # Use of function or classes marked [[deprecated]]
86 /wd26409 # CppCoreCheck - GTest
87 /wd26426 # CppCoreCheck - GTest
88 /wd26440 # CppCoreCheck - GTest
89 /wd26446 # CppCoreCheck - prefer gsl::at()
90 /wd26472 # CppCoreCheck - use gsl::narrow(_cast)
91 /wd26481 # CppCoreCheck - use span instead of pointer arithmetic
92 $<$<VERSION_LESS:$<CXX_COMPILER_VERSION>,1920>: # VS2015
93 /wd4189 # variable is initialized but not referenced
94 $<$<NOT:$<CONFIG:Debug>>: # Release, RelWithDebInfo
95 /wd4702 # Unreachable code
96 >
97 >
98 >
99 $<$<CXX_COMPILER_ID:Clang>:
100 -Weverything
101 -Wfloat-equal
102 -Wno-c++98-compat
103 -Wno-c++98-compat-pedantic
104 -Wno-covered-switch-default # GTest
105 -Wno-deprecated-declarations # Allow tests for [[deprecated]] elements
106 -Wno-global-constructors # GTest
107 -Wno-language-extension-token # GTest gtest-port.h
108 -Wno-missing-braces
109 -Wno-missing-prototypes
110 -Wno-shift-sign-overflow # GTest gtest-port.h
111 -Wno-undef # GTest
112 -Wno-used-but-marked-unused # GTest EXPECT_DEATH
113 -Wno-switch-default # GTest EXPECT_DEATH
114 $<$<EQUAL:${GSL_CXX_STANDARD},14>: # no support for [[maybe_unused]]
115 -Wno-unused-member-function
116 -Wno-unused-variable
117 $<$<VERSION_EQUAL:$<CXX_COMPILER_VERSION>,15.0.1>:
118 -Wno-deprecated # False positive in MSVC Clang 15.0.1 raises a C++17 warning
119 >
120 >
121 >
122 )
123 check_cxx_compiler_flag("-Wreserved-identifier" WARN_RESERVED_ID)
124 if (WARN_RESERVED_ID)
125 target_compile_options(gsl_tests_config INTERFACE "-Wno-reserved-identifier")
126 endif()
127 else()
128 target_compile_options(gsl_tests_config INTERFACE
129 -fno-strict-aliasing
130 -Wall
131 -Wcast-align
132 -Wconversion
133 -Wctor-dtor-privacy
134 -Werror
135 -Wextra
136 -Wpedantic
137 -Wshadow
138 -Wsign-conversion
139 -Wfloat-equal
140 -Wno-deprecated-declarations # Allow tests for [[deprecated]] elements
141 $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
142 -Weverything
143 -Wno-c++98-compat
144 -Wno-c++98-compat-pedantic
145 -Wno-missing-braces
146 -Wno-covered-switch-default # GTest
147 -Wno-global-constructors # GTest
148 -Wno-missing-prototypes
149 -Wno-padded
150 -Wno-switch-default
151 -Wno-unknown-attributes
152 -Wno-used-but-marked-unused # GTest EXPECT_DEATH
153 -Wno-weak-vtables
154 $<$<EQUAL:${GSL_CXX_STANDARD},14>: # no support for [[maybe_unused]]
155 -Wno-unused-member-function
156 -Wno-unused-variable
157 >
158 >
159 $<$<CXX_COMPILER_ID:Clang>:
160 $<$<AND:$<VERSION_GREATER:$<CXX_COMPILER_VERSION>,4.99>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,6>>:
161 $<$<EQUAL:${GSL_CXX_STANDARD},17>:-Wno-undefined-func-template>
162 >
163 $<$<AND:$<EQUAL:${GSL_CXX_STANDARD},20>,$<OR:$<CXX_COMPILER_VERSION:11.0.0>,$<CXX_COMPILER_VERSION:10.0.0>>>:
164 -Wno-zero-as-null-pointer-constant # failing Clang Ubuntu 20.04 tests, seems to be a bug with clang 10.0.0
165 # and clang 11.0.0. (operator< is being re-written by the compiler
166 # as operator<=> and raising the warning)
167 >
168 >
169 $<$<CXX_COMPILER_ID:AppleClang>:
170 $<$<AND:$<VERSION_GREATER:$<CXX_COMPILER_VERSION>,9.1>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,10>>:
171 $<$<EQUAL:${GSL_CXX_STANDARD},17>:-Wno-undefined-func-template>
172 >
173 >
174 $<$<CXX_COMPILER_ID:GNU>:
175 -Wdouble-promotion # float implicit to double
176 -Wlogical-op # suspicious uses of logical operators
177 $<$<NOT:$<VERSION_LESS:$<CXX_COMPILER_VERSION>,6>>:
178 -Wduplicated-cond # duplicated if-else conditions
179 -Wmisleading-indentation
180 -Wnull-dereference
181 $<$<EQUAL:${GSL_CXX_STANDARD},14>: # no support for [[maybe_unused]]
182 -Wno-unused-variable
183 >
184 >
185 $<$<NOT:$<VERSION_LESS:$<CXX_COMPILER_VERSION>,7>>:
186 -Wduplicated-branches # identical if-else branches
187 >
188 >
189 )
190 endif(MSVC)
191 check_cxx_compiler_flag("-Wunsafe-buffer-usage" WARN_UNSAFE_BUFFER)
192 if (WARN_UNSAFE_BUFFER)
193 # This test uses very greedy heuristics such as "no pointer arithmetic on raw buffer"
194 target_compile_options(gsl_tests_config INTERFACE "-Wno-unsafe-buffer-usage")
195 endif()
196
197 # for tests to find the gtest header
198 target_include_directories(gsl_tests_config SYSTEM INTERFACE
199 googletest/googletest/include
200 )
201
202 add_executable(gsl_tests
203 algorithm_tests.cpp
204 assertion_tests.cpp
205 at_tests.cpp
206 byte_tests.cpp
207 notnull_tests.cpp
208 owner_tests.cpp
209 pointers_tests.cpp
210 span_compatibility_tests.cpp
211 span_ext_tests.cpp
212 span_tests.cpp
213 strict_notnull_tests.cpp
214
215 utils_tests.cpp
216 )
217
218 target_link_libraries(gsl_tests
219 Microsoft.GSL::GSL
220 gsl_tests_config
221 ${GTestMain_LIBRARIES}
222 )
223 add_test(gsl_tests gsl_tests)
224
225 # Ignore uninteresting warning about ABI change somewhere inside std::regex. GSL never supported GCC 5.
226 # The warning was removed in GCC 12, see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93011
227 if (CMAKE_SYSTEM_PROCESSOR STREQUAL "ppc64le" # PowerPC 64-bit Little-Endian
228 AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU" # GNU Compiler Collection
229 AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12)
230 if (CMAKE_MINOR_VERSION GREATER 10)
231 set_property(SOURCE span_tests.cpp APPEND PROPERTY COMPILE_OPTIONS "-Wno-psabi")
232 else()
233 target_compile_options(gsl_tests PRIVATE "-Wno-psabi")
234 endif()
235 endif()
236
237 # No exception tests
238
239 foreach(flag_var
240 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
241 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
242 STRING (REGEX REPLACE "/EHsc" "" ${flag_var} "${${flag_var}}")
243 endforeach(flag_var)
244
245 # this interface adds compile options to how the tests are run
246 # please try to keep entries ordered =)
247 add_library(gsl_tests_config_noexcept INTERFACE)
248 if(MSVC) # MSVC or simulating MSVC
249 target_compile_definitions(gsl_tests_config_noexcept INTERFACE
250 _HAS_EXCEPTIONS=0 # disable exceptions in the Microsoft STL
251 )
252 target_compile_options(gsl_tests_config_noexcept INTERFACE
253 ${GSL_CPLUSPLUS_OPT}
254 /W4
255 /WX
256 $<$<CXX_COMPILER_ID:MSVC>:
257 /wd4577
258 /wd4702
259 /wd26440 # CppCoreCheck - GTest
260 /wd26446 # CppCoreCheck - prefer gsl::at()
261 >
262 $<$<CXX_COMPILER_ID:Clang>:
263 -Weverything
264 -Wfloat-equal
265 -Wno-c++98-compat
266 -Wno-c++98-compat-pedantic
267 -Wno-missing-prototypes
268 -Wno-unknown-attributes
269 $<$<EQUAL:${GSL_CXX_STANDARD},14>:
270 $<$<VERSION_EQUAL:$<CXX_COMPILER_VERSION>,15.0.1>:
271 -Wno-deprecated # False positive in MSVC Clang 15.0.1 raises a C++17 warning
272 >
273 >
274 >
275 )
276 check_cxx_compiler_flag("-Wreserved-identifier" WARN_RESERVED_ID)
277 if (WARN_RESERVED_ID)
278 target_compile_options(gsl_tests_config_noexcept INTERFACE "-Wno-reserved-identifier")
279 endif()
280 else()
281 target_compile_options(gsl_tests_config_noexcept INTERFACE
282 -fno-exceptions
283 -fno-strict-aliasing
284 -Wall
285 -Wcast-align
286 -Wconversion
287 -Wctor-dtor-privacy
288 -Werror
289 -Wextra
290 -Wpedantic
291 -Wshadow
292 -Wsign-conversion
293 -Wfloat-equal
294 $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
295 -Weverything
296 -Wno-c++98-compat
297 -Wno-c++98-compat-pedantic
298 -Wno-missing-prototypes
299 -Wno-unknown-attributes
300 -Wno-weak-vtables
301 >
302 $<$<CXX_COMPILER_ID:GNU>:
303 -Wdouble-promotion # float implicit to double
304 -Wlogical-op # suspicious uses of logical operators
305 -Wuseless-cast # casting to its own type
306 $<$<NOT:$<VERSION_LESS:$<CXX_COMPILER_VERSION>,6>>:
307 -Wduplicated-cond # duplicated if-else conditions
308 -Wmisleading-indentation
309 -Wnull-dereference
310 >
311 $<$<NOT:$<VERSION_LESS:$<CXX_COMPILER_VERSION>,7>>:
312 -Wduplicated-branches # identical if-else branches
313 >
314 $<$<NOT:$<VERSION_LESS:$<CXX_COMPILER_VERSION>,8>>:
315 -Wcast-align=strict # increase alignment (i.e. char* to int*)
316 >
317 >
318 )
319 endif(MSVC)
320 check_cxx_compiler_flag("-Wunsafe-buffer-usage" WARN_UNSAFE_BUFFER)
321 if (WARN_UNSAFE_BUFFER)
322 # This test uses very greedy heuristics such as "no pointer arithmetic on raw buffer"
323 target_compile_options(gsl_tests_config_noexcept INTERFACE "-Wno-unsafe-buffer-usage")
324 endif()
325
326 add_executable(gsl_noexcept_tests no_exception_ensure_tests.cpp)
327 target_link_libraries(gsl_noexcept_tests
328 Microsoft.GSL::GSL
329 gsl_tests_config_noexcept
330 )
331 add_test(gsl_noexcept_tests gsl_noexcept_tests)