Debian Codegraph @

Modules/ThirdParty/HDF5/src/itkhdf5/config/cmake/HDFCompilerFlags.cmake

raw
1 #
2 # Copyright by The HDF Group.
3 # All rights reserved.
4 #
5 # This file is part of HDF5. The full HDF5 copyright notice, including
6 # terms governing use, modification, and redistribution, is contained in
7 # the COPYING file, which can be found at the root of the source code
8 # distribution tree, or in https://www.hdfgroup.org/licenses.
9 # If you do not have access to either file, you may request a copy from
10 # [email protected].
11 #
12 set(CMAKE_C_STANDARD 99)
13 set(CMAKE_C_STANDARD_REQUIRED TRUE)
14
15 set (CMAKE_C_FLAGS "${CMAKE_C99_STANDARD_COMPILE_OPTION} ${CMAKE_C_FLAGS}")
16 set (CMAKE_C_FLAGS "${CMAKE_C_SANITIZER_FLAGS} ${CMAKE_C_FLAGS}")
17 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_SANITIZER_FLAGS} ${CMAKE_CXX_FLAGS}")
18
19 #[[ ITK --start
20 if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15.0")
21 message (VERBOSE "Warnings Configuration: default: ${CMAKE_C_FLAGS} : ${CMAKE_CXX_FLAGS}")
22 endif ()
23 # ITK --stop ]]
24 #-----------------------------------------------------------------------------
25 # Compiler specific flags : Shouldn't there be compiler tests for these
26 #-----------------------------------------------------------------------------
27 set(CMAKE_C_STANDARD 99)
28 set(CMAKE_C_EXTENSIONS ON)
29 if (CMAKE_COMPILER_IS_GNUCC)
30 set (CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}")
31 if (${HDF_CFG_NAME} MATCHES "Debug")
32 if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0)
33 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Og -ftrapv -fno-common")
34 endif ()
35 else ()
36 if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0 AND
37 NOT CMAKE_C_CLANG_TIDY)
38 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstdarg-opt")
39 endif ()
40 if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 10.0)
41 #-----------------------------------------------------------------------------
42 # Option to allow the user to enable build extended diagnostics
43 #
44 # This should NOT be on by default as it can cause process issues.
45 #-----------------------------------------------------------------------------
46 if (FALSE) # XXX(kitware): Hardcode settings.
47 option (HDF5_ENABLE_BUILD_DIAGS "Enable color and URL extended diagnostic messages" OFF)
48 else ()
49 set(HDF5_ENABLE_BUILD_DIAGS OFF)
50 endif ()
51 #[[ ITK --start
52 if (HDF5_ENABLE_BUILD_DIAGS)
53 message (STATUS "... default color and URL extended diagnostic messages enabled")
54 else ()
55 message (STATUS "... disable color and URL extended diagnostic messages")
56 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdiagnostics-urls=never -fno-diagnostics-color")
57 endif ()
58 # ITK --stop ]]
59 endif ()
60 endif ()
61 endif ()
62
63 #-----------------------------------------------------------------------------
64 # Option to allow the user to disable compiler warnings
65 #-----------------------------------------------------------------------------
66 if (FALSE) # XXX(kitware): Hardcode settings.
67 option (HDF5_DISABLE_COMPILER_WARNINGS "Disable compiler warnings" OFF)
68 else ()
69 set(HDF5_DISABLE_COMPILER_WARNINGS OFF)
70 endif ()
71 if (HDF5_DISABLE_COMPILER_WARNINGS)
72 message (STATUS "....Compiler warnings are suppressed")
73 # MSVC uses /w to suppress warnings. It also complains if another
74 # warning level is given, so remove it.
75 if (MSVC)
76 set (HDF5_WARNINGS_BLOCKED 1)
77 string (REGEX REPLACE "(^| )([/-])W[0-9]( |$)" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
78 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W0")
79 endif ()
80 if (WIN32)
81 add_definitions (-D_CRT_SECURE_NO_WARNINGS)
82 endif ()
83 # Borland uses -w- to suppress warnings.
84 if (BORLAND)
85 set (HDF5_WARNINGS_BLOCKED 1)
86 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-")
87 endif ()
88
89 # Most compilers use -w to suppress warnings.
90 if (NOT HDF5_WARNINGS_BLOCKED)
91 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w")
92 endif ()
93 endif ()
94
95 #-----------------------------------------------------------------------------
96 # HDF5 library compile options
97 #-----------------------------------------------------------------------------
98
99 if (NOT MSVC AND NOT MINGW)
100 #-----------------------------------------------------------------------------
101 # Option to allow the user to interpret certain warnings as errors
102 #
103 # This should NOT be on by default as it can cause a lot of conflicts with
104 # new operating systems and compiler versions. Header files that are out of
105 # our control (MPI, HDFS, etc.) can also raise warnings.
106 #-----------------------------------------------------------------------------
107 if (FALSE) # XXX(kitware): Hardcode settings.
108 option (HDF5_ENABLE_WARNINGS_AS_ERRORS "Interpret some warnings as errors" OFF)
109 else ()
110 set(HDF5_ENABLE_WARNINGS_AS_ERRORS OFF)
111 endif ()
112 if (HDF5_ENABLE_WARNINGS_AS_ERRORS)
113 message (STATUS "...some warnings will be interpreted as errors")
114 endif ()
115
116 if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
117 list (APPEND HDF5_CMAKE_C_FLAGS "-erroff=%none -DBSD_COMP")
118 else ()
119 # General flags
120 #
121 # Note that some of the flags listed here really should be developer
122 # flags (listed in a separate variable, below) but we put them here
123 # because they are not raised by the current code and we'd like to
124 # know if they do start showing up.
125 #
126 # NOTE: Don't add -Wpadded here since we can't/won't fix the (many)
127 # warnings that are emitted. If you need it, add it at configure time.
128 if (CMAKE_C_COMPILER_ID STREQUAL "Intel")
129 ADD_H5_FLAGS (HDF5_CMAKE_C_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/general")
130 if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 15.0)
131 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/15")
132 endif()
133 # this is just a failsafe
134 list (APPEND H5_CFLAGS "-finline-functions")
135 if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 18.0)
136 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/18")
137 endif()
138 elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU")
139 # Add general CFlags for GCC versions 4.8 and above
140 if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.8)
141 ADD_H5_FLAGS (HDF5_CMAKE_C_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/general")
142 if (HDF5_ENABLE_WARNINGS_AS_ERRORS)
143 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/error-general")
144 else ()
145 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/noerror-general")
146 endif ()
147 endif ()
148 # gcc automatically inlines based on the optimization level
149 # this is just a failsafe
150 list (APPEND H5_CFLAGS "-finline-functions")
151 elseif (CMAKE_C_COMPILER_ID MATCHES "[Cc]lang")
152 ADD_H5_FLAGS (HDF5_CMAKE_C_FLAGS "${HDF5_SOURCE_DIR}/config/clang-warnings/general")
153 if (HDF5_ENABLE_WARNINGS_AS_ERRORS)
154 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/clang-warnings/error-general")
155 else ()
156 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/clang-warnings/noerror-general")
157 endif ()
158 elseif (CMAKE_C_COMPILER_ID STREQUAL "PGI")
159 list (APPEND HDF5_CMAKE_C_FLAGS "-Minform=inform")
160 endif ()
161 #[[ ITK --start
162 if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15.0")
163 message (VERBOSE "CMAKE_C_FLAGS_GENERAL=${HDF5_CMAKE_C_FLAGS}")
164 endif ()
165 # ITK --stop ]]
166 endif ()
167
168 #-----------------------------------------------------------------------------
169 # Option to allow the user to enable developer warnings
170 # Developer warnings (suggestions from gcc, not code problems)
171 #-----------------------------------------------------------------------------
172 if (FALSE) # XXX(kitware): Hardcode settings.
173 option (HDF5_ENABLE_DEV_WARNINGS "Enable HDF5 developer group warnings" OFF)
174 else ()
175 set(HDF5_ENABLE_DEV_WARNINGS OFF)
176 endif ()
177 if (HDF5_ENABLE_DEV_WARNINGS)
178 message (STATUS "....HDF5 developer group warnings are enabled")
179 if (CMAKE_C_COMPILER_ID STREQUAL "Intel")
180 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/developer-general")
181 elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.8)
182 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-general")
183 elseif (CMAKE_C_COMPILER_ID MATCHES "[Cc]lang")
184 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/clang-warnings/developer-general")
185 endif ()
186 else ()
187 if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.8)
188 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-general")
189 elseif (CMAKE_C_COMPILER_ID MATCHES "[Cc]lang")
190 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/clang-warnings/no-developer-general")
191 endif ()
192 endif ()
193
194 if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
195 # Technically, variable-length arrays are part of the C99 standard, but
196 # we should approach them a bit cautiously... Only needed for gcc 4.X
197 if (CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0 AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.8)
198 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/4.8-4.last")
199 endif ()
200
201 # Append more extra warning flags that only gcc 4.8+ knows about
202 if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.8)
203 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/4.8")
204 if (HDF5_ENABLE_DEV_WARNINGS)
205 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-4.8")
206 else ()
207 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-4.8")
208 endif ()
209 endif ()
210
211 # Append more extra warning flags that only gcc 4.9+ knows about
212 if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.9)
213 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/4.9")
214 endif ()
215
216 # Append more extra warning flags that only gcc 5.x+ knows about
217 if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0)
218 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/5")
219 if (HDF5_ENABLE_WARNINGS_AS_ERRORS)
220 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/error-5")
221 else ()
222 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/error-5")
223 endif ()
224 endif ()
225
226 # Append more extra warning flags that only gcc 6.x+ knows about
227 if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 6.0)
228 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/6")
229 endif ()
230
231 # Append more extra warning flags that only gcc 7.x+ knows about
232 if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 7.0)
233 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/7")
234 if (HDF5_ENABLE_DEV_WARNINGS)
235 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-7")
236 #else ()
237 # ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-7")
238 endif ()
239 endif ()
240
241 # Append more extra warning flags that only gcc 8.x+ knows about
242 if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 8.0)
243 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/8")
244 if (HDF5_ENABLE_WARNINGS_AS_ERRORS)
245 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/error-8")
246 endif ()
247 if (HDF5_ENABLE_DEV_WARNINGS)
248 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-8")
249 else ()
250 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-8")
251 endif ()
252 endif ()
253
254 # Append more extra warning flags that only gcc 9.x+ knows about
255 if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 9.0)
256 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/9")
257 endif ()
258
259 # Append more extra warning flags that only gcc 9.3+ knows about
260 if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 9.3)
261 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/9.3")
262 endif ()
263
264 # Append more extra warning flags that only gcc 10.x+ knows about
265 if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 10.0)
266 if (HDF5_ENABLE_DEV_WARNINGS)
267 ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-10")
268 #else ()
269 # ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-10")
270 endif ()
271 endif ()
272 endif ()
273 endif ()
274
275 #-----------------------------------------------------------------------------
276 # Option to allow the user to enable all warnings
277 #-----------------------------------------------------------------------------
278 if (FALSE) # XXX(kitware): Hardcode settings.
279 option (HDF5_ENABLE_ALL_WARNINGS "Enable all warnings" ON)
280 else ()
281 set(HDF5_ENABLE_ALL_WARNINGS OFF)
282 endif ()
283 if (HDF5_ENABLE_ALL_WARNINGS)
284 message (STATUS "....All Warnings are enabled")
285 if (MSVC)
286 if (HDF5_ENABLE_DEV_WARNINGS)
287 string (REGEX REPLACE "(^| )([/-])W[0-9]( |$)" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
288 list (APPEND HDF5_CMAKE_C_FLAGS "/Wall" "/wd4668")
289 else ()
290 string (REGEX REPLACE "(^| )([/-])W[0-9]( |$)" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
291 list (APPEND HDF5_CMAKE_C_FLAGS "/W3" "/wd4100" "/wd4706" "/wd4127")
292 endif ()
293 else ()
294 list (APPEND HDF5_CMAKE_C_FLAGS ${H5_CFLAGS})
295 endif ()
296 endif ()
297
298 #-----------------------------------------------------------------------------
299 # This is in here to help some of the GCC based IDES like Eclipse
300 # and code blocks parse the compiler errors and warnings better.
301 #-----------------------------------------------------------------------------
302 if (CMAKE_COMPILER_IS_GNUCC)
303 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fmessage-length=0")
304 endif ()
305
306 #-----------------------------------------------------------------------------
307 # Option for --enable-asserts
308 # By default, CMake adds NDEBUG to CMAKE_${lang}_FLAGS for Release build types
309 # This option will force/override the default setting for all configurations
310 #-----------------------------------------------------------------------------
311 if (FALSE) # XXX(kitware): Hardcode settings.
312 #option (HDF5_ENABLE_ASSERTS "Determines whether NDEBUG is defined to control assertions." OFF)
313 set (HDF5_ENABLE_ASSERTS "OFF" CACHE STRING "Determines whether NDEBUG is defined to control assertions (OFF NO YES)")
314 set_property (CACHE HDF5_ENABLE_ASSERTS PROPERTY STRINGS OFF NO YES)
315 mark_as_advanced (HDF5_ENABLE_ASSERTS)
316 else ()
317 set(HDF5_ENABLE_ASSERTS OFF)
318 endif ()
319 if (HDF5_ENABLE_ASSERTS MATCHES "YES")
320 add_compile_options ("-UNDEBUG")
321 elseif (HDF5_ENABLE_ASSERTS MATCHES "NO")
322 add_compile_options ("-DNDEBUG")
323 endif ()
324
325 #-----------------------------------------------------------------------------
326 # Option for --enable-symbols
327 # This option will force/override the default setting for all configurations
328 #-----------------------------------------------------------------------------
329 if (FALSE) # XXX(kitware): Hardcode settings.
330 #option (HDF5_ENABLE_SYMBOLS "Add debug symbols to the library independent of the build mode and optimization level." OFF)
331 set (HDF5_ENABLE_SYMBOLS "OFF" CACHE STRING "Add debug symbols to the library independent of the build mode and optimization level (OFF NO YES)")
332 set_property (CACHE HDF5_ENABLE_SYMBOLS PROPERTY STRINGS OFF NO YES)
333 mark_as_advanced (HDF5_ENABLE_SYMBOLS)
334 else ()
335 set(HDF5_ENABLE_SYMBOLS OFF)
336 endif ()
337 if (HDF5_ENABLE_SYMBOLS STREQUAL "YES")
338 if (CMAKE_C_COMPILER_ID STREQUAL "Intel")
339 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
340 elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU")
341 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fno-omit-frame-pointer")
342 endif ()
343 elseif (HDF5_ENABLE_SYMBOLS STREQUAL "NO")
344 if (CMAKE_C_COMPILER_ID STREQUAL "Intel")
345 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-s")
346 elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU")
347 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s")
348 endif ()
349 endif ()
350
351 #-----------------------------------------------------------------------------
352 # Option for --enable-profiling
353 # This option will force/override the default setting for all configurations
354 #-----------------------------------------------------------------------------
355 if (FALSE) # XXX(kitware): Hardcode settings.
356 option (HDF5_ENABLE_PROFILING "Enable profiling flags independently from the build mode." OFF)
357 mark_as_advanced (HDF5_ENABLE_PROFILING)
358 else ()
359 set(HDF5_ENABLE_PROFILING OFF)
360 endif ()
361 if (HDF5_ENABLE_PROFILING)
362 list (APPEND HDF5_CMAKE_C_FLAGS "${PROFILE_CFLAGS}")
363 endif ()
364
365 #-----------------------------------------------------------------------------
366 # Option for --enable-optimization
367 # This option will force/override the default setting for all configurations
368 #-----------------------------------------------------------------------------
369 if (FALSE) # XXX(kitware): Hardcode settings.
370 option (HDF5_ENABLE_OPTIMIZATION "Enable optimization flags/settings independently from the build mode" OFF)
371 mark_as_advanced (HDF5_ENABLE_OPTIMIZATION)
372 else ()
373 set(HDF5_ENABLE_OPTIMIZATION OFF)
374 endif ()
375 if (HDF5_ENABLE_OPTIMIZATION)
376 list (APPEND HDF5_CMAKE_C_FLAGS "${OPTIMIZE_CFLAGS}")
377 endif ()