2017-04-18 03:32:16 +08:00
|
|
|
#
|
|
|
|
# Copyright by The HDF Group.
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# This file is part of HDF5. The full HDF5 copyright notice, including
|
|
|
|
# terms governing use, modification, and redistribution, is contained in
|
|
|
|
# the COPYING file, which can be found at the root of the source code
|
2021-02-17 22:52:36 +08:00
|
|
|
# distribution tree, or in https://www.hdfgroup.org/licenses.
|
2017-04-18 03:32:16 +08:00
|
|
|
# If you do not have access to either file, you may request a copy from
|
|
|
|
# help@hdfgroup.org.
|
|
|
|
#
|
2023-10-20 06:17:20 +08:00
|
|
|
set (CMAKE_C_STANDARD 99)
|
|
|
|
set (CMAKE_C_STANDARD_REQUIRED TRUE)
|
2018-08-17 04:45:17 +08:00
|
|
|
|
2019-01-03 07:07:37 +08:00
|
|
|
set (CMAKE_C_FLAGS "${CMAKE_C99_STANDARD_COMPILE_OPTION} ${CMAKE_C_FLAGS}")
|
2020-02-12 23:42:23 +08:00
|
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_SANITIZER_FLAGS} ${CMAKE_C_FLAGS}")
|
2022-09-03 08:31:29 +08:00
|
|
|
message (VERBOSE "Warnings Configuration: C default: ${CMAKE_C_FLAGS}")
|
2015-05-15 00:51:20 +08:00
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Compiler specific flags : Shouldn't there be compiler tests for these
|
|
|
|
#-----------------------------------------------------------------------------
|
2023-10-20 06:17:20 +08:00
|
|
|
if (WIN32 AND (CMAKE_C_COMPILER_ID STREQUAL "Intel" OR CMAKE_C_COMPILER_ID MATCHES "IntelLLVM"))
|
|
|
|
set (_INTEL_WINDOWS 1)
|
|
|
|
endif ()
|
2021-08-16 21:06:59 +08:00
|
|
|
|
2023-10-20 06:17:20 +08:00
|
|
|
if (WIN32 AND CMAKE_C_COMPILER_ID MATCHES "[Cc]lang" AND "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC")
|
|
|
|
set (_CLANG_MSVC_WINDOWS 1)
|
|
|
|
endif ()
|
2021-08-16 21:06:59 +08:00
|
|
|
|
|
|
|
# Disable deprecation warnings for standard C functions.
|
|
|
|
# really only needed for newer versions of VS, but should
|
|
|
|
# not hurt other versions, and this will work into the
|
|
|
|
# future
|
2023-10-20 06:17:20 +08:00
|
|
|
if (MSVC OR _INTEL_WINDOWS OR _CLANG_MSVC_WINDOWS)
|
|
|
|
add_definitions (-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
|
|
|
|
endif ()
|
2021-08-16 21:06:59 +08:00
|
|
|
|
2023-10-20 06:17:20 +08:00
|
|
|
if (MSVC)
|
|
|
|
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stack:10000000")
|
|
|
|
endif ()
|
2021-08-16 21:06:59 +08:00
|
|
|
|
|
|
|
# MSVC 14.28 enables C5105, but the Windows SDK 10.0.18362.0 triggers it.
|
2023-10-20 06:17:20 +08:00
|
|
|
if (CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 19.28)
|
|
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -wd5105")
|
|
|
|
endif ()
|
2021-08-16 21:06:59 +08:00
|
|
|
|
|
|
|
if(_CLANG_MSVC_WINDOWS AND "x${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU")
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Xlinker -stack:20000000")
|
|
|
|
endif()
|
|
|
|
|
2023-10-20 06:17:20 +08:00
|
|
|
if (CMAKE_C_COMPILER_ID STREQUAL "NVHPC" )
|
|
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Minform=warn")
|
2023-10-19 03:44:42 +08:00
|
|
|
if (NOT ${HDF_CFG_NAME} MATCHES "Debug" AND NOT ${HDF_CFG_NAME} MATCHES "Developer")
|
|
|
|
if (NOT ${HDF_CFG_NAME} MATCHES "RelWithDebInfo")
|
2023-10-20 06:17:20 +08:00
|
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s")
|
2023-10-19 03:44:42 +08:00
|
|
|
endif ()
|
|
|
|
else ()
|
2023-10-20 06:17:20 +08:00
|
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Mbounds -g")
|
2023-10-19 03:44:42 +08:00
|
|
|
endif ()
|
2023-11-02 03:41:46 +08:00
|
|
|
|
|
|
|
# With at least NVHPC 23.5 - 23.9, compiling with -O2 or higher and -DNDEBUG
|
|
|
|
# appears to have issues that manifest in the tests as incorrect metadata
|
|
|
|
# checksums being read or memory being corrupted. Compiling without -DNDEBUG
|
|
|
|
# does not appear to have these issues, but is not ideal due to compiling in
|
|
|
|
# asserts and other library debug code. Compiling with -O1 also does not appear
|
|
|
|
# to have these issues, so set maximum optimization level to -O1 for now until
|
|
|
|
# it can be determined whether these issues are compiler-specific or issues
|
|
|
|
# in the library.
|
|
|
|
set (cmake_c_flags_minsizerel_edited "${CMAKE_C_FLAGS_MINSIZEREL}")
|
|
|
|
string (REPLACE "-O2" "" cmake_c_flags_minsizerel_edited "${cmake_c_flags_minsizerel_edited}")
|
|
|
|
string (REPLACE "-O3" "" cmake_c_flags_minsizerel_edited "${cmake_c_flags_minsizerel_edited}")
|
|
|
|
string (REPLACE "-O4" "" cmake_c_flags_minsizerel_edited "${cmake_c_flags_minsizerel_edited}")
|
|
|
|
string (REPLACE "-Ofast" "" cmake_c_flags_minsizerel_edited "${cmake_c_flags_minsizerel_edited}")
|
|
|
|
string (REPLACE "-fast" "" cmake_c_flags_minsizerel_edited "${cmake_c_flags_minsizerel_edited}")
|
|
|
|
string (STRIP "${cmake_c_flags_minsizerel_edited}" cmake_c_flags_minsizerel_edited)
|
|
|
|
string (PREPEND cmake_c_flags_minsizerel_edited "-O1 ")
|
|
|
|
set (CMAKE_C_FLAGS_MINSIZEREL "${cmake_c_flags_minsizerel_edited}")
|
|
|
|
|
|
|
|
set (cmake_c_flags_release_edited "${CMAKE_C_FLAGS_RELEASE}")
|
|
|
|
string (REPLACE "-O2" "" cmake_c_flags_release_edited "${cmake_c_flags_release_edited}")
|
|
|
|
string (REPLACE "-O3" "" cmake_c_flags_release_edited "${cmake_c_flags_release_edited}")
|
|
|
|
string (REPLACE "-O4" "" cmake_c_flags_release_edited "${cmake_c_flags_release_edited}")
|
|
|
|
string (REPLACE "-Ofast" "" cmake_c_flags_release_edited "${cmake_c_flags_release_edited}")
|
|
|
|
string (REPLACE "-fast" "" cmake_c_flags_release_edited "${cmake_c_flags_release_edited}")
|
|
|
|
string (STRIP "${cmake_c_flags_release_edited}" cmake_c_flags_release_edited)
|
|
|
|
string (PREPEND cmake_c_flags_release_edited "-O1 ")
|
|
|
|
set (CMAKE_C_FLAGS_RELEASE "${cmake_c_flags_release_edited}")
|
|
|
|
|
|
|
|
set (cmake_c_flags_relwithdebinfo_edited "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
|
|
|
|
string (REPLACE "-O2" "" cmake_c_flags_relwithdebinfo_edited "${cmake_c_flags_relwithdebinfo_edited}")
|
|
|
|
string (REPLACE "-O3" "" cmake_c_flags_relwithdebinfo_edited "${cmake_c_flags_relwithdebinfo_edited}")
|
|
|
|
string (REPLACE "-O4" "" cmake_c_flags_relwithdebinfo_edited "${cmake_c_flags_relwithdebinfo_edited}")
|
|
|
|
string (REPLACE "-Ofast" "" cmake_c_flags_relwithdebinfo_edited "${cmake_c_flags_relwithdebinfo_edited}")
|
|
|
|
string (REPLACE "-fast" "" cmake_c_flags_relwithdebinfo_edited "${cmake_c_flags_relwithdebinfo_edited}")
|
|
|
|
string (STRIP "${cmake_c_flags_relwithdebinfo_edited}" cmake_c_flags_relwithdebinfo_edited)
|
|
|
|
string (PREPEND cmake_c_flags_relwithdebinfo_edited "-O1 ")
|
|
|
|
set (CMAKE_C_FLAGS_RELWITHDEBINFO "${cmake_c_flags_relwithdebinfo_edited}")
|
2023-10-20 06:17:20 +08:00
|
|
|
endif ()
|
2023-10-19 03:44:42 +08:00
|
|
|
|
2015-05-15 00:51:20 +08:00
|
|
|
if (CMAKE_COMPILER_IS_GNUCC)
|
2018-07-18 22:39:13 +08:00
|
|
|
set (CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}")
|
2022-08-20 08:18:30 +08:00
|
|
|
if (${HDF_CFG_NAME} MATCHES "Debug" OR ${HDF_CFG_NAME} MATCHES "Developer")
|
2015-05-15 22:38:38 +08:00
|
|
|
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0)
|
2015-07-10 00:56:16 +08:00
|
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Og -ftrapv -fno-common")
|
2015-05-15 22:38:38 +08:00
|
|
|
endif ()
|
2018-01-13 04:17:04 +08:00
|
|
|
else ()
|
2023-06-08 07:40:57 +08:00
|
|
|
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0 AND
|
|
|
|
NOT CMAKE_C_CLANG_TIDY)
|
|
|
|
# `clang-tidy` does not understand -fstdarg-opt
|
2015-05-15 00:51:20 +08:00
|
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstdarg-opt")
|
|
|
|
endif ()
|
2021-02-09 07:23:09 +08:00
|
|
|
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 10.0)
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Option to allow the user to enable build extended diagnostics
|
|
|
|
#
|
|
|
|
# This should NOT be on by default as it can cause process issues.
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
option (HDF5_ENABLE_BUILD_DIAGS "Enable color and URL extended diagnostic messages" OFF)
|
2023-04-14 01:36:48 +08:00
|
|
|
mark_as_advanced (HDF5_ENABLE_BUILD_DIAGS)
|
2021-02-09 07:23:09 +08:00
|
|
|
if (HDF5_ENABLE_BUILD_DIAGS)
|
|
|
|
message (STATUS "... default color and URL extended diagnostic messages enabled")
|
|
|
|
else ()
|
|
|
|
message (STATUS "... disable color and URL extended diagnostic messages")
|
|
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdiagnostics-urls=never -fno-diagnostics-color")
|
|
|
|
endif ()
|
|
|
|
endif ()
|
2017-01-11 07:09:53 +08:00
|
|
|
endif ()
|
|
|
|
endif ()
|
2015-05-15 00:51:20 +08:00
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Option to allow the user to disable compiler warnings
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
option (HDF5_DISABLE_COMPILER_WARNINGS "Disable compiler warnings" OFF)
|
|
|
|
if (HDF5_DISABLE_COMPILER_WARNINGS)
|
2018-08-17 04:45:17 +08:00
|
|
|
message (STATUS "....Compiler warnings are suppressed")
|
2015-05-15 00:51:20 +08:00
|
|
|
# MSVC uses /w to suppress warnings. It also complains if another
|
|
|
|
# warning level is given, so remove it.
|
|
|
|
if (MSVC)
|
|
|
|
set (HDF5_WARNINGS_BLOCKED 1)
|
|
|
|
string (REGEX REPLACE "(^| )([/-])W[0-9]( |$)" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
|
2018-01-31 02:46:23 +08:00
|
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W0")
|
2017-01-11 07:09:53 +08:00
|
|
|
endif ()
|
2015-05-15 00:51:20 +08:00
|
|
|
if (WIN32)
|
|
|
|
add_definitions (-D_CRT_SECURE_NO_WARNINGS)
|
2017-01-11 07:09:53 +08:00
|
|
|
endif ()
|
2015-05-15 00:51:20 +08:00
|
|
|
# Borland uses -w- to suppress warnings.
|
|
|
|
if (BORLAND)
|
|
|
|
set (HDF5_WARNINGS_BLOCKED 1)
|
|
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-")
|
2017-01-11 07:09:53 +08:00
|
|
|
endif ()
|
2015-05-15 00:51:20 +08:00
|
|
|
|
|
|
|
# Most compilers use -w to suppress warnings.
|
|
|
|
if (NOT HDF5_WARNINGS_BLOCKED)
|
|
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w")
|
2017-01-11 07:09:53 +08:00
|
|
|
endif ()
|
|
|
|
endif ()
|
2015-05-15 00:51:20 +08:00
|
|
|
|
2020-03-25 05:45:12 +08:00
|
|
|
#-----------------------------------------------------------------------------
|
2023-10-19 03:44:42 +08:00
|
|
|
# HDF5 library compile options - to be made available to all targets
|
2020-03-25 05:45:12 +08:00
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
2021-08-16 21:06:59 +08:00
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Option to allow the user to interpret certain warnings as errors
|
|
|
|
#
|
|
|
|
# This should NOT be on by default as it can cause a lot of conflicts with
|
|
|
|
# new operating systems and compiler versions. Header files that are out of
|
|
|
|
# our control (MPI, HDFS, etc.) can also raise warnings.
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
option (HDF5_ENABLE_WARNINGS_AS_ERRORS "Interpret some warnings as errors" OFF)
|
|
|
|
if (HDF5_ENABLE_WARNINGS_AS_ERRORS)
|
|
|
|
message (STATUS "...some warnings will be interpreted as errors")
|
|
|
|
endif ()
|
2020-11-25 11:57:48 +08:00
|
|
|
|
2021-08-16 21:06:59 +08:00
|
|
|
if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
|
|
|
|
list (APPEND HDF5_CMAKE_C_FLAGS "-erroff=%none -DBSD_COMP")
|
|
|
|
else ()
|
|
|
|
# General flags
|
|
|
|
#
|
|
|
|
# Note that some of the flags listed here really should be developer
|
|
|
|
# flags (listed in a separate variable, below) but we put them here
|
|
|
|
# because they are not raised by the current code and we'd like to
|
|
|
|
# know if they do start showing up.
|
|
|
|
#
|
|
|
|
# NOTE: Don't add -Wpadded here since we can't/won't fix the (many)
|
|
|
|
# warnings that are emitted. If you need it, add it at configure time.
|
|
|
|
if (CMAKE_C_COMPILER_ID STREQUAL "Intel")
|
|
|
|
if (_INTEL_WINDOWS)
|
2023-10-20 06:17:20 +08:00
|
|
|
ADD_H5_FLAGS (HDF5_CMAKE_C_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/win-general")
|
2021-08-16 21:06:59 +08:00
|
|
|
else ()
|
2023-10-20 06:17:20 +08:00
|
|
|
ADD_H5_FLAGS (HDF5_CMAKE_C_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/general")
|
2021-08-16 21:06:59 +08:00
|
|
|
endif()
|
|
|
|
if (NOT _INTEL_WINDOWS)
|
2023-10-20 06:17:20 +08:00
|
|
|
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 15.0)
|
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/15")
|
|
|
|
endif ()
|
2018-10-03 07:13:21 +08:00
|
|
|
# this is just a failsafe
|
2021-03-23 04:28:06 +08:00
|
|
|
list (APPEND H5_CFLAGS "-finline-functions")
|
2023-10-20 06:17:20 +08:00
|
|
|
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 18.0)
|
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/18")
|
|
|
|
endif ()
|
|
|
|
endif ()
|
2021-08-16 21:06:59 +08:00
|
|
|
elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
|
|
|
# Add general CFlags for GCC versions 4.8 and above
|
|
|
|
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.8)
|
|
|
|
ADD_H5_FLAGS (HDF5_CMAKE_C_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/general")
|
2021-10-07 05:24:22 +08:00
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/error-general")
|
2018-10-03 07:13:21 +08:00
|
|
|
endif ()
|
2021-08-16 21:06:59 +08:00
|
|
|
# gcc automatically inlines based on the optimization level
|
|
|
|
# this is just a failsafe
|
|
|
|
list (APPEND H5_CFLAGS "-finline-functions")
|
2023-10-20 06:17:20 +08:00
|
|
|
elseif (CMAKE_C_COMPILER_ID MATCHES "IntelLLVM")
|
|
|
|
if (_INTEL_WINDOWS)
|
|
|
|
ADD_H5_FLAGS (HDF5_CMAKE_C_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/oneapi/win-general")
|
|
|
|
else ()
|
|
|
|
# this is just a failsafe
|
|
|
|
list (APPEND H5_CFLAGS "-finline-functions")
|
|
|
|
ADD_H5_FLAGS (HDF5_CMAKE_C_FLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/oneapi/general")
|
|
|
|
endif ()
|
|
|
|
elseif (CMAKE_C_COMPILER_ID MATCHES "[Cc]lang")
|
2021-08-16 21:06:59 +08:00
|
|
|
ADD_H5_FLAGS (HDF5_CMAKE_C_FLAGS "${HDF5_SOURCE_DIR}/config/clang-warnings/general")
|
2021-10-07 05:24:22 +08:00
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/clang-warnings/error-general")
|
2021-08-16 21:06:59 +08:00
|
|
|
elseif (CMAKE_C_COMPILER_ID STREQUAL "PGI")
|
|
|
|
list (APPEND HDF5_CMAKE_C_FLAGS "-Minform=inform")
|
2017-01-11 07:09:53 +08:00
|
|
|
endif ()
|
2022-09-03 08:31:29 +08:00
|
|
|
message (VERBOSE "CMAKE_C_FLAGS_GENERAL=${HDF5_CMAKE_C_FLAGS}")
|
2021-08-16 21:06:59 +08:00
|
|
|
endif ()
|
2017-01-11 07:09:53 +08:00
|
|
|
|
2021-08-16 21:06:59 +08:00
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Option to allow the user to enable developer warnings
|
|
|
|
# Developer warnings (suggestions from gcc, not code problems)
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
option (HDF5_ENABLE_DEV_WARNINGS "Enable HDF5 developer group warnings" OFF)
|
2022-08-20 08:18:30 +08:00
|
|
|
if (${HDF_CFG_NAME} MATCHES "Developer")
|
|
|
|
# Developer build modes should always have these types of warnings enabled
|
|
|
|
set (HDF5_ENABLE_DEV_WARNINGS ON CACHE BOOL "Enable HDF5 developer group warnings" FORCE)
|
|
|
|
endif ()
|
2021-08-16 21:06:59 +08:00
|
|
|
if (HDF5_ENABLE_DEV_WARNINGS)
|
|
|
|
message (STATUS "....HDF5 developer group warnings are enabled")
|
|
|
|
if (CMAKE_C_COMPILER_ID STREQUAL "Intel")
|
|
|
|
if (_INTEL_WINDOWS)
|
2023-10-20 06:17:20 +08:00
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/win-developer-general")
|
2021-08-16 21:06:59 +08:00
|
|
|
else ()
|
2023-10-20 06:17:20 +08:00
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/classic/developer-general")
|
2017-01-13 04:00:50 +08:00
|
|
|
endif ()
|
2021-08-16 21:06:59 +08:00
|
|
|
elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.8)
|
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-general")
|
2023-10-20 06:17:20 +08:00
|
|
|
elseif (CMAKE_C_COMPILER_ID MATCHES "IntelLLVM")
|
|
|
|
if (_INTEL_WINDOWS)
|
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/oneapi/win-developer-general")
|
|
|
|
else ()
|
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/intel-warnings/oneapi/developer-general")
|
|
|
|
endif ()
|
|
|
|
elseif (CMAKE_C_COMPILER_ID MATCHES "[Cc]lang")
|
2021-08-16 21:06:59 +08:00
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/clang-warnings/developer-general")
|
2020-04-13 21:16:57 +08:00
|
|
|
endif ()
|
2023-07-18 19:27:07 +08:00
|
|
|
|
|
|
|
# Turn on -Winline warnings now only for non-Debug and
|
|
|
|
# non-Developer builds. For at least GNU compilers this
|
|
|
|
# flag appears to conflict specifically with the -Og
|
|
|
|
# optimization flag and will produce warnings about functions
|
|
|
|
# not being considered for inlining
|
|
|
|
if (NOT ${HDF_CFG_NAME} MATCHES "Debug" AND NOT ${HDF_CFG_NAME} MATCHES "Developer")
|
|
|
|
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
|
|
|
list (APPEND H5_CFLAGS "-Winline")
|
|
|
|
elseif (CMAKE_C_COMPILER_ID STREQUAL "Intel" AND NOT _INTEL_WINDOWS)
|
|
|
|
list (APPEND H5_CFLAGS "-Winline")
|
2023-10-20 06:17:20 +08:00
|
|
|
elseif (CMAKE_C_COMPILER_ID MATCHES "IntelLLVM" AND NOT _INTEL_WINDOWS)
|
|
|
|
list (APPEND H5_CFLAGS "-Winline")
|
|
|
|
elseif (CMAKE_C_COMPILER_ID MATCHES "[Cc]lang")
|
|
|
|
list (APPEND H5_CFLAGS "-Winline")
|
2023-07-18 19:27:07 +08:00
|
|
|
endif ()
|
|
|
|
endif ()
|
2021-08-16 21:06:59 +08:00
|
|
|
else ()
|
|
|
|
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.8)
|
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-general")
|
2023-10-20 06:17:20 +08:00
|
|
|
elseif (CMAKE_C_COMPILER_ID MATCHES "[Cc]lang")
|
2021-08-16 21:06:59 +08:00
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/clang-warnings/no-developer-general")
|
|
|
|
endif ()
|
|
|
|
endif ()
|
2015-05-15 00:51:20 +08:00
|
|
|
|
2021-08-16 21:06:59 +08:00
|
|
|
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
|
|
|
# Technically, variable-length arrays are part of the C99 standard, but
|
|
|
|
# we should approach them a bit cautiously... Only needed for gcc 4.X
|
|
|
|
if (CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0 AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.8)
|
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/4.8-4.last")
|
|
|
|
endif ()
|
2017-01-13 04:00:50 +08:00
|
|
|
|
2021-08-16 21:06:59 +08:00
|
|
|
# Append more extra warning flags that only gcc 4.8+ knows about
|
|
|
|
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.8)
|
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/4.8")
|
|
|
|
if (HDF5_ENABLE_DEV_WARNINGS)
|
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-4.8")
|
|
|
|
else ()
|
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-4.8")
|
2017-01-11 07:09:53 +08:00
|
|
|
endif ()
|
2021-08-16 21:06:59 +08:00
|
|
|
endif ()
|
2015-05-15 00:51:20 +08:00
|
|
|
|
2021-08-16 21:06:59 +08:00
|
|
|
# Append more extra warning flags that only gcc 4.9+ knows about
|
|
|
|
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.9)
|
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/4.9")
|
|
|
|
endif ()
|
2015-05-15 00:51:20 +08:00
|
|
|
|
2021-08-16 21:06:59 +08:00
|
|
|
# Append more extra warning flags that only gcc 5.x+ knows about
|
|
|
|
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0)
|
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/5")
|
2021-10-07 05:24:22 +08:00
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/error-5")
|
2021-08-16 21:06:59 +08:00
|
|
|
endif ()
|
2017-01-11 07:09:53 +08:00
|
|
|
|
2021-08-16 21:06:59 +08:00
|
|
|
# Append more extra warning flags that only gcc 6.x+ knows about
|
|
|
|
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 6.0)
|
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/6")
|
|
|
|
endif ()
|
2019-06-23 08:34:47 +08:00
|
|
|
|
2021-08-16 21:06:59 +08:00
|
|
|
# Append more extra warning flags that only gcc 7.x+ knows about
|
|
|
|
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 7.0)
|
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/7")
|
2022-05-07 07:26:48 +08:00
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/error-7")
|
2021-08-16 21:06:59 +08:00
|
|
|
if (HDF5_ENABLE_DEV_WARNINGS)
|
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-7")
|
|
|
|
#else ()
|
|
|
|
# ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-7")
|
2017-01-11 07:09:53 +08:00
|
|
|
endif ()
|
2021-08-16 21:06:59 +08:00
|
|
|
endif ()
|
2015-05-15 00:51:20 +08:00
|
|
|
|
2021-08-16 21:06:59 +08:00
|
|
|
# Append more extra warning flags that only gcc 8.x+ knows about
|
|
|
|
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 8.0)
|
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/8")
|
2021-10-07 05:24:22 +08:00
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/error-8")
|
2021-08-16 21:06:59 +08:00
|
|
|
if (HDF5_ENABLE_DEV_WARNINGS)
|
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-8")
|
|
|
|
else ()
|
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-8")
|
2021-03-23 04:28:06 +08:00
|
|
|
endif ()
|
2021-08-16 21:06:59 +08:00
|
|
|
endif ()
|
2021-03-23 04:28:06 +08:00
|
|
|
|
2021-08-16 21:06:59 +08:00
|
|
|
# Append more extra warning flags that only gcc 9.x+ knows about
|
|
|
|
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 9.0)
|
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/9")
|
|
|
|
endif ()
|
2021-03-23 04:28:06 +08:00
|
|
|
|
2021-08-16 21:06:59 +08:00
|
|
|
# Append more extra warning flags that only gcc 9.3+ knows about
|
|
|
|
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 9.3)
|
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/9.3")
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
# Append more extra warning flags that only gcc 10.x+ knows about
|
|
|
|
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 10.0)
|
|
|
|
if (HDF5_ENABLE_DEV_WARNINGS)
|
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-10")
|
|
|
|
#else ()
|
|
|
|
# ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-10")
|
2019-07-03 12:49:35 +08:00
|
|
|
endif ()
|
2020-04-13 21:16:57 +08:00
|
|
|
endif ()
|
2022-08-20 08:18:30 +08:00
|
|
|
|
|
|
|
# Append more extra warning flags that only gcc 12.x+ knows about
|
|
|
|
# or which should only be enabled for gcc 12.x+
|
|
|
|
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 12.0)
|
|
|
|
if (HDF5_ENABLE_DEV_WARNINGS)
|
|
|
|
ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-12")
|
|
|
|
#else ()
|
|
|
|
# ADD_H5_FLAGS (H5_CFLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/no-developer-12")
|
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Option to allow the user to enable debug output
|
|
|
|
# from various HDF5 modules
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
option (HDF5_ENABLE_DEBUG_APIS "Turn on extra debug output in all packages" OFF)
|
|
|
|
if (HDF5_ENABLE_DEBUG_APIS)
|
|
|
|
# Add standard debug definitions to any existing ones
|
|
|
|
list (APPEND HDF5_DEBUG_APIS
|
|
|
|
H5AC_DEBUG
|
|
|
|
H5CX_DEBUG
|
|
|
|
H5D_DEBUG
|
|
|
|
H5D_CHUNK_DEBUG
|
|
|
|
H5F_DEBUG
|
|
|
|
H5HL_DEBUG
|
|
|
|
H5I_DEBUG
|
2023-08-26 04:56:50 +08:00
|
|
|
H5MM_DEBUG
|
2022-08-20 08:18:30 +08:00
|
|
|
H5O_DEBUG
|
|
|
|
H5S_DEBUG
|
|
|
|
H5T_DEBUG
|
|
|
|
H5Z_DEBUG
|
|
|
|
)
|
2017-01-11 07:09:53 +08:00
|
|
|
endif ()
|
2015-05-15 00:51:20 +08:00
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Option to allow the user to enable all warnings
|
|
|
|
#-----------------------------------------------------------------------------
|
2021-03-23 04:28:06 +08:00
|
|
|
option (HDF5_ENABLE_ALL_WARNINGS "Enable all warnings" ON)
|
2015-05-15 00:51:20 +08:00
|
|
|
if (HDF5_ENABLE_ALL_WARNINGS)
|
2018-08-17 04:45:17 +08:00
|
|
|
message (STATUS "....All Warnings are enabled")
|
2015-05-15 00:51:20 +08:00
|
|
|
if (MSVC)
|
2017-01-13 02:41:50 +08:00
|
|
|
if (HDF5_ENABLE_DEV_WARNINGS)
|
|
|
|
string (REGEX REPLACE "(^| )([/-])W[0-9]( |$)" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
|
2021-03-23 04:28:06 +08:00
|
|
|
list (APPEND HDF5_CMAKE_C_FLAGS "/Wall" "/wd4668")
|
2017-01-13 02:41:50 +08:00
|
|
|
else ()
|
|
|
|
string (REGEX REPLACE "(^| )([/-])W[0-9]( |$)" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
|
2021-03-23 04:28:06 +08:00
|
|
|
list (APPEND HDF5_CMAKE_C_FLAGS "/W3" "/wd4100" "/wd4706" "/wd4127")
|
2017-01-13 02:41:50 +08:00
|
|
|
endif ()
|
2017-01-11 07:09:53 +08:00
|
|
|
else ()
|
2021-03-23 04:28:06 +08:00
|
|
|
list (APPEND HDF5_CMAKE_C_FLAGS ${H5_CFLAGS})
|
2017-01-11 07:09:53 +08:00
|
|
|
endif ()
|
|
|
|
endif ()
|
2015-05-15 00:51:20 +08:00
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# This is in here to help some of the GCC based IDES like Eclipse
|
|
|
|
# and code blocks parse the compiler errors and warnings better.
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
if (CMAKE_COMPILER_IS_GNUCC)
|
|
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fmessage-length=0")
|
2017-01-11 07:09:53 +08:00
|
|
|
endif ()
|
2019-09-14 00:33:47 +08:00
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Option for --enable-asserts
|
|
|
|
# By default, CMake adds NDEBUG to CMAKE_${lang}_FLAGS for Release build types
|
|
|
|
# This option will force/override the default setting for all configurations
|
|
|
|
#-----------------------------------------------------------------------------
|
2019-09-18 04:43:27 +08:00
|
|
|
#option (HDF5_ENABLE_ASSERTS "Determines whether NDEBUG is defined to control assertions." OFF)
|
|
|
|
set (HDF5_ENABLE_ASSERTS "OFF" CACHE STRING "Determines whether NDEBUG is defined to control assertions (OFF NO YES)")
|
|
|
|
set_property (CACHE HDF5_ENABLE_ASSERTS PROPERTY STRINGS OFF NO YES)
|
|
|
|
if (HDF5_ENABLE_ASSERTS MATCHES "YES")
|
2019-09-14 00:33:47 +08:00
|
|
|
add_compile_options ("-UNDEBUG")
|
2019-09-18 04:43:27 +08:00
|
|
|
elseif (HDF5_ENABLE_ASSERTS MATCHES "NO")
|
2019-09-14 00:33:47 +08:00
|
|
|
add_compile_options ("-DNDEBUG")
|
|
|
|
endif ()
|
|
|
|
MARK_AS_ADVANCED (HDF5_ENABLE_ASSERTS)
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Option for --enable-symbols
|
|
|
|
# This option will force/override the default setting for all configurations
|
|
|
|
#-----------------------------------------------------------------------------
|
2019-09-18 04:43:27 +08:00
|
|
|
#option (HDF5_ENABLE_SYMBOLS "Add debug symbols to the library independent of the build mode and optimization level." OFF)
|
|
|
|
set (HDF5_ENABLE_SYMBOLS "OFF" CACHE STRING "Add debug symbols to the library independent of the build mode and optimization level (OFF NO YES)")
|
|
|
|
set_property (CACHE HDF5_ENABLE_SYMBOLS PROPERTY STRINGS OFF NO YES)
|
|
|
|
if (HDF5_ENABLE_SYMBOLS MATCHES "YES")
|
2021-08-16 21:06:59 +08:00
|
|
|
if (CMAKE_C_COMPILER_ID STREQUAL "Intel" AND NOT _INTEL_WINDOWS)
|
2019-09-14 00:33:47 +08:00
|
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
|
|
|
|
elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
|
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fno-omit-frame-pointer")
|
|
|
|
endif ()
|
2019-09-18 04:43:27 +08:00
|
|
|
elseif (HDF5_ENABLE_SYMBOLS MATCHES "NO")
|
2021-08-16 21:06:59 +08:00
|
|
|
if (CMAKE_C_COMPILER_ID STREQUAL "Intel" AND NOT _INTEL_WINDOWS)
|
2019-09-14 00:33:47 +08:00
|
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-s")
|
|
|
|
elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
|
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s")
|
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
MARK_AS_ADVANCED (HDF5_ENABLE_SYMBOLS)
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Option for --enable-profiling
|
|
|
|
# This option will force/override the default setting for all configurations
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
option (HDF5_ENABLE_PROFILING "Enable profiling flags independently from the build mode." OFF)
|
|
|
|
if (HDF5_ENABLE_PROFILING)
|
2020-03-25 05:45:12 +08:00
|
|
|
list (APPEND HDF5_CMAKE_C_FLAGS "${PROFILE_CFLAGS}")
|
2019-09-14 00:33:47 +08:00
|
|
|
endif ()
|
|
|
|
MARK_AS_ADVANCED (HDF5_ENABLE_PROFILING)
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Option for --enable-optimization
|
|
|
|
# This option will force/override the default setting for all configurations
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
option (HDF5_ENABLE_OPTIMIZATION "Enable optimization flags/settings independently from the build mode" OFF)
|
|
|
|
if (HDF5_ENABLE_OPTIMIZATION)
|
2020-03-25 05:45:12 +08:00
|
|
|
list (APPEND HDF5_CMAKE_C_FLAGS "${OPTIMIZE_CFLAGS}")
|
2019-09-14 00:33:47 +08:00
|
|
|
endif ()
|
|
|
|
MARK_AS_ADVANCED (HDF5_ENABLE_OPTIMIZATION)
|