Create common build system files for warnings

This commit is contained in:
Allen Byrne
2020-01-17 13:13:36 -06:00
parent 5fadf221ba
commit cf84882b3c
8 changed files with 149 additions and 27 deletions

View File

@@ -141,6 +141,12 @@
./config/pgi-flags
./config/solaris
#warnings files for both autotools and CMake
./config/gnu-warnings-general
./config/gnu-warnings-developer-general
./config/gnu-warnings-no-developer-general
./config/intel-warnings-general
./config/site-specific/BlankForm
./examples/Attributes.txt

View File

@@ -12,6 +12,24 @@
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)
set (${h5_flag_var} "${${h5_flag_var}} ${str_flag}")
endif ()
endforeach ()
endif ()
#message (STATUS "h5_flag_var=${${h5_flag_var}}")
endmacro ()
message (STATUS "Warnings Configuration:")
set (CMAKE_C_FLAGS "${CMAKE_C99_STANDARD_COMPILE_OPTION} ${CMAKE_C_FLAGS}")
#-----------------------------------------------------------------------------
@@ -95,7 +113,9 @@ if (NOT MSVC AND CMAKE_COMPILER_IS_GNUCC)
# 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")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcheck -Wall")
ADD_H5_FLAGS (CMAKE_C_FLAGS_GENERAL "${HDF5_SOURCE_DIR}/config/intel-warnings-general")
message (STATUS "CMAKE_C_FLAGS_GENERAL=${CMAKE_C_FLAGS_GENERAL}")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_GENERAL}")
set (H5_CFLAGS0 "${H5_CFLAGS0} -Wcomment -Wdeprecated -Wmain -Wmissing-declarations -Wmissing-prototypes -Wp64 -Wpointer-arith")
set (H5_CFLAGS0 "${H5_CFLAGS0} -Wreturn-type -Wstrict-prototypes -Wuninitialized")
set (H5_CFLAGS0 "${H5_CFLAGS0} -Wunknown-pragmas -Wunused-function -Wunused-variable")
@@ -106,16 +126,19 @@ if (NOT MSVC AND CMAKE_COMPILER_IS_GNUCC)
set (H5_CFLAGS0 "${H5_CFLAGS0} -Wsign-compare -Wtrigraphs -Wwrite-strings")
endif()
elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic -Wall -Wextra")
set (H5_CFLAGS0 "${H5_CFLAGS0} -Wbad-function-cast -Wno-c++-compat -Wcast-align")
set (H5_CFLAGS0 "${H5_CFLAGS0} -Wcast-qual -Wconversion -Wdeclaration-after-statement -Wdisabled-optimization -Wfloat-equal")
set (H5_CFLAGS0 "${H5_CFLAGS0} -Wformat=2 -Winit-self -Winvalid-pch -Wmissing-declarations -Wmissing-include-dirs")
set (H5_CFLAGS0 "${H5_CFLAGS0} -Wmissing-prototypes -Wnested-externs -Wold-style-definition -Wpacked -Wpointer-arith")
set (H5_CFLAGS0 "${H5_CFLAGS0} -Wredundant-decls -Wshadow -Wstrict-prototypes -Wswitch-default -Wswitch-enum")
set (H5_CFLAGS0 "${H5_CFLAGS0} -Wundef -Wunused-macros -Wunsafe-loop-optimizations -Wwrite-strings")
ADD_H5_FLAGS (CMAKE_C_FLAGS_GENERAL "${HDF5_SOURCE_DIR}/config/gnu-warnings-general")
message (STATUS "CMAKE_C_FLAGS_GENERAL=${CMAKE_C_FLAGS_GENERAL}")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_GENERAL}")
set (H5_CFLAGS0 "${H5_CFLAGS0} -Wbad-function-cast -Wcast-align")
set (H5_CFLAGS0 "${H5_CFLAGS0} -Wdeclaration-after-statement -Wdisabled-optimization")
set (H5_CFLAGS0 "${H5_CFLAGS0} -Wmissing-declarations")
set (H5_CFLAGS0 "${H5_CFLAGS0} -Wmissing-prototypes -Wnested-externs -Wold-style-definition -Wpacked")
set (H5_CFLAGS0 "${H5_CFLAGS0} -Wredundant-decls -Wstrict-prototypes -Wswitch-enum -Wswitch-default")
set (H5_CFLAGS0 "${H5_CFLAGS0} -Wunused-macros -Wunsafe-loop-optimizations")
# gcc automatically inlines based on the optimization level
# this is just a failsafe
set (H5_CFLAGS0 "${H5_CFLAGS0} -finline-functions")
message (STATUS "H5_CFLAGS0=${H5_CFLAGS0}")
endif ()
endif ()
@@ -129,11 +152,13 @@ if (NOT MSVC AND CMAKE_COMPILER_IS_GNUCC)
if (CMAKE_C_COMPILER_ID STREQUAL "Intel")
set (H5_CFLAGS0 "${H5_CFLAGS0} -Winline -Wreorder -Wport -Wstrict-aliasing")
elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU")
set (H5_CFLAGS0 "${H5_CFLAGS0} -Winline -Waggregate-return -Wmissing-format-attribute -Wmissing-noreturn")
ADD_H5_FLAGS (CMAKE_C_FLAGS_DEV_GENERAL "${HDF5_SOURCE_DIR}/config/gnu-warnings-developer-general")
set (H5_CFLAGS0 "${H5_CFLAGS0} ${CMAKE_C_FLAGS_DEV_GENERAL}")
endif ()
else ()
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
set (H5_CFLAGS0 "${H5_CFLAGS0} -Wno-inline -Wno-aggregate-return -Wno-missing-format-attribute -Wno-missing-noreturn")
ADD_H5_FLAGS (CMAKE_C_FLAGS_NO_DEV_GENERAL "${HDF5_SOURCE_DIR}/config/gnu-warnings-no-developer-general")
set (H5_CFLAGS0 "${H5_CFLAGS0} ${CMAKE_C_FLAGS_NO_DEV_GENERAL}")
endif ()
endif ()

