CHECK_C_COMPILER_FLAG("${FLAGS}" ${VARIABLE})
ENDIF()
IF (${VARIABLE})
- SET (${CFLAGSVAR} "${FLAGS} ${${CFLAGSVAR}}")
+ list(APPEND ${CFLAGSVAR} "${FLAGS}")
ENDIF ()
ENDMACRO(GMX_TEST_CFLAG VARIABLE FLAGS CFLAGSVAR)
CHECK_CXX_COMPILER_FLAG("${FLAGS}" ${VARIABLE})
ENDIF()
IF (${VARIABLE})
- SET (${CXXFLAGSVAR} "${FLAGS} ${${CXXFLAGSVAR}}")
+ list(APPEND ${CXXFLAGSVAR} "${FLAGS}")
ENDIF ()
ENDMACRO(GMX_TEST_CXXFLAG VARIABLE FLAGS CXXFLAGSVAR)
# inconvenient in CMake to pass more than one list, and such a
# list is only used here.
foreach(build_type RELWITHDEBINFO RELWITHASSERT MINSIZEREL PROFILE)
- set(GMXC_${language}FLAGS_${build_type} "${GMXC_${language}FLAGS_RELEASE} ${GMXC_${language}FLAGS_${build_type}}")
+ set(GMXC_${language}FLAGS_${build_type} "${GMXC_${language}FLAGS_RELEASE}" "${GMXC_${language}FLAGS_${build_type}}")
endforeach()
# Copy the flags that are only used by the real Release build
# type. Used for, e.g., -Wno-array-bounds in Release to work around
# while using RelWithAssert (ie. without that suppression) in Jenkins.
#
# TODO check the behaviour of more recent gcc on the improved code
- set(GMXC_${language}FLAGS_RELEASE "${GMXC_${language}FLAGS_RELEASE} ${GMXC_${language}FLAGS_RELEASE_ONLY}")
-
- # Modify the real CMake variables for compiler flags for all
- # builds and language types, and also those common to all
- # build types.
- foreach(build_type "" ${build_types_with_explicit_flags})
- if("${build_type}" STREQUAL "")
- set(punctuation "") # for general compiler flags (e.g.) CMAKE_CXX_FLAGS
- else()
- set(punctuation "_") # for build-type-specific compiler flags (e.g.) CMAKE_CXX_FLAGS_RELEASE
- endif()
+ set(GMXC_${language}FLAGS_RELEASE "${GMXC_${language}FLAGS_RELEASE}" "${GMXC_${language}FLAGS_RELEASE_ONLY}")
+ endforeach()
+endfunction()
- # Append to the variables for the given build type for
- # each language, in the parent scope. We add our new variables at the end, so
- # compiler-specific choices are more likely to override default CMake choices.
- # This is for instance useful for RelWithDebInfo builds, where we want to use the full
- # set of our optimization flags detected in this file, rather than having -O2 override them.
- set(CMAKE_${language}_FLAGS${punctuation}${build_type}
- "${CMAKE_${language}_FLAGS${punctuation}${build_type}} ${GMXC_${language}FLAGS${punctuation}${build_type}}"
- PARENT_SCOPE)
+# Add compiler flags expected for all GROMACS build configurations,
+# and those expected for the current CMake build type (e.g. Release)
+# to TARGET.
+#
+# Most targets (ie. libraries, executables) need compiler flags that
+# are characteristic of the build configuration. This function
+# provides a central point for adding such flags. This approach is
+# more flexible than e.g. setting CMAKE_CXX_FLAGS globally, because
+# that setting will apply globally, which means it applies also to
+# "external" code that the build of GROMACS might also build.
+function(gmx_target_compile_options TARGET)
+ if (NOT GMX_SKIP_DEFAULT_CFLAGS)
+ target_compile_options(${TARGET}
+ PRIVATE
+ $<$<COMPILE_LANGUAGE:C>:${SIMD_C_FLAGS};${MPI_COMPILE_FLAGS};${EXTRA_C_FLAGS};${GMXC_CFLAGS}>
+ $<$<COMPILE_LANGUAGE:CXX>:${SIMD_CXX_FLAGS};${MPI_COMPILE_FLAGS};${EXTRA_CXX_FLAGS};${GMXC_CXXFLAGS}>
+ )
+ foreach(build_type ${build_types_with_explicit_flags})
+ target_compile_options(${TARGET}
+ BEFORE PRIVATE
+ $<$<AND:$<COMPILE_LANGUAGE:C>,$<CONFIG:${build_type}>>:${GMXC_CFLAGS_${build_type}}>
+ $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CONFIG:${build_type}>>:${GMXC_CXXFLAGS_${build_type}}>
+ )
endforeach()
- endforeach()
+ endif()
endfunction()
+# Add the WARNING_FLAG to the compile options for TARGET if the
+# compiler supports that flag. VARNAME is used to cache the result of
+# the check whether the compiler supports that flag, as multiple
+# targets may use the same suppression.
+#
+# This is generally used to suppress warnings judged not worth fixing
+# in code external to, or generated by, GROMACS.
function(gmx_target_warning_suppression TARGET WARNING_FLAG VARNAME)
check_cxx_compiler_flag(${WARNING_FLAG} ${VARNAME})
if(${VARNAME})
GMX_TEST_CFLAG(CFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CFLAGS)
endif()
if (GMX_COMPILER_WARNINGS)
- GMX_TEST_CFLAG(CFLAGS_WARN "-Wall -Wno-unused -Wunused-value -Wunused-parameter" GMXC_CFLAGS)
- GMX_TEST_CFLAG(CFLAGS_WARN_EXTRA "-Wextra -Wno-missing-field-initializers -Wno-sign-compare -Wpointer-arith" GMXC_CFLAGS)
+ GMX_TEST_CFLAG(CFLAGS_WARN "-Wall;-Wno-unused;-Wunused-value;-Wunused-parameter" GMXC_CFLAGS)
+ GMX_TEST_CFLAG(CFLAGS_WARN_EXTRA "-Wextra;-Wno-missing-field-initializers;-Wno-sign-compare;-Wpointer-arith" GMXC_CFLAGS)
GMX_TEST_CFLAG(CFLAGS_WARN_UNDEF "-Wundef" GMXC_CFLAGS)
GMX_TEST_CFLAG(CFLAGS_WARN_REL "-Wno-array-bounds" GMXC_CFLAGS_RELEASE_ONLY)
if(CYGWIN)
GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wall" GMXC_CXXFLAGS)
# Problematic with CUDA
# GMX_TEST_CXXFLAG(CXXFLAGS_WARN_EFFCXX "-Wnon-virtual-dtor" GMXC_CXXFLAGS)
- GMX_TEST_CXXFLAG(CXXFLAGS_WARN_EXTRA "-Wextra -Wno-missing-field-initializers -Wpointer-arith -Wmissing-declarations" GMXC_CXXFLAGS)
+ GMX_TEST_CXXFLAG(CXXFLAGS_WARN_EXTRA "-Wextra;-Wno-missing-field-initializers;-Wpointer-arith;-Wmissing-declarations" GMXC_CXXFLAGS)
# CUDA versions prior to 7.5 come with a header (math_functions.h) which uses the _MSC_VER macro
# unconditionally, so we don't use -Wundef for earlier CUDA versions.
if(NOT(GMX_GPU AND CUDA_VERSION VERSION_LESS "7.5"))
#3280: declaration hides member ".."
#11074: Inlining inhibited by limit max-size(/max-total-size)
#11076: To get full report use -opt-report=3 -opt-report-phase ipo (shown for previous remark)
- GMX_TEST_CFLAG(CFLAGS_WARN "-w3 -wd177 -wd411 -wd593 -wd981 -wd1418 -wd1419 -wd1572 -wd1599 -wd2259 -wd2415 -wd2547 -wd2557 -wd3280 -wd11074 -wd11076" GMXC_CFLAGS)
+ GMX_TEST_CFLAG(CFLAGS_WARN "-w3;-wd177;-wd411;-wd593;-wd981;-wd1418;-wd1419;-wd1572;-wd1599;-wd2259;-wd2415;-wd2547;-wd2557;-wd3280;-wd11074;-wd11076" GMXC_CFLAGS)
endif()
GMX_TEST_CFLAG(CFLAGS_STDGNU "-std=gnu99" GMXC_CFLAGS)
- GMX_TEST_CFLAG(CFLAGS_OPT "-ip -funroll-all-loops -alias-const -ansi-alias -no-prec-div -fimf-domain-exclusion=14 -qoverride-limits" GMXC_CFLAGS_RELEASE)
+ GMX_TEST_CFLAG(CFLAGS_OPT "-ip;-funroll-all-loops;-alias-const;-ansi-alias;-no-prec-div;-fimf-domain-exclusion=14;-qoverride-limits" GMXC_CFLAGS_RELEASE)
GMX_TEST_CFLAG(CFLAGS_DEBUG "-O0" GMXC_CFLAGS_DEBUG) #icc defaults to -O2 even with -g
- GMX_TEST_CFLAG(CFLAGS_FP_RELASSERT "-fp-model except -fp-model precise" GMXC_CFLAGS_RELWITHASSERT)
+ # The "except" fp-model requires something other than the
+ # default "fast" model, so we test and use it with
+ # "precise".
+ GMX_TEST_CFLAG(CFLAGS_FP_MODEL_RELASSERT "-fp-model=except;-fp-model=precise" GMXC_CFLAGS_RELWITHASSERT)
else()
if(NOT GMX_OPENMP)
GMX_TEST_CFLAG(CFLAGS_PRAGMA "/wd3180" GMXC_CFLAGS)
#only on Windows
#161: unrecognized pragma
#1786 function was declared deprecated (is issued for stdlib function such as strncpy which have a _s version)
-GMX_TEST_CFLAG(CFLAGS_WARN "/W3 /wd161 /wd177 /wd411 /wd593 /wd981 /wd1418 /wd1419 /wd1572 /wd1599 /wd1786 /wd2259 /wd2415 /wd2547 /wd2557 /wd3280" GMXC_CFLAGS)
+GMX_TEST_CFLAG(CFLAGS_WARN "/W3;/wd161;/wd177;/wd411;/wd593;/wd981;/wd1418;/wd1419;/wd1572;/wd1599;/wd1786;/wd2259;/wd2415;/wd2547;/wd2557;/wd3280" GMXC_CFLAGS)
endif()
GMX_TEST_CFLAG(CFLAGS_OPT "/Qip" GMXC_CFLAGS_RELEASE)
endif()
# 444: destructor for base class ".." is not virtual
# 869: was never referenced (false positives)
#2282: unrecognized GCC pragma
- GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-w3 -wd177 -wd304 -wd383 -wd411 -wd444 -wd869 -wd981 -wd1418 -wd1572 -wd1599 -wd2259 -wd2547 -wd3280 -wd11074 -wd11076 -wd2282" GMXC_CXXFLAGS)
+ GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-w3;-wd177;-wd304;-wd383;-wd411;-wd444;-wd869;-wd981;-wd1418;-wd1572;-wd1599;-wd2259;-wd2547;-wd3280;-wd11074;-wd11076;-wd2282" GMXC_CXXFLAGS)
endif()
- GMX_TEST_CXXFLAG(CXXFLAGS_OPT "-ip -funroll-all-loops -alias-const -ansi-alias -no-prec-div -fimf-domain-exclusion=14 -qoverride-limits" GMXC_CXXFLAGS_RELEASE)
+ GMX_TEST_CXXFLAG(CXXFLAGS_OPT "-ip;-funroll-all-loops;-alias-const;-ansi-alias;-no-prec-div;-fimf-domain-exclusion=14;-qoverride-limits" GMXC_CXXFLAGS_RELEASE)
GMX_TEST_CXXFLAG(CXXFLAGS_DEBUG "-O0" GMXC_CXXFLAGS_DEBUG)
- GMX_TEST_CXXFLAG(CXXFLAGS_FP_RELASSERT "-fp-model except -fp-model precise" GMXC_CXXFLAGS_RELWITHASSERT)
+ # The "except" fp-model requires something other than the
+ # default "fast" model, so we test and use it with
+ # "precise".
+ GMX_TEST_CXXFLAG(CXXFLAGS_FP_MODEL_RELASSERT "-fp-model=except;-fp-model=precise" GMXC_CXXFLAGS_RELWITHASSERT)
else()
if(NOT GMX_OPENMP)
GMX_TEST_CXXFLAG(CXXFLAGS_PRAGMA "/wd3180" GMXC_CFLAGS)
if (GMX_COMPILER_WARNINGS)
#161: unrecognized pragma
#809: exception specification for virtual function X is incompatible with that of overridden function
- GMX_TEST_CXXFLAG(CXXFLAGS_WARN "/W3 /wd161 /wd177 /wd304 /wd383 /wd411 /wd444 /wd809 /wd869 /wd981 /wd1418 /wd1572 /wd1599 /wd1786 /wd2259 /wd2547 /wd3280 /wd11074 /wd11076 /wd2282" GMXC_CXXFLAGS)
+ GMX_TEST_CXXFLAG(CXXFLAGS_WARN "/W3;/wd161;/wd177;/wd304;/wd383;/wd411;/wd444;/wd809;/wd869;/wd981;/wd1418;/wd1572;/wd1599;/wd1786;/wd2259;/wd2547;/wd3280;/wd11074;/wd11076;/wd2282" GMXC_CXXFLAGS)
endif()
GMX_TEST_CXXFLAG(CXXFLAGS_OPT "/Qip" GMXC_CXXFLAGS_RELEASE)
endif()
GMX_TEST_CFLAG(CFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CFLAGS)
endif()
if (GMX_COMPILER_WARNINGS)
- GMX_TEST_CFLAG(CFLAGS_WARN "-Wall -Wno-unused -Wunused-value" GMXC_CFLAGS)
+ GMX_TEST_CFLAG(CFLAGS_WARN "-Wall;-Wno-unused;-Wunused-value" GMXC_CFLAGS)
endif()
- GMX_TEST_CFLAG(CFLAGS_OPT "-OPT:Ofast -fno-math-errno -ffast-math"
+ GMX_TEST_CFLAG(CFLAGS_OPT "-OPT:Ofast;-fno-math-errno;-ffast-math"
GMXC_CFLAGS_RELEASE)
GMX_TEST_CFLAG(CFLAGS_LANG "-std=gnu99" GMXC_CFLAGS)
endif()
GMX_TEST_CXXFLAG(CXXFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CXXFLAGS)
endif()
if (GMX_COMPILER_WARNINGS)
- GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wall -Wno-unused -Wunused-value" GMXC_CXXFLAGS)
+ GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wall;-Wno-unused;-Wunused-value" GMXC_CXXFLAGS)
endif()
- GMX_TEST_CXXFLAG(CXXFLAGS_OPT "-OPT:Ofast -fno-math-errno -ffast-math"
+ GMX_TEST_CXXFLAG(CXXFLAGS_OPT "-OPT:Ofast;-fno-math-errno;-ffast-math"
GMXC_CXXFLAGS_RELEASE)
endif()
# 1500-010: (W) about correct PBC-related use of maximum array indices of DIM-sized C arrays
# 1500-030: (I) Additional optimization may be attained by recompiling and specifying MAXMEM option with a value greater than 8192.
if (CMAKE_C_COMPILER_ID MATCHES "XL")
- GMX_TEST_CFLAG(CFLAGS_ARCH "-qarch=auto -qtune=auto" GMXC_CFLAGS)
+ GMX_TEST_CFLAG(CFLAGS_ARCH "-qarch=auto;-qtune=auto" GMXC_CFLAGS)
GMX_TEST_CFLAG(CFLAGS_OPT "-O3" GMXC_CFLAGS_RELEASE)
GMX_TEST_CFLAG(CFLAGS_LANG "-qlanglvl=extc99" GMXC_CFLAGS)
- GMX_TEST_CFLAG(CFLAGS_LANG "-qsuppress=1500-036 -qsuppress=1500-010 -qsuppress=1500-030" GMXC_CFLAGS)
+ GMX_TEST_CFLAG(CFLAGS_LANG "-qsuppress=1500-036;-qsuppress=1500-010;-qsuppress=1500-030" GMXC_CFLAGS)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "XL")
- GMX_TEST_CXXFLAG(CXXFLAGS_ARCH "-qarch=auto -qtune=auto" GMXC_CXXFLAGS)
+ GMX_TEST_CXXFLAG(CXXFLAGS_ARCH "-qarch=auto;-qtune=auto" GMXC_CXXFLAGS)
GMX_TEST_CXXFLAG(CXXFLAGS_OPT "-O3" GMXC_CXXFLAGS_RELEASE)
- GMX_TEST_CXXFLAG(CXXFLAGS_LANG "-qsuppress=1500-036 -qsuppress=1500-010 -qsuppress=1500-030" GMXC_CXXFLAGS)
+ GMX_TEST_CXXFLAG(CXXFLAGS_LANG "-qsuppress=1500-036;-qsuppress=1500-010;-qsuppress=1500-030" GMXC_CXXFLAGS)
endif()
# msvc
# forcing value to bool
# "this" in initializer list
# deprecated (posix, secure) functions
- # truncation (double -> float)
- # conversion from 'double' to 'real', possible loss of data
+ # C4305: truncation (double -> float)
+ # C4244: conversion from 'double' to 'real', possible loss of data
# unreferenced local variable (only C)
- # conversion from 'size_t' to 'int', possible loss of data
+ # C4267: conversion from 'size_t' to 'int', possible loss of data
# conversion from 'const char*' to 'void*', different 'const' qualifiers (only C)
# unknown pragma (4068)
if(NOT CMAKE_CONFIGURATION_TYPES)
- GMX_TEST_CFLAG(CFLAGS_WARN "/wd4800 /wd4355 /wd4996 /wd4305 /wd4244 /wd4101 /wd4267 /wd4090 /wd4068" GMXC_CFLAGS)
- GMX_TEST_CXXFLAG(CXXFLAGS_WARN "/wd4800 /wd4355 /wd4996 /wd4305 /wd4244 /wd4267 /wd4068" GMXC_CXXFLAGS)
+ GMX_TEST_CFLAG(CFLAGS_WARN "/wd4800;/wd4355;/wd4996;/wd4305;/wd4244;/wd4101;/wd4267;/wd4090;/wd4068" GMXC_CFLAGS)
+ GMX_TEST_CXXFLAG(CXXFLAGS_WARN "/wd4800;/wd4355;/wd4996;/wd4305;/wd4244;/wd4267;/wd4068" GMXC_CXXFLAGS)
else() # MSVC projects only use the C++ flags
- GMX_TEST_CXXFLAG(CXXFLAGS_WARN "/wd4800 /wd4355 /wd4996 /wd4305 /wd4244 /wd4101 /wd4267 /wd4090 /wd4068" GMXC_CXXFLAGS)
+ GMX_TEST_CXXFLAG(CXXFLAGS_WARN "/wd4800;/wd4355;/wd4996;/wd4305;/wd4244;/wd4101;/wd4267;/wd4090;/wd4068" GMXC_CXXFLAGS)
endif()
endif()
GMX_TEST_CFLAG(CFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CFLAGS)
endif()
if (GMX_COMPILER_WARNINGS)
- GMX_TEST_CFLAG(CFLAGS_WARN "-Wall -Wno-unused -Wunused-value -Wunused-parameter" GMXC_CFLAGS)
+ GMX_TEST_CFLAG(CFLAGS_WARN "-Wall;-Wno-unused;-Wunused-value;-Wunused-parameter" GMXC_CFLAGS)
GMX_TEST_CFLAG(CFLAGS_WARN_EXTRA "-Wpointer-arith" GMXC_CFLAGS_EXTRA)
endif()
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
- if(NOT GMX_OPENMP)
- GMX_TEST_CXXFLAG(CXXFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CXXFLAGS)
- endif()
if (GMX_COMPILER_WARNINGS)
+ # If used, -Wall should precede other options that silence warnings it enables
+ GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wall" GMXC_CXXFLAGS)
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0") #LLVM BUG #21629
GMX_TEST_CXXFLAG(CXXFLAGS_WARN_NO_BRACES "-Wno-missing-braces" GMXC_CXXFLAGS)
endif()
- GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wall" GMXC_CXXFLAGS)
- GMX_TEST_CXXFLAG(CXXFLAGS_WARN_EXTRA "-Wextra -Wno-missing-field-initializers -Wpointer-arith -Wmissing-prototypes" GMXC_CXXFLAGS)
+ GMX_TEST_CXXFLAG(CXXFLAGS_WARN_EXTRA "-Wextra;-Wno-missing-field-initializers;-Wpointer-arith;-Wmissing-prototypes" GMXC_CXXFLAGS)
GMX_TEST_CXXFLAG(CXXFLAGS_DEPRECATED "-Wdeprecated" GMXC_CXXFLAGS)
endif()
+ if(NOT GMX_OPENMP)
+ GMX_TEST_CXXFLAG(CXXFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CXXFLAGS)
+ endif()
endif()
# Fujitsu compilers on PrimeHPC/Sparc64
if(${CMAKE_C_COMPILER_ID} MATCHES Fujitsu OR
(${CMAKE_C_COMPILER_ID} MATCHES unknown AND ${CMAKE_C_COMPILER} MATCHES ^fcc))
- GMX_TEST_CFLAG(CFLAG_GNUCOMPAT "-Xg -w" GMXC_CFLAGS)
- GMX_TEST_CFLAG(CFLAG_OPT "-Kfast,reduction,swp,simd=2,uxsimd,fsimple -x100" GMXC_CFLAGS)
+ GMX_TEST_CFLAG(CFLAG_GNUCOMPAT "-Xg;-w" GMXC_CFLAGS)
+ GMX_TEST_CFLAG(CFLAG_OPT "-Kfast,reduction,swp,simd=2,uxsimd,fsimple;-x100" GMXC_CFLAGS)
endif()
if(${CMAKE_CXX_COMPILER_ID} MATCHES Fujitsu OR
(${CMAKE_CXX_COMPILER_ID} MATCHES unknown AND ${CMAKE_CXX_COMPILER} MATCHES ^FCC))
- GMX_TEST_CXXFLAG(CXXFLAG_GNUCOMPAT "-Xg -w" GMXC_CXXFLAGS)
- GMX_TEST_CXXFLAG(CXXFLAG_OPT "-Kfast,reduction,swp,simd=2,uxsimd,fsimple -x100" GMXC_CXXFLAGS)
+ GMX_TEST_CXXFLAG(CXXFLAG_GNUCOMPAT "-Xg;-w" GMXC_CXXFLAGS)
+ GMX_TEST_CXXFLAG(CXXFLAG_OPT "-Kfast,reduction,swp,simd=2,uxsimd,fsimple;-x100" GMXC_CXXFLAGS)
endif()
# now actually set the flags: