| 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_CXX_STANDARD 98) |
| 13 |
set(CMAKE_CXX_STANDARD_REQUIRED TRUE) |
| 14 |
set(CMAKE_CXX_EXTENSIONS OFF) |
| 15 |
|
| 16 |
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_SANITIZER_FLAGS} ${CMAKE_CXX_FLAGS}") |
| 17 |
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15.0") |
| 18 |
message (VERBOSE "Warnings Configuration: CXX default: ${CMAKE_CXX_FLAGS}") |
| 19 |
endif () |
| 20 |
#----------------------------------------------------------------------------- |
| 21 |
# Compiler specific flags : Shouldn't there be compiler tests for these |
| 22 |
#----------------------------------------------------------------------------- |
| 23 |
if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_LOADED) |
| 24 |
set (CMAKE_CXX_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_CXX_FLAGS}") |
| 25 |
if (${HDF_CFG_NAME} MATCHES "Debug") |
| 26 |
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0) |
| 27 |
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Og -ftrapv -fno-common") |
| 28 |
endif () |
| 29 |
else () |
| 30 |
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0) |
| 31 |
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstdarg-opt") |
| 32 |
endif () |
| 33 |
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.0) |
| 34 |
if (HDF5_ENABLE_BUILD_DIAGS) |
| 35 |
message (STATUS "... default color and URL extended diagnostic messages enabled") |
| 36 |
else () |
| 37 |
message (STATUS "... disable color and URL extended diagnostic messages") |
| 38 |
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-urls=never -fno-diagnostics-color") |
| 39 |
endif () |
| 40 |
endif () |
| 41 |
endif () |
| 42 |
endif () |
| 43 |
|
| 44 |
#----------------------------------------------------------------------------- |
| 45 |
# Option to allow the user to disable compiler warnings |
| 46 |
#----------------------------------------------------------------------------- |
| 47 |
if (HDF5_DISABLE_COMPILER_WARNINGS) |
| 48 |
message (STATUS "....Compiler warnings are suppressed") |
| 49 |
# MSVC uses /w to suppress warnings. It also complains if another |
| 50 |
# warning level is given, so remove it. |
| 51 |
if (MSVC) |
| 52 |
set (HDF5_WARNINGS_BLOCKED 1) |
| 53 |
if (CMAKE_CXX_COMPILER_LOADED) |
| 54 |
string (REGEX REPLACE "(^| )([/-])W[0-9]( |$)" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 55 |
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W0") |
| 56 |
endif () |
| 57 |
endif () |
| 58 |
if (WIN32) |
| 59 |
add_definitions (-D_CRT_SECURE_NO_WARNINGS) |
| 60 |
endif () |
| 61 |
|
| 62 |
# Most compilers use -w to suppress warnings. |
| 63 |
if (NOT HDF5_WARNINGS_BLOCKED) |
| 64 |
if (CMAKE_CXX_COMPILER_LOADED) |
| 65 |
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w") |
| 66 |
endif () |
| 67 |
endif () |
| 68 |
endif () |
| 69 |
|
| 70 |
#----------------------------------------------------------------------------- |
| 71 |
# HDF5 library compile options |
| 72 |
#----------------------------------------------------------------------------- |
| 73 |
|
| 74 |
if (NOT MSVC AND NOT MINGW) |
| 75 |
if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS") |
| 76 |
list (APPEND HDF5_CMAKE_CXX_FLAGS "-erroff=%none -DBSD_COMP") |
| 77 |
else () |
| 78 |
# General flags |
| 79 |
# |
| 80 |
# Note that some of the flags listed here really should be developer |
| 81 |
# flags (listed in a separate variable, below) but we put them here |
| 82 |
# because they are not raised by the current code and we'd like to |
| 83 |
# know if they do start showing up. |
| 84 |
# |
| 85 |
# NOTE: Don't add -Wpadded here since we can't/won't fix the (many) |
| 86 |
# warnings that are emitted. If you need it, add it at configure time. |
| 87 |
if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel") |
| 88 |
ADD_H5_FLAGS (HDF5_CMAKE_CXX_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/general") |
| 89 |
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15.0) |
| 90 |
ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/15") |
| 91 |
endif() |
| 92 |
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0) |
| 93 |
ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/18") |
| 94 |
endif() |
| 95 |
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
| 96 |
if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_LOADED |
| 97 |
AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 4.8) |
| 98 |
# add the general CXX flags for g++ compiler versions 4.8 and above. |
| 99 |
ADD_H5_FLAGS (HDF5_CMAKE_CXX_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/cxx-general") |
| 100 |
if (HDF5_ENABLE_WARNINGS_AS_ERRORS) |
| 101 |
ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/cxx-error-general") |
| 102 |
else () |
| 103 |
ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/cxx-noerror-general") |
| 104 |
endif () |
| 105 |
endif () |
| 106 |
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
| 107 |
ADD_H5_FLAGS (HDF5_CMAKE_CXX_FLAGS "${HDF5_SOURCE_DIR}/config/clang-warnings/general") |
| 108 |
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "PGI") |
| 109 |
list (APPEND HDF5_CMAKE_CXX_FLAGS "-Minform=inform") |
| 110 |
endif () |
| 111 |
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15.0") |
| 112 |
message (VERBOSE "CMAKE_CXX_FLAGS_GENERAL=${HDF5_CMAKE_CXX_FLAGS}") |
| 113 |
endif () |
| 114 |
endif () |
| 115 |
|
| 116 |
#----------------------------------------------------------------------------- |
| 117 |
# Option to allow the user to enable developer warnings |
| 118 |
# Developer warnings (suggestions from gcc, not code problems) |
| 119 |
#----------------------------------------------------------------------------- |
| 120 |
if (HDF5_ENABLE_DEV_WARNINGS) |
| 121 |
message (STATUS "....HDF5 developer group warnings are enabled") |
| 122 |
if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel") |
| 123 |
ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/developer-general") |
| 124 |
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
| 125 |
# Use the C warnings as CXX warnings are the same |
| 126 |
ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-general") |
| 127 |
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
| 128 |
ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/clang-warnings/developer-general") |
| 129 |
endif () |
| 130 |
else () |
| 131 |
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
| 132 |
# Use the C warnings as CXX warnings are the same |
| 133 |
ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-general") |
| 134 |
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
| 135 |
ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/clang-warnings/no-developer-general") |
| 136 |
endif () |
| 137 |
endif () |
| 138 |
|
| 139 |
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
| 140 |
# Technically, variable-length arrays are part of the C99 standard, but |
| 141 |
# we should approach them a bit cautiously... Only needed for gcc 4.X |
| 142 |
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0 AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.8) |
| 143 |
# Use the C warnings as CXX warnings are the same |
| 144 |
ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/4.8-4.last") |
| 145 |
endif () |
| 146 |
|
| 147 |
# Append more extra warning flags that only gcc 4.8+ knows about |
| 148 |
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8) |
| 149 |
ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/cxx-4.8") |
| 150 |
if (HDF5_ENABLE_DEV_WARNINGS) |
| 151 |
# Use the C warnings as CXX warnings are the same |
| 152 |
ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-4.8") |
| 153 |
else () |
| 154 |
ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-4.8") |
| 155 |
endif () |
| 156 |
endif () |
| 157 |
|
| 158 |
# Append more extra warning flags that only gcc 4.9+ knows about |
| 159 |
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) |
| 160 |
# Use the C warnings as CXX warnings are the same |
| 161 |
ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/cxx-4.9") |
| 162 |
endif () |
| 163 |
|
| 164 |
# Append more extra warning flags that only gcc 5.1+ knows about |
| 165 |
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0) |
| 166 |
# autotools always add the C flags with the CXX flags |
| 167 |
ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/cxx-5") |
| 168 |
if (HDF5_ENABLE_WARNINGS_AS_ERRORS) |
| 169 |
ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/cxx-error-5") |
| 170 |
else () |
| 171 |
ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/cxx-noerror-5") |
| 172 |
endif () |
| 173 |
endif () |
| 174 |
|
| 175 |
# Append more extra warning flags that only gcc 6.x+ knows about |
| 176 |
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0) |
| 177 |
# Use the C warnings as CXX warnings are the same |
| 178 |
ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/6") |
| 179 |
endif () |
| 180 |
|
| 181 |
# Append more extra warning flags that only gcc 7.x+ knows about |
| 182 |
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0) |
| 183 |
# Use the C warnings as CXX warnings are the same |
| 184 |
ADD_H5_FLAGS (H5_CXxFLAGS2 "${HDF5_SOURCE_DIR}/config/gnu-warnings/7") |
| 185 |
if (HDF5_ENABLE_DEV_WARNINGS) |
| 186 |
# Use the C warnings as CXX warnings are the same |
| 187 |
ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-7") |
| 188 |
#else () |
| 189 |
# ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-7") |
| 190 |
endif () |
| 191 |
endif () |
| 192 |
|
| 193 |
# Append more extra warning flags that only gcc 8.x+ knows about |
| 194 |
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0) |
| 195 |
# Use the C warnings as CXX warnings are the same |
| 196 |
ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/8") |
| 197 |
if (HDF5_ENABLE_WARNINGS_AS_ERRORS) |
| 198 |
ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/error-8") |
| 199 |
else () |
| 200 |
ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/noerror-8") |
| 201 |
endif () |
| 202 |
if (HDF5_ENABLE_DEV_WARNINGS) |
| 203 |
# Use the C warnings as CXX warnings are the same |
| 204 |
ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-8") |
| 205 |
else () |
| 206 |
# autotools always add the C flags with the CXX flags |
| 207 |
ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-8") |
| 208 |
endif () |
| 209 |
endif () |
| 210 |
|
| 211 |
# Append more extra warning flags that only gcc 9.x+ knows about |
| 212 |
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0) |
| 213 |
# Use the C warnings as CXX warnings are the same |
| 214 |
ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/cxx-9") |
| 215 |
endif () |
| 216 |
|
| 217 |
# Append more extra warning flags that only gcc 9.3+ knows about |
| 218 |
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.3) |
| 219 |
# do not use C warnings, gnu-warnings 9.3, no cxx warniings |
| 220 |
# ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/9.3") |
| 221 |
endif () |
| 222 |
|
| 223 |
# Append more extra warning flags that only gcc 10.x+ knows about |
| 224 |
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.0) |
| 225 |
if (HDF5_ENABLE_DEV_WARNINGS) |
| 226 |
# Use the C warnings as CXX warnings are the same |
| 227 |
ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-10") |
| 228 |
#else () |
| 229 |
# ADD_H5_FLAGS (H5_CXXFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-10") |
| 230 |
endif () |
| 231 |
endif () |
| 232 |
endif () |
| 233 |
endif () |
| 234 |
|
| 235 |
#----------------------------------------------------------------------------- |
| 236 |
# Option to allow the user to enable all warnings |
| 237 |
#----------------------------------------------------------------------------- |
| 238 |
if (HDF5_ENABLE_ALL_WARNINGS) |
| 239 |
message (STATUS "....All Warnings are enabled") |
| 240 |
if (MSVC) |
| 241 |
if (HDF5_ENABLE_DEV_WARNINGS) |
| 242 |
if (CMAKE_CXX_COMPILER_LOADED) |
| 243 |
string (REGEX REPLACE "(^| )([/-])W[0-9]( |$)" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 244 |
list (APPEND HDF5_CMAKE_CXX_FLAGS "/Wall" "/wd4668") |
| 245 |
endif () |
| 246 |
else () |
| 247 |
if (CMAKE_CXX_COMPILER_LOADED) |
| 248 |
string (REGEX REPLACE "(^| )([/-])W[0-9]( |$)" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 249 |
list (APPEND HDF5_CMAKE_CXX_FLAGS "/W3" "/wd4100" "/wd4706" "/wd4127") |
| 250 |
endif () |
| 251 |
endif () |
| 252 |
else () |
| 253 |
if (CMAKE_CXX_COMPILER_LOADED) |
| 254 |
list (APPEND HDF5_CMAKE_CXX_FLAGS ${H5_CXXFLAGS}) |
| 255 |
endif () |
| 256 |
endif () |
| 257 |
endif () |
| 258 |
|
| 259 |
#----------------------------------------------------------------------------- |
| 260 |
# This is in here to help some of the GCC based IDES like Eclipse |
| 261 |
# and code blocks parse the compiler errors and warnings better. |
| 262 |
#----------------------------------------------------------------------------- |
| 263 |
if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_LOADED) |
| 264 |
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fmessage-length=0") |
| 265 |
endif () |
| 266 |
|
| 267 |
#----------------------------------------------------------------------------- |
| 268 |
# Option for --enable-symbols |
| 269 |
# This option will force/override the default setting for all configurations |
| 270 |
#----------------------------------------------------------------------------- |
| 271 |
if (HDF5_ENABLE_SYMBOLS MATCHES "YES") |
| 272 |
if(CMAKE_CXX_COMPILER_LOADED) |
| 273 |
if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel") |
| 274 |
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g") |
| 275 |
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
| 276 |
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g") |
| 277 |
endif () |
| 278 |
endif () |
| 279 |
elseif (HDF5_ENABLE_SYMBOLS MATCHES "NO") |
| 280 |
if(CMAKE_CXX_COMPILER_LOADED) |
| 281 |
if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel") |
| 282 |
set (CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -Wl,-s") |
| 283 |
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
| 284 |
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s") |
| 285 |
endif () |
| 286 |
endif () |
| 287 |
endif () |
| 288 |
|
| 289 |
#----------------------------------------------------------------------------- |
| 290 |
# Option for --enable-profiling |
| 291 |
# This option will force/override the default setting for all configurations |
| 292 |
#----------------------------------------------------------------------------- |
| 293 |
if (HDF5_ENABLE_PROFILING) |
| 294 |
if(CMAKE_CXX_COMPILER_LOADED) |
| 295 |
list (APPEND HDF5_CMAKE_CXX_FLAGS "${PROFILE_CXXFLAGS}") |
| 296 |
endif () |
| 297 |
endif () |
| 298 |
|
| 299 |
#----------------------------------------------------------------------------- |
| 300 |
# Option for --enable-optimization |
| 301 |
# This option will force/override the default setting for all configurations |
| 302 |
#----------------------------------------------------------------------------- |
| 303 |
if (HDF5_ENABLE_OPTIMIZATION) |
| 304 |
if(CMAKE_CXX_COMPILER_LOADED) |
| 305 |
list (APPEND HDF5_CMAKE_CXX_FLAGS "${OPTIMIZE_CXXFLAGS}") |
| 306 |
endif () |
| 307 |
endif () |