View File

@@ -17,6 +17,21 @@
# if the compiler is not GNU; otherwise 'cc_flags_set' is set to 'yes'
#
#
# Prepend `$srcdir/config/gnu-` to the filename suffix(es) given as
# subroutine argument(s), remove comments starting with # and ending
# at EOL, replace spans of whitespace (including newlines) with spaces,
# and re-emit the file(s) thus filtered on the standard output stream.
#
load_gcc_arguments()
{
set -- $(for arg; do
sed 's,#.*$,,' $srcdir/config/gnu-${arg}
done)
IFS=' ' echo "$*"
}
# Get the compiler version in a way that works for gcc
# unless a compiler version is already known
#
@@ -138,7 +153,7 @@ if test "X-gcc" = "X-$cc_vendor"; then
################
# Optimization #
################
if test $cc_vers_major -le 4; then
HIGH_OPT_CFLAGS="-O3"
DEBUG_OPT_CFLAGS=
@@ -171,12 +186,13 @@ if test "X-gcc" = "X-$cc_vendor"; then
# NOTE: Due to the divergence in the C and C++, we're dropping support for
# compiling the C library with a C++ compiler and dropping the -Wc++-compat
# warning.
H5_CFLAGS="$H5_CFLAGS -pedantic -Wall -Wextra -Wbad-function-cast -Wno-c++-compat -Wcast-align"
H5_CFLAGS="$H5_CFLAGS -Wcast-qual -Wconversion -Wdeclaration-after-statement -Wdisabled-optimization -Wfloat-equal"
H5_CFLAGS="$H5_CFLAGS -Wformat=2 -Wno-format-nonliteral -Winit-self -Winvalid-pch -Wmissing-declarations -Wmissing-include-dirs"
H5_CFLAGS="$H5_CFLAGS $(load_gcc_arguments warnings-general)"
H5_CFLAGS="$H5_CFLAGS -Wbad-function-cast -Wcast-align"
H5_CFLAGS="$H5_CFLAGS -Wdeclaration-after-statement -Wdisabled-optimization"
H5_CFLAGS="$H5_CFLAGS -Wmissing-declarations"
H5_CFLAGS="$H5_CFLAGS -Wmissing-prototypes -Wnested-externs -Wold-style-definition -Wpacked"
H5_CFLAGS="$H5_CFLAGS -Wredundant-decls -Wshadow -Wstrict-prototypes -Wswitch-enum -Wswitch-default"
H5_CFLAGS="$H5_CFLAGS -Wundef -Wunused-macros -Wunsafe-loop-optimizations -Wwrite-strings"
H5_CFLAGS="$H5_CFLAGS -Wredundant-decls -Wstrict-prototypes -Wswitch-enum -Wswitch-default"
H5_CFLAGS="$H5_CFLAGS -Wunused-macros -Wunsafe-loop-optimizations"
######################
# Developer warnings #
@@ -184,8 +200,8 @@ if test "X-gcc" = "X-$cc_vendor"; then
# (suggestions from gcc, not code problems)
# NOTE: -Wformat-nonliteral added back in here (from being disabled in H5_CFLAGS)
DEVELOPER_WARNING_CFLAGS="-Winline -Waggregate-return -Wmissing-format-attribute -Wmissing-noreturn -Wformat-nonliteral"
NO_DEVELOPER_WARNING_CFLAGS="-Wno-inline -Wno-aggregate-return -Wno-missing-format-attribute -Wno-missing-noreturn"
NO_DEVELOPER_WARNING_CFLAGS=$(load_gcc_arguments warnings-no-developer-general)
DEVELOPER_WARNING_CFLAGS=$(load_gcc_arguments warnings-developer-general)
#######################
# gcc 4 special cases #
@@ -196,11 +212,11 @@ if test "X-gcc" = "X-$cc_vendor"; then
H5_CFLAGS="$H5_CFLAGS -Wno-long-long"
fi
# -Wvolatile-register-var was later incorporated into -Wall and
# only needs to be specified explicitly for gcc 4.2-4.3
# -Wvolatile-register-var was later incorporated into -Wall and
# only needs to be specified explicitly for gcc 4.2-4.3
if test $cc_vers_major -eq 4 -a $cc_vers_minor -ge 2 -o $cc_vers_major -eq 4 -a $cc_vers_minor -le 3; then
H5_CFLAGS="$H5_CFLAGS -Wvolatile-register-var"
fi
H5_CFLAGS="$H5_CFLAGS -Wvolatile-register-var"
fi
# -Wstrict-aliasing was later incorporated into -Wall and
# only needs to be specified explicitly for gcc 4.5-4.6
@@ -223,10 +239,10 @@ if test "X-gcc" = "X-$cc_vendor"; then
# Version-specific warnings #
#############################
# gcc 4.3
# gcc 4.3
if test $cc_vers_major -ge 5 -o $cc_vers_major -eq 4 -a $cc_vers_minor -ge 3; then
H5_CFLAGS="$H5_CFLAGS -Wlogical-op -Wlarger-than=2560"
fi
H5_CFLAGS="$H5_CFLAGS -Wlogical-op -Wlarger-than=2560"
fi
# gcc 4.4
if test $cc_vers_major -ge 5 -o $cc_vers_major -eq 4 -a $cc_vers_minor -ge 4; then

View File

@@ -0,0 +1,14 @@
# (suggestions from gcc, not code problems)
# NOTE: -Wformat-nonliteral added back in here (from being disabled in
# H5_CFLAGS)
-Waggregate-return
-Wformat-nonliteral
-Winline
-Wmissing-format-attribute
-Wmissing-noreturn
# suggested dev warnings from general section
# -Wdisabled-optimization
# -Wswitch-default
# -Wswitch-enum
# -Wunsafe-loop-optimizations
# -Wunused-macros

View File

@@ -0,0 +1,32 @@
# Note that some of the flags listed here really should be developer
# flags (listed in separate files, gnu-warnings-developer*) 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 from the
# environment variable at configure time.
-Wall
-Wcast-qual
-Wconversion
-Wextra
-Wfloat-equal
-Wformat=2
-Winit-self
-Winvalid-pch
-Wmissing-include-dirs
#
# NOTE: Due to the divergence in the C and C++, we're dropping support for
# compiling the C library with a C++ compiler and dropping the -Wc++-compat
# warning.
#
-Wno-c++-compat
#
# NOTE: Disable the -Wformat-nonliteral from -Wformat=2 here and re-add
# it to the developer flags.
#
-Wno-format-nonliteral
-Wshadow
-Wundef
-Wwrite-strings
-pedantic

View File

@@ -0,0 +1,4 @@
-Wno-aggregate-return
-Wno-inline
-Wno-missing-format-attribute
-Wno-missing-noreturn

View File

@@ -1,4 +1,4 @@
# -*- shell-script -*-
# -*- shell-script -*-
#
# Copyright by The HDF Group.
# Copyright by the Board of Trustees of the University of Illinois.
@@ -17,6 +17,20 @@
# if the compiler is not Intel; otherwise `cc_flags_set' is set to `yes'
#
#
# Prepend `$srcdir/config/intel-` to the filename suffix(es) given as
# subroutine argument(s), remove comments starting with # and ending
# at EOL, replace spans of whitespace (including newlines) with spaces,
# and re-emit the file(s) thus filtered on the standard output stream.
#
load_intel_arguments()
{
set -- $(for arg; do
sed 's,#.*$,,' $srcdir/config/intel-${arg}
done)
IFS=' ' echo "$*"
}
# Get the compiler version in a way that works for icc
# icc unless a compiler version is already known
#
@@ -66,7 +80,8 @@ if test "X-icc" = "X-$cc_vendor"; then
# General
# Default to C99 standard.
H5_CFLAGS="$H5_CFLAGS $arch -std=c99 -Wcheck -Wall"
H5_CFLAGS="$H5_CFLAGS $arch -std=c99"
H5_CFLAGS="$H5_CFLAGS $(load_intel_arguments warnings-general)"
# Production
PROD_CFLAGS=

View File

@@ -0,0 +1,10 @@
# Note that some of the flags listed here really should be developer
# flags (listed in separate files, gnu-warnings-developer*) 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 from the
# environment variable at configure time.
-Wall
-Wcheck