summaryrefslogtreecommitdiffstats
path: root/config/cmake/HDFCompilerFlags.cmake
diff options
context:
space:
mode:
authorLarry Knox <lrknox@hdfgroup.org>2020-04-23 18:41:34 (GMT)
committerLarry Knox <lrknox@hdfgroup.org>2020-04-23 18:41:34 (GMT)
commit5ea58acf8a2bdf8ca19d4c86d9ef94fbc4ac449f (patch)
treeda1ee5cccec97216ffb73edd94815845b379e71f /config/cmake/HDFCompilerFlags.cmake
parent1db039d1beee05d7349e153cef4cf642c907cc1e (diff)
parent43424a1392b662a29542bb70014c253162ccfe48 (diff)
downloadhdf5-5ea58acf8a2bdf8ca19d4c86d9ef94fbc4ac449f.zip
hdf5-5ea58acf8a2bdf8ca19d4c86d9ef94fbc4ac449f.tar.gz
hdf5-5ea58acf8a2bdf8ca19d4c86d9ef94fbc4ac449f.tar.bz2
Merge pull request #2525 in HDFFV/hdf5 from ~LRKNOX/hdf5_lrk:develop to develop
* commit '43424a1392b662a29542bb70014c253162ccfe48': Add missing ')'. Add C++ warnings treated as error for autotools builds. Move macro ADD_H5_CFLAGS to cmake_ext_mod/HDFMacros.cmake and remove duplicate versions. Address PR suggestions and add overlooked GCC compiler version flags. Don't add general warnings flags for unsupported old versions of gcc and g++ (older than gcc/g++ 4.2). Correct gnu-cxxflags to determine warnings flags to be added based on C++ compiler version instead of C compiler version.
Diffstat (limited to 'config/cmake/HDFCompilerFlags.cmake')
-rw-r--r--config/cmake/HDFCompilerFlags.cmake50
1 files changed, 24 insertions, 26 deletions
diff --git a/config/cmake/HDFCompilerFlags.cmake b/config/cmake/HDFCompilerFlags.cmake
index 72141c0..02bc8b1 100644
--- a/config/cmake/HDFCompilerFlags.cmake
+++ b/config/cmake/HDFCompilerFlags.cmake
@@ -12,24 +12,6 @@
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED TRUE)
-macro (ADD_H5_FLAGS h5_flag_var infile)
- file (STRINGS ${infile} TEST_FLAG_STREAM)
- #message (STATUS "TEST_FLAG_STREAM=${TEST_FLAG_STREAM}")
- list (LENGTH TEST_FLAG_STREAM len_flag)
- if (len_flag GREATER 0)
- math (EXPR _FP_LEN "${len_flag} - 1")
- foreach (line RANGE 0 ${_FP_LEN})
- list (GET TEST_FLAG_STREAM ${line} str_flag)
- string (REGEX REPLACE "^#.*" "" str_flag "${str_flag}")
- #message (STATUS "str_flag=${str_flag}")
- if (str_flag)
- list (APPEND ${h5_flag_var} "${str_flag}")
- endif ()
- endforeach ()
- endif ()
- #message (STATUS "h5_flag_var=${${h5_flag_var}}")
-endmacro ()
-
set (CMAKE_C_FLAGS "${CMAKE_C99_STANDARD_COMPILE_OPTION} ${CMAKE_C_FLAGS}")
set (CMAKE_C_FLAGS "${CMAKE_C_SANITIZER_FLAGS} ${CMAKE_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_SANITIZER_FLAGS} ${CMAKE_CXX_FLAGS}")
@@ -111,8 +93,11 @@ if (NOT MSVC)
list (APPEND H5_CFLAGS0 "-Wsign-compare -Wtrigraphs -Wwrite-strings")
endif()
elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU")
- ADD_H5_FLAGS (HDF5_CMAKE_C_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/general")
- ADD_H5_FLAGS (H5_CFLAGS0 "${HDF5_SOURCE_DIR}/config/gnu-warnings/error-general")
+ # Add general CFlags for GCC versions 4.2 and above
+ if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.2)
+ ADD_H5_FLAGS (HDF5_CMAKE_C_FLAGS "${HDF5_SOURCE_DIR}/config/gnu-warnings/general")
+ ADD_H5_FLAGS (H5_CFLAGS0 "${HDF5_SOURCE_DIR}/config/gnu-warnings/error-general")
+ endif ()
# gcc automatically inlines based on the optimization level
# this is just a failsafe
list (APPEND H5_CFLAGS0 "-finline-functions")
@@ -149,15 +134,27 @@ if (NOT MSVC)
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
- # Append warning flags that only gcc 4.3+ knows about
- ADD_H5_FLAGS (H5_CFLAGS1 "${HDF5_SOURCE_DIR}/config/gnu-warnings/4.3")
- #
# 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)
+ if (CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0 AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.2)
ADD_H5_FLAGS (H5_CFLAGS1 "${HDF5_SOURCE_DIR}/config/gnu-warnings/4.2-4.last")
endif ()
+ # Append warning flags for gcc 4.2-4.3
+ if (CMAKE_C_COMPILER_VERSION VERSION_LESS_EQUAL 4.3 AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.2)
+ ADD_H5_FLAGS (H5_CFLAGS1 "${HDF5_SOURCE_DIR}/config/gnu-warnings/4.2-4.3")
+ endif ()
+
+ # Append warning flags for gcc 4.2-4.4
+ if (CMAKE_C_COMPILER_VERSION VERSION_LESS_EQUAL 4.4 AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.2)
+ ADD_H5_FLAGS (H5_CFLAGS1 "${HDF5_SOURCE_DIR}/config/gnu-warnings/4.2-4.4")
+ endif ()
+
+ # Append warning flags that only gcc 4.3+ knows about
+ if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.3)
+ ADD_H5_FLAGS (H5_CFLAGS1 "${HDF5_SOURCE_DIR}/config/gnu-warnings/4.3")
+ endif ()
+
# Append more extra warning flags that only gcc 4.4+ know about
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.4)
ADD_H5_FLAGS (H5_CFLAGS1 "${HDF5_SOURCE_DIR}/config/gnu-warnings/4.4")
@@ -174,7 +171,7 @@ if (NOT MSVC)
endif ()
# Append more extra warning flags that only gcc 4.6 and less know about
- if (CMAKE_C_COMPILER_VERSION VERSION_LESS 4.7)
+ if (CMAKE_C_COMPILER_VERSION VERSION_LESS 4.7 AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.2)
ADD_H5_FLAGS (H5_CFLAGS1 "${HDF5_SOURCE_DIR}/config/gnu-warnings/4.2-4.6")
endif ()
@@ -218,7 +215,7 @@ if (NOT MSVC)
ADD_H5_FLAGS (H5_CFLAGS1 "${HDF5_SOURCE_DIR}/config/gnu-warnings/4.9")
endif ()
- # Append more extra warning flags that only gcc 5.1+ know about
+ # Append more extra warning flags that only gcc 5.x+ know about
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0)
ADD_H5_FLAGS (H5_CFLAGS1 "${HDF5_SOURCE_DIR}/config/gnu-warnings/5")
ADD_H5_FLAGS (H5_CFLAGS1 "${HDF5_SOURCE_DIR}/config/gnu-warnings/error-5")
@@ -242,6 +239,7 @@ if (NOT MSVC)
# Append more extra warning flags that only gcc 8.x+ know about
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 8.0)
ADD_H5_FLAGS (H5_CFLAGS3 "${HDF5_SOURCE_DIR}/config/gnu-warnings/8")
+ ADD_H5_FLAGS (H5_CFLAGS3 "${HDF5_SOURCE_DIR}/config/gnu-warnings/error-8")
if (HDF5_ENABLE_DEV_WARNINGS)
ADD_H5_FLAGS (H5_CFLAGS3 "${HDF5_SOURCE_DIR}/config/gnu-warnings/developer-8")
else ()