Remove no-inline-max-size and suppress remark
[alexxy/gromacs.git] / cmake / gmxCFlags.cmake
index 52d36d2d7c98a87a5d600958c5ecc743ffbc803a..0ccbc001ff4ea200c0ec184174f85703ce3763f6 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2009,2010,2011,2012,2013, by the GROMACS development team, led by
+# Copyright (c) 2009,2010,2011,2012,2013,2014, by the GROMACS development team, led by
 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
 # and including many others, as listed in the AUTHORS file in the
 # top-level source directory and at http://www.gromacs.org.
 MACRO(GMX_TEST_CFLAG VARIABLE FLAGS CFLAGSVAR)
     IF(NOT DEFINED ${VARIABLE})
         CHECK_C_COMPILER_FLAG("${FLAGS}" ${VARIABLE})
-    ENDIF(NOT DEFINED ${VARIABLE})
+    ENDIF()
     IF (${VARIABLE})
         SET (${CFLAGSVAR} "${FLAGS} ${${CFLAGSVAR}}")
-    ENDIF (${VARIABLE})
+    ENDIF ()
 ENDMACRO(GMX_TEST_CFLAG VARIABLE FLAGS CFLAGSVAR)
 
 # Test C++ flags FLAGS, and set VARIABLE to true if the work. Also add the
@@ -48,12 +48,50 @@ ENDMACRO(GMX_TEST_CFLAG VARIABLE FLAGS CFLAGSVAR)
 MACRO(GMX_TEST_CXXFLAG VARIABLE FLAGS CXXFLAGSVAR)
     IF(NOT DEFINED ${VARIABLE})
         CHECK_CXX_COMPILER_FLAG("${FLAGS}" ${VARIABLE})
-    ENDIF(NOT DEFINED ${VARIABLE})
+    ENDIF()
     IF (${VARIABLE})
         SET (${CXXFLAGSVAR} "${FLAGS} ${${CXXFLAGSVAR}}")
-    ENDIF (${VARIABLE})
+    ENDIF ()
 ENDMACRO(GMX_TEST_CXXFLAG VARIABLE FLAGS CXXFLAGSVAR)
 
+# Set the real CMake variables for compiler flags. This should be a function
+# so we can have proper local variables while avoiding duplicating code.
+function(gmx_set_cmake_compiler_flags)
+    foreach(language C CXX)
+        # Copy the flags for the release build type to the build types
+        # that are modified forms of it. Ideally, the list of build
+        # types that are modifications of the Release build type would
+        # be set up elsewhere and passed to this function, but it is
+        # inconvenient in CMake to pass more than one list, and such a
+        # list is only used here.
+        foreach(build_type RELWITHDEBUGINFO RELWITHASSERT MINSIZEREL)
+            set(GMXC_${language}FLAGS_${build_type} "${GMXC_${language}FLAGS_RELEASE}")
+        endforeach()
+        # Copy the flags that are only used by the real Release build
+        # type. Currently unused, but we plan to use -Wno-array-bounds
+        # in Release to work around gcc-4.8 being a little too vocal
+        # about some perfectly good code, while using RelWithAssert
+        # (ie. without that suppression) in Jenkins.
+        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()
+
+            # Append to the variables for the given build type for
+            # each language, in the parent scope.
+            set(CMAKE_${language}_FLAGS${punctuation}${build_type}
+                "${GMXC_${language}FLAGS${punctuation}${build_type}} ${CMAKE_${language}_FLAGS${punctuation}${build_type}}"
+                PARENT_SCOPE)
+        endforeach()
+    endforeach()
+endfunction()
 
 # This is the actual exported function to be called 
 MACRO(gmx_c_flags)
@@ -68,7 +106,15 @@ MACRO(gmx_c_flags)
             GMX_TEST_CFLAG(CFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CFLAGS)
         endif()
         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" GMXC_CFLAGS)
+        GMX_TEST_CFLAG(CFLAGS_WARN_EXTRA "-Wextra -Wno-missing-field-initializers -Wno-sign-compare -Wpointer-arith" GMXC_CFLAGS)
+        # Since 4.8 on by default. For previous version disabling is a no-op. Only disabling for Release because with assert
+        # the warnings are OK.
+        GMX_TEST_CFLAG(CFLAGS_WARN_REL "-Wno-array-bounds" GMXC_CFLAGS_RELEASE_ONLY)
+        # Since gcc 4.8 strict - false postives with old gmx_fatal. TODO: Remove in master
+        GMX_TEST_CFLAG(CFLAGS_WARN_UNINIT "-Wno-maybe-uninitialized" GMXC_CFLAGS)
+        if(CYGWIN)
+            GMX_TEST_CFLAG(CFLAGS_WARN_SUBSCRIPT "-Wno-char-subscripts" GMXC_CFLAGS)
+        endif()
         # new in gcc 4.5
         GMX_TEST_CFLAG(CFLAGS_EXCESS_PREC "-fexcess-precision=fast" GMXC_CFLAGS_RELEASE)
         GMX_TEST_CFLAG(CFLAGS_COPT "-fomit-frame-pointer -funroll-all-loops"
@@ -83,7 +129,8 @@ MACRO(gmx_c_flags)
         GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wall -Wno-unused-function" 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" GMXC_CXXFLAGS)
+        GMX_TEST_CXXFLAG(CXXFLAGS_WARN_EXTRA "-Wextra -Wno-missing-field-initializers -Wpointer-arith" GMXC_CXXFLAGS)
+        GMX_TEST_CFLAG(CXXFLAGS_WARN_REL "-Wno-array-bounds" GMXC_CXXFLAGS_RELEASE_ONLY)
         # new in gcc 4.5
         GMX_TEST_CXXFLAG(CXXFLAGS_EXCESS_PREC "-fexcess-precision=fast" GMXC_CXXFLAGS_RELEASE)
         GMX_TEST_CXXFLAG(CXXFLAGS_COPT "-fomit-frame-pointer -funroll-all-loops"
@@ -95,27 +142,79 @@ MACRO(gmx_c_flags)
     if (CMAKE_C_COMPILER_ID MATCHES "Intel")
         if (NOT WIN32) 
             if(NOT GMX_OPENMP)
-                GMX_TEST_CFLAG(CFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CFLAGS)
+                if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 13.99.99)
+# 3180: unrecognized OpenMP #pragma
+                    GMX_TEST_CFLAG(CFLAGS_PRAGMA "-wd3180" GMXC_CFLAGS)
+                else()
+# 161: unrecognized #pragma
+                    GMX_TEST_CFLAG(CFLAGS_PRAGMA "-wd161" GMXC_CFLAGS)
+                endif()
             endif()
-            GMX_TEST_CFLAG(CFLAGS_WARN "-Wall" GMXC_CFLAGS)
+# 111: statement is unreachable
+# 177: function ".." was declared but never referenced
+# 181: argument of type ".." is incompatible with format "..", expecting argument of type ".."
+# 193: zero used for undefined preprocessing identifier ".."
+# 271: trailing comma is nonstandard
+# 304: access control not specified ("public" by default)
+# 383: value copied to temporary, reference to temporary used
+# 424: extra ";" ignored
+# 444: destructor for base class ".." is not virtual
+# 522: function ".." redeclared "inline" after being called
+# 593: variable ".." was set but never used
+# 869: parameter ".." was never referenced
+# 981: operands are evaluated in unspecified order
+#1418: external function definition with no prior declaration
+#1419: external declaration in primary source file
+#1572: floating-point equality and inequality comparisons are unreliable
+#1599: declaration hides variable ".."
+#2259: non-pointer conversion from ".." to ".." may lose significant bits
+#2415: variable ".." of static storage duration was declared but never referenced
+#2547: ".." was specified as both a system and non-system include directory
+#2557: comparison between signed and unsigned operands
+#3280: declaration hides member ".."
+#3346: dynamic exception specifications are deprecated
+#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 -wd111 -wd177 -wd181 -wd193 -wd271 -wd304 -wd383 -wd424 -wd444 -wd522 -wd593 -wd869 -wd981 -wd1418 -wd1419 -wd1572 -wd1599 -wd2259 -wd2415 -wd2547 -wd2557 -wd3280 -wd3346 -wd11074 -wd11076" GMXC_CFLAGS)
             GMX_TEST_CFLAG(CFLAGS_STDGNU "-std=gnu99" GMXC_CFLAGS)
-            GMX_TEST_CFLAG(CFLAGS_OPT "-ip -funroll-all-loops" GMXC_CFLAGS_RELEASE)
+            GMX_TEST_CFLAG(CFLAGS_OPT "-ip -funroll-all-loops -alias-const -ansi-alias" GMXC_CFLAGS_RELEASE)
         else()
-            GMX_TEST_CFLAG(CFLAGS_WARN "/W2" GMXC_CFLAGS)
-            GMX_TEST_CFLAG(CFLAGS_X86 "/Qip" GMXC_CFLAGS_RELEASE)
+            if(NOT GMX_OPENMP)
+                if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 13.99.99)
+                    GMX_TEST_CFLAG(CFLAGS_PRAGMA "/wd3180" GMXC_CFLAGS)
+                else()
+                    GMX_TEST_CFLAG(CFLAGS_PRAGMA "/wd161" GMXC_CFLAGS)
+                endif()
+            endif()
+            GMX_TEST_CFLAG(CFLAGS_WARN "/W3 /wd111 /wd177 /wd181 /wd193 /wd271 /wd304 /wd383 /wd424 /wd444 /wd522 /wd593 /wd869 /wd981 /wd1418 /wd1419 /wd1572 /wd1599 /wd2259 /wd2415 /wd2547 /wd2557 /wd3280 /wd3346" GMXC_CFLAGS)
+            GMX_TEST_CFLAG(CFLAGS_OPT "/Qip" GMXC_CFLAGS_RELEASE)
         endif()
     endif()
 
     if (CMAKE_CXX_COMPILER_ID MATCHES "Intel")
         if (NOT WIN32) 
             if(NOT GMX_OPENMP)
-                GMX_TEST_CXXFLAG(CXXFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CXXFLAGS)
+                if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 13.99.99)
+                    GMX_TEST_CXXFLAG(CXXFLAGS_PRAGMA "-wd3180" GMXC_CXXFLAGS)
+                else()
+                    GMX_TEST_CXXFLAG(CXXFLAGS_PRAGMA "-wd161" GMXC_CXXFLAGS)
+                endif()
             endif()
-            GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wall" GMXC_CXXFLAGS)
-            GMX_TEST_CXXFLAG(CXXFLAGS_OPT "-ip -funroll-all-loops" GMXC_CXXFLAGS_RELEASE)
+#All but the following warnings are identical for the C-compiler (see above)
+#1782: #pragma once is obsolete
+#2282: unrecognized GCC pragma
+            GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-w3 -wd111 -wd177 -wd181 -wd193 -wd271 -wd304 -wd383 -wd424 -wd444 -wd522 -wd593 -wd869 -wd981 -wd1418 -wd1419 -wd1572 -wd1599 -wd2259 -wd2415 -wd2547 -wd2557 -wd3280 -wd3346 -wd11074 -wd11076 -wd1782 -wd2282" GMXC_CXXFLAGS)
+            GMX_TEST_CXXFLAG(CXXFLAGS_OPT "-ip -funroll-all-loops -alias-const -ansi-alias" GMXC_CXXFLAGS_RELEASE)
         else()
-            GMX_TEST_CXXFLAG(CXXFLAGS_WARN "/W2" GMXC_CXXFLAGS)
-            GMX_TEST_CXXFLAG(CXXFLAGS_X86 "/Qip" GMXC_CXXFLAGS_RELEASE)
+            if(NOT GMX_OPENMP)
+                if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 13.99.99)
+                    GMX_TEST_CXXFLAG(CXXFLAGS_PRAGMA "/wd3180" GMXC_CFLAGS)
+                else()
+                    GMX_TEST_CXXFLAG(CXXFLAGS_PRAGMA "/wd161" GMXC_CXXFLAGS)
+                endif()
+            endif()
+            GMX_TEST_CXXFLAG(CXXFLAGS_WARN "/W3 /wd111 /wd177 /wd181 /wd193 /wd271 /wd304 /wd383 /wd424 /wd444 /wd522 /wd593 /wd869 /wd981 /wd1418 /wd1419 /wd1572 /wd1599 /wd2259 /wd2415 /wd2547 /wd2557 /wd3280 /wd3346 /wd1782 /wd2282" GMXC_CXXFLAGS)
+            GMX_TEST_CXXFLAG(CXXFLAGS_OPT "/Qip" GMXC_CXXFLAGS_RELEASE)
         endif()
     endif()
 
@@ -147,12 +246,18 @@ MACRO(gmx_c_flags)
     endif()
 
     # xlc
+    # The suppressions below stop information messages about -O3
+    # causing non-strict IEEE compliance that changes the semantics of
+    # the program (duh; 1500-036), warnings about correct PBC-related use of
+    # maximum array indices of DIM-sized C arrays (1500-010).
     if (CMAKE_C_COMPILER_ID MATCHES "XL")
         GMX_TEST_CFLAG(CFLAGS_OPT "-qarch=auto -qtune=auto" GMXC_CFLAGS)
         GMX_TEST_CFLAG(CFLAGS_LANG "-qlanglvl=extc99" GMXC_CFLAGS)
+        GMX_TEST_CFLAG(CFLAGS_LANG "-qsuppress=1500-036 -qsuppress=1500-010" GMXC_CFLAGS)
     endif()
     if (CMAKE_CXX_COMPILER_ID MATCHES "XL")
         GMX_TEST_CXXFLAG(CXXFLAGS_OPT "-qarch=auto -qtune=auto" GMXC_CXXFLAGS)
+        GMX_TEST_CXXFLAG(CFLAGS_LANG "-qsuppress=1500-036 -qsuppress=1500-010" GMXC_CXXFLAGS)
     endif()
 
     # msvc
@@ -161,8 +266,17 @@ MACRO(gmx_c_flags)
         #      forcing value to bool
         #      "this" in initializer list
         #      deprecated (posix, secure) functions
-        GMX_TEST_CFLAG(CFLAGS_WARN "/wd4800 /wd4355 /wd4996" GMXC_CFLAGS)
-        GMX_TEST_CXXFLAG(CXXFLAGS_WARN "/wd4800 /wd4355 /wd4996" GMXC_CXXFLAGS)
+        #      truncation (double -> float)
+        #      conversion from 'double' to 'real', possible loss of data
+        #      unreferenced local variable (only C)
+        #      conversion from 'size_t' to 'int', possible loss of data
+        #      conversion from 'const char*' to 'void*', different 'const' qualifiers (only C)
+        if(NOT CMAKE_CONFIGURATION_TYPES)
+            GMX_TEST_CFLAG(CFLAGS_WARN "/wd4800 /wd4355 /wd4996 /wd4305 /wd4244 /wd4101 /wd4267 /wd4090" GMXC_CFLAGS)
+            GMX_TEST_CXXFLAG(CXXFLAGS_WARN "/wd4800 /wd4355 /wd4996 /wd4305 /wd4244 /wd4267" GMXC_CXXFLAGS)
+        else() #Projects only use the C++ flags
+            GMX_TEST_CXXFLAG(CXXFLAGS_WARN "/wd4800 /wd4355 /wd4996 /wd4305 /wd4244 /wd4101 /wd4267 /wd4090" GMXC_CXXFLAGS)
+        endif()
     endif()
 
     if (CMAKE_C_COMPILER_ID MATCHES "Clang")
@@ -170,6 +284,7 @@ MACRO(gmx_c_flags)
             GMX_TEST_CFLAG(CFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CFLAGS)
         endif()
         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()
 
     if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
@@ -177,24 +292,25 @@ MACRO(gmx_c_flags)
             GMX_TEST_CXXFLAG(CXXFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CXXFLAGS)
         endif()
         GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wall -Wno-unused-function" GMXC_CXXFLAGS)
-        GMX_TEST_CXXFLAG(CXXFLAGS_WARN_EXTRA "-Wextra -Wno-missing-field-initializers" GMXC_CXXFLAGS)
+        GMX_TEST_CXXFLAG(CXXFLAGS_WARN_EXTRA "-Wextra -Wno-missing-field-initializers -Wpointer-arith" GMXC_CXXFLAGS)
+    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)
+    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)
     endif()
 
     # now actually set the flags:
-    # C
-    if ( NOT GMX_SKIP_DEFAULT_CFLAGS )
-        set(CMAKE_C_FLAGS "${GMXC_CFLAGS} ${CMAKE_C_FLAGS}")
-        set(CMAKE_C_FLAGS_RELEASE "${GMXC_CFLAGS_RELEASE} ${CMAKE_C_FLAGS_RELEASE}")
-        set(CMAKE_C_FLAGS_DEBUG "${GMXC_CFLAGS_DEBUG} ${CMAKE_C_FLAGS_DEBUG}")
-    endif()
-
-    # C++
-    if ( NOT GMX_SKIP_DEFAULT_CFLAGS)
-        set(CMAKE_CXX_FLAGS "${GMXC_CXXFLAGS} ${CMAKE_CXX_FLAGS}")
-        set(CMAKE_CXX_FLAGS_RELEASE 
-            "${GMXC_CXXFLAGS_RELEASE} ${CMAKE_CXX_FLAGS_RELEASE}")
-        set(CMAKE_CXX_FLAGS_DEBUG 
-            "${GMXC_CXXFLAGS_DEBUG} ${CMAKE_CXX_FLAGS_DEBUG}")
+    if (NOT GMX_SKIP_DEFAULT_CFLAGS)
+        gmx_set_cmake_compiler_flags()
     endif()
 ENDMACRO(gmx_c_flags)