Move pmePpCommGpu reset outside do_md
[alexxy/gromacs.git] / cmake / gmxCFlags.cmake
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
5 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 # and including many others, as listed in the AUTHORS file in the
7 # top-level source directory and at http://www.gromacs.org.
8 #
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
13 #
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # Lesser General Public License for more details.
18 #
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23 #
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
31 #
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
34
35 # Test C flags FLAGS, and set VARIABLE to true if the work. Also add the
36 # flags to CFLAGSVAR.
37 MACRO(GMX_TEST_CFLAG VARIABLE FLAGS CFLAGSVAR)
38     IF(NOT DEFINED ${VARIABLE})
39         CHECK_C_COMPILER_FLAG("${FLAGS}" ${VARIABLE})
40     ENDIF()
41     IF (${VARIABLE})
42         list(APPEND ${CFLAGSVAR} "${FLAGS}")
43     ENDIF ()
44 ENDMACRO(GMX_TEST_CFLAG VARIABLE FLAGS CFLAGSVAR)
45
46 # Test C++ flags FLAGS, and set VARIABLE to true if the work. Also add the
47 # flags to CXXFLAGSVAR.
48 MACRO(GMX_TEST_CXXFLAG VARIABLE FLAGS CXXFLAGSVAR)
49     IF(NOT DEFINED ${VARIABLE})
50         CHECK_CXX_COMPILER_FLAG("${FLAGS}" ${VARIABLE})
51     ENDIF()
52     IF (${VARIABLE})
53         list(APPEND ${CXXFLAGSVAR} "${FLAGS}")
54     ENDIF ()
55 ENDMACRO(GMX_TEST_CXXFLAG VARIABLE FLAGS CXXFLAGSVAR)
56
57 # Prepare some local variables so CUDA and non-CUDA code in targets
58 # works the same way.
59 function(gmx_target_compile_options_inner)
60     set (CFLAGS "${SIMD_C_FLAGS};${MPI_COMPILE_FLAGS};${EXTRA_C_FLAGS};${GMXC_CFLAGS}" PARENT_SCOPE)
61     set (CXXFLAGS "${SIMD_CXX_FLAGS};${MPI_COMPILE_FLAGS};${EXTRA_CXX_FLAGS};${GMXC_CXXFLAGS}" PARENT_SCOPE)
62 endfunction()
63
64 # Implementation function to add compiler flags expected for all
65 # GROMACS build configurations, and those expected for the current
66 # CMake build type (e.g. Release) to TARGET. Other GROMACS CMake code
67 # is expected to use either gmx_target_compile_options(name_of_target)
68 # or gmx_cuda_target_compile_options(name_of_variable) because CUDA
69 # compilation has special requirements.
70 #
71 # Most targets (ie. libraries, executables) need compiler flags that
72 # are characteristic of the build configuration. This function
73 # provides a central point for adding such flags. This approach is
74 # more flexible than e.g. setting CMAKE_CXX_FLAGS globally, because
75 # that setting will apply globally, which means it applies also to
76 # "external" code that the build of GROMACS might also build.
77 function(gmx_target_compile_options TARGET)
78     if (GMX_SKIP_DEFAULT_CFLAGS)
79         return()
80     endif()
81
82     # Prepare the generic compiler options
83     gmx_target_compile_options_inner()
84     target_compile_options(${TARGET}
85         PRIVATE
86         $<$<COMPILE_LANGUAGE:C>:${CFLAGS}>
87         $<$<COMPILE_LANGUAGE:CXX>:${CXXFLAGS}>
88         )
89     # Add compiler options for the build types
90     foreach(build_type ${build_types_with_explicit_flags})
91         target_compile_options(${TARGET}
92             BEFORE PRIVATE
93             $<$<AND:$<COMPILE_LANGUAGE:C>,$<CONFIG:${build_type}>>:${GMXC_CFLAGS_${build_type}}>
94             $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CONFIG:${build_type}>>:${GMXC_CXXFLAGS_${build_type}}>
95             )
96     endforeach()
97     # Add the release-configuration compiler options to build
98     # configurations that derive from it.
99     foreach(build_type RELWITHDEBINFO RELWITHASSERT MINSIZEREL PROFILE)
100         target_compile_options(${TARGET}
101             BEFORE PRIVATE
102             $<$<AND:$<COMPILE_LANGUAGE:C>,$<CONFIG:${build_type}>>:${GMXC_CFLAGS_RELEASE}>
103             $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CONFIG:${build_type}>>:${GMXC_CXXFLAGS_RELEASE}>
104             )
105     endforeach()
106     # Add those flags that we only want in the proper release build
107     # configuration.
108     target_compile_options(${TARGET}
109         BEFORE PRIVATE
110         $<$<AND:$<COMPILE_LANGUAGE:C>,$<CONFIG:RELEASE>>:${GMXC_CFLAGS_RELEASE_ONLY}>
111         $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CONFIG:RELEASE>>:${GMXC_CXXFLAGS_RELEASE_ONLY}>
112         )
113 endfunction()
114
115 # The approach taken by FindCUDA.cmake is to require that the compiler
116 # flags are known and present in a variable before creating the target
117 # for the library. (Those get embedded in files that are generated at
118 # the point of calling cuda_add_library, which does not create a
119 # target that one could later call target_compile_options upon.) So,
120 # this function instead returns appropriate content in
121 # ${VARIABLE_NAME}, along with other such variables that are
122 # specialized for the various build_types. Hopefully this will improve
123 # when we use native CUDA language support in our CMake.
124 function(gmx_cuda_target_compile_options VARIABLE_NAME)
125     if (GMX_SKIP_DEFAULT_CFLAGS)
126         set (CXXFLAGS "")
127     else()
128         gmx_target_compile_options_inner()
129     endif()
130
131     # Only C++ compilation is supported with CUDA code in GROMACS
132     set(${VARIABLE_NAME} ${CXXFLAGS} PARENT_SCOPE)
133
134     # Now organize the flags for different build
135     # configurations. First, the debug configuration.
136     set(${VARIABLE_NAME}_DEBUG "${GMXC_CXXFLAGS_DEBUG}" PARENT_SCOPE)
137     # Add those flags that we only want in the proper release build
138     # configuration.
139     set(${VARIABLE_NAME}_RELEASE "${GMXC_CXXFLAGS_RELEASE};${GMXC_CXXFLAGS_RELEASE_ONLY}" PARENT_SCOPE)
140     # Add the release flags to build configurations that derive from it
141     foreach(build_type RELWITHDEBINFO RELWITHASSERT MINSIZEREL PROFILE)
142         set(${VARIABLE_NAME}_${build_type} "${GMXC_CXXFLAGS_RELEASE};${GMXC_CXXFLAGS_${build_type}}" PARENT_SCOPE)
143     endforeach()
144 endfunction()
145
146 # Add the WARNING_FLAG to the compile options for TARGET if the
147 # compiler supports that flag. VARNAME is used to cache the result of
148 # the check whether the compiler supports that flag, as multiple
149 # targets may use the same suppression.
150 #
151 # This is generally used to suppress warnings judged not worth fixing
152 # in code external to, or generated by, GROMACS, or code that is
153 # more efficient to work around and later replace, rather than fix.
154 function(gmx_target_warning_suppression TARGET WARNING_FLAG VARNAME)
155     check_cxx_compiler_flag(${WARNING_FLAG} ${VARNAME})
156     if(${VARNAME})
157         target_compile_options(${TARGET} PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${WARNING_FLAG}>)
158     endif()
159 endfunction()
160
161 # Add the WARNING_FLAG to the compile flags for SOURCE_FILE if the
162 # compiler supports that flag. VARNAME is used to cache the result of
163 # the check whether the compiler supports that flag, as multiple
164 # targets may use the same suppression.
165 #
166 # This is generally used to suppress warnings judged not worth fixing
167 # in code external to, or generated by, GROMACS, or code that is
168 # more efficient to work around and later replace, rather than fix.
169 function(gmx_source_file_warning_suppression SOURCE_FILE WARNING_FLAG VARNAME)
170     check_cxx_compiler_flag(${WARNING_FLAG} ${VARNAME})
171     if(${VARNAME})
172         set_source_files_properties(${SOURCE_FILE} PROPERTIES COMPILE_FLAGS ${WARNING_FLAG})
173     endif()
174 endfunction()
175
176 # This is the actual exported function to be called
177 macro (gmx_c_flags)
178
179     include(CheckCCompilerFlag)
180     include(CheckCXXCompilerFlag)
181
182     # gcc
183     if(CMAKE_COMPILER_IS_GNUCC)
184         #flags are added in reverse order and -Wno* need to appear after -Wall
185         if(NOT GMX_OPENMP)
186             GMX_TEST_CFLAG(CFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CFLAGS)
187         endif()
188         if (GMX_COMPILER_WARNINGS)
189             GMX_TEST_CFLAG(CFLAGS_WARN "-Wall;-Wno-unused;-Wunused-value;-Wunused-parameter" GMXC_CFLAGS)
190             GMX_TEST_CFLAG(CFLAGS_WARN_EXTRA "-Wextra;-Wno-missing-field-initializers;-Wno-sign-compare;-Wpointer-arith" GMXC_CFLAGS)
191             GMX_TEST_CFLAG(CFLAGS_WARN_UNDEF "-Wundef" GMXC_CFLAGS)
192             GMX_TEST_CFLAG(CFLAGS_WARN_REL "-Wno-array-bounds" GMXC_CFLAGS_RELEASE_ONLY)
193             if(CYGWIN)
194                 GMX_TEST_CFLAG(CFLAGS_WARN_SUBSCRIPT "-Wno-char-subscripts" GMXC_CFLAGS)
195             endif()
196             GMX_TEST_CFLAG(CFLAGS_STRINGOP_TRUNCATION "-Werror=stringop-truncation" GMXC_CFLAGS)
197         endif()
198         # new in gcc 4.5
199         GMX_TEST_CFLAG(CFLAGS_EXCESS_PREC "-fexcess-precision=fast" GMXC_CFLAGS_RELEASE)
200         GMX_TEST_CFLAG(CFLAGS_COPT "-funroll-all-loops"
201                        GMXC_CFLAGS_RELEASE)
202         GMX_TEST_CFLAG(CFLAGS_NOINLINE "-fno-inline" GMXC_CFLAGS_DEBUG)
203     endif()
204     # g++
205     if(CMAKE_COMPILER_IS_GNUCXX)
206         if(NOT GMX_OPENMP)
207             GMX_TEST_CXXFLAG(CXXFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CXXFLAGS)
208         endif()
209         if (GMX_COMPILER_WARNINGS)
210             GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wall" GMXC_CXXFLAGS)
211             # Problematic with CUDA
212             # GMX_TEST_CXXFLAG(CXXFLAGS_WARN_EFFCXX "-Wnon-virtual-dtor" GMXC_CXXFLAGS)
213             GMX_TEST_CXXFLAG(CXXFLAGS_WARN_EXTRA "-Wextra;-Wno-missing-field-initializers;-Wpointer-arith;-Wmissing-declarations" GMXC_CXXFLAGS)
214             # CUDA versions prior to 7.5 come with a header (math_functions.h) which uses the _MSC_VER macro
215             # unconditionally, so we don't use -Wundef for earlier CUDA versions.
216             if(NOT(GMX_GPU AND CUDA_VERSION VERSION_LESS "7.5"))
217                 GMX_TEST_CXXFLAG(CXXFLAGS_WARN_UNDEF "-Wundef" GMXC_CXXFLAGS)
218             endif()
219             GMX_TEST_CFLAG(CXXFLAGS_WARN_REL "-Wno-array-bounds" GMXC_CXXFLAGS_RELEASE_ONLY)
220             GMX_TEST_CXXFLAG(CXXFLAGS_STRINGOP_TRUNCATION "-Wstringop-truncation" GMXC_CXXFLAGS)
221             if (CXXFLAGS_STRINGOP_TRUNCATION)
222                 set(CXXFLAGS_NO_STRINGOP_TRUNCATION "-Wno-stringop-truncation")
223             endif()
224         endif()
225         # new in gcc 4.5
226         GMX_TEST_CXXFLAG(CXXFLAGS_EXCESS_PREC "-fexcess-precision=fast" GMXC_CXXFLAGS_RELEASE)
227         GMX_TEST_CXXFLAG(CXXFLAGS_COPT "-funroll-all-loops"
228                          GMXC_CXXFLAGS_RELEASE)
229         GMX_TEST_CXXFLAG(CXXFLAGS_NOINLINE "-fno-inline" GMXC_CXXFLAGS_DEBUG)
230     endif()
231
232     # icc
233     if (CMAKE_C_COMPILER_ID MATCHES "Intel")
234         if (NOT WIN32)
235             if(NOT GMX_OPENMP)
236 # 3180: unrecognized OpenMP #pragma
237                 GMX_TEST_CFLAG(CFLAGS_PRAGMA "-wd3180" GMXC_CFLAGS)
238             endif()
239             if (GMX_COMPILER_WARNINGS)
240 # -w3 enables a lot of useful diagnostics but we don't care about all. -wd disables some selectively.
241 # 177: function/variable ".." was declared but never referenced
242 # 280: selector expression is constant
243 # 411: class defines no constructor to initialize the following (incorrect for struct, initializer list works)
244 # 593: variable ".." was set but never used
245 # 981: operands are evaluated in unspecified order
246 #1418: external function definition with no prior declaration
247 #1419: external declaration in primary source file
248 #1572: floating-point equality and inequality comparisons are unreliable
249 #1599: declaration hides variable ".."
250 #2259: non-pointer conversion from ".." to ".." may lose significant bits
251 #2415: variable ".." of static storage duration was declared but never referenced
252 #2547: ".." was specified as both a system and non-system include directory
253 #2557: comparison between signed and unsigned operands
254 #3280: declaration hides member ".."
255 #11074: Inlining inhibited by limit max-size(/max-total-size)
256 #11076: To get full report use -opt-report=3 -opt-report-phase ipo (shown for previous remark)
257                 GMX_TEST_CFLAG(CFLAGS_WARN "-w3;-wd177;-wd280;-wd411;-wd593;-wd981;-wd1418;-wd1419;-wd1572;-wd1599;-wd2259;-wd2415;-wd2547;-wd2557;-wd3280;-wd11074;-wd11076" GMXC_CFLAGS)
258             endif()
259             GMX_TEST_CFLAG(CFLAGS_STDGNU "-std=gnu99" GMXC_CFLAGS)
260             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)
261             GMX_TEST_CFLAG(CFLAGS_DEBUG "-O0" GMXC_CFLAGS_DEBUG) #icc defaults to -O2 even with -g
262             # The "except" fp-model requires something other than the
263             # default "fast" model, so we test and use it with
264             # "precise".
265             GMX_TEST_CFLAG(CFLAGS_FP_MODEL_RELASSERT "-fp-model=except;-fp-model=precise" GMXC_CFLAGS_RELWITHASSERT)
266         else()
267             if(NOT GMX_OPENMP)
268                 GMX_TEST_CFLAG(CFLAGS_PRAGMA "/wd3180" GMXC_CFLAGS)
269             endif()
270             if (GMX_COMPILER_WARNINGS)
271 #only on Windows
272 #161: unrecognized pragma
273 #1786 function was declared deprecated (is issued for stdlib function such as strncpy which have a _s version)
274 GMX_TEST_CFLAG(CFLAGS_WARN "/W3;/wd161;/wd177;/wd411;/wd593;/wd981;/wd1418;/wd1419;/wd1572;/wd1599;/wd1786;/wd2259;/wd2415;/wd2547;/wd2557;/wd3280" GMXC_CFLAGS)
275             endif()
276             GMX_TEST_CFLAG(CFLAGS_OPT "/Qip" GMXC_CFLAGS_RELEASE)
277         endif()
278     endif()
279
280     if (CMAKE_CXX_COMPILER_ID MATCHES "Intel")
281         if (NOT WIN32) 
282             if(NOT GMX_OPENMP)
283                 GMX_TEST_CXXFLAG(CXXFLAGS_PRAGMA "-wd3180" GMXC_CXXFLAGS)
284             endif()
285             if (GMX_COMPILER_WARNINGS)
286 #All but the following warnings are identical for the C-compiler (see above)
287 # 304: access control not specified
288 # 383: value copied to temporary, reference to temporary used
289 # 444: destructor for base class ".." is not virtual
290 # 869: was never referenced (false positives)
291 #2282: unrecognized GCC pragma
292                 GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-w3;-wd177;-wd280;-wd304;-wd383;-wd411;-wd444;-wd869;-wd981;-wd1418;-wd1572;-wd1599;-wd2259;-wd2547;-wd3280;-wd11074;-wd11076;-wd2282" GMXC_CXXFLAGS)
293             endif()
294             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)
295             GMX_TEST_CXXFLAG(CXXFLAGS_DEBUG "-O0" GMXC_CXXFLAGS_DEBUG)
296             # The "except" fp-model requires something other than the
297             # default "fast" model, so we test and use it with
298             # "precise".
299             GMX_TEST_CXXFLAG(CXXFLAGS_FP_MODEL_RELASSERT "-fp-model=except;-fp-model=precise" GMXC_CXXFLAGS_RELWITHASSERT)
300         else()
301             if(NOT GMX_OPENMP)
302                 GMX_TEST_CXXFLAG(CXXFLAGS_PRAGMA "/wd3180" GMXC_CFLAGS)
303             endif()
304             if (GMX_COMPILER_WARNINGS)
305 #161: unrecognized pragma
306 #809: exception specification for virtual function X is incompatible with that of overridden function
307                 GMX_TEST_CXXFLAG(CXXFLAGS_WARN "/W3;/wd161;/wd177;/wd280;/wd304;/wd383;/wd411;/wd444;/wd809;/wd869;/wd981;/wd1418;/wd1572;/wd1599;/wd1786;/wd2259;/wd2547;/wd3280;/wd11074;/wd11076;/wd2282" GMXC_CXXFLAGS)
308             endif()
309             GMX_TEST_CXXFLAG(CXXFLAGS_OPT "/Qip" GMXC_CXXFLAGS_RELEASE)
310         endif()
311     endif()
312
313     # PGI
314     # Inter-procedural analysis causes pgcc/pgc++ to crash when linking the library with PGI release 15.7.
315     if (CMAKE_C_COMPILER_ID MATCHES "PGI")
316         GMX_TEST_CFLAG(CFLAGS_OPT "-Mnoipa" GMXC_CFLAGS_RELEASE)
317     endif()
318     if (CMAKE_CXX_COMPILER_ID MATCHES "PGI")
319         # Using ipa exposes internal PGI-15.7 compiler bugs at compile time
320         GMX_TEST_CXXFLAG(CXXFLAGS_OPT "-Mnoipa" GMXC_CXXFLAGS_RELEASE)
321         # PGI identifies itself as GCC, but does not understand the GCC
322         # pragmas that occur in parser.cpp. Since that file is generated
323         # we cannot add a define there, but supress the warning instead.
324         GMX_TEST_CXXFLAG(CXXFLAGS_WARN "--diag_suppress=1675" GMXC_CXXFLAGS)
325     endif()
326
327     # Pathscale
328     if (CMAKE_C_COMPILER_ID MATCHES "PathScale")
329         if(NOT GMX_OPENMP)
330             GMX_TEST_CFLAG(CFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CFLAGS)
331         endif()
332         if (GMX_COMPILER_WARNINGS)
333             GMX_TEST_CFLAG(CFLAGS_WARN "-Wall;-Wno-unused;-Wunused-value" GMXC_CFLAGS)
334         endif()
335         GMX_TEST_CFLAG(CFLAGS_OPT "-OPT:Ofast;-fno-math-errno;-ffast-math"
336                          GMXC_CFLAGS_RELEASE)
337         GMX_TEST_CFLAG(CFLAGS_LANG "-std=gnu99" GMXC_CFLAGS)
338     endif()
339     if (CMAKE_CXX_COMPILER_ID MATCHES "PathScale")
340         if(NOT GMX_OPENMP)
341             GMX_TEST_CXXFLAG(CXXFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CXXFLAGS)
342         endif()
343         if (GMX_COMPILER_WARNINGS)
344             GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wall;-Wno-unused;-Wunused-value" GMXC_CXXFLAGS)
345         endif()
346         GMX_TEST_CXXFLAG(CXXFLAGS_OPT "-OPT:Ofast;-fno-math-errno;-ffast-math"
347                          GMXC_CXXFLAGS_RELEASE)
348     endif()
349
350     # xlc
351     # The suppressions below stop
352     # 1500-036: (I) about -O3 causing non-strict IEEE compliance that changes the semantics of the program (duh)
353     # 1500-010: (W) about correct PBC-related use of maximum array indices of DIM-sized C arrays
354     # 1500-030: (I) Additional optimization may be attained by recompiling and specifying MAXMEM option with a value greater than 8192.
355     if (CMAKE_C_COMPILER_ID MATCHES "XL")
356         GMX_TEST_CFLAG(CFLAGS_ARCH "-qarch=auto;-qtune=auto" GMXC_CFLAGS)
357         GMX_TEST_CFLAG(CFLAGS_OPT  "-O3" GMXC_CFLAGS_RELEASE)
358         GMX_TEST_CFLAG(CFLAGS_LANG "-qlanglvl=extc99" GMXC_CFLAGS)
359         GMX_TEST_CFLAG(CFLAGS_LANG "-qsuppress=1500-036;-qsuppress=1500-010;-qsuppress=1500-030" GMXC_CFLAGS)
360     endif()
361     if (CMAKE_CXX_COMPILER_ID MATCHES "XL")
362         GMX_TEST_CXXFLAG(CXXFLAGS_ARCH "-qarch=auto;-qtune=auto" GMXC_CXXFLAGS)
363         GMX_TEST_CXXFLAG(CXXFLAGS_OPT "-O3" GMXC_CXXFLAGS_RELEASE)
364         GMX_TEST_CXXFLAG(CXXFLAGS_LANG "-qsuppress=1500-036;-qsuppress=1500-010;-qsuppress=1500-030" GMXC_CXXFLAGS)
365     endif()
366
367     # msvc
368     if (MSVC)
369         # disable warnings for: 
370         #      forcing value to bool
371         #      "this" in initializer list
372         #      deprecated (posix, secure) functions
373         #      C4305: truncation (double -> float)
374         #      C4244: conversion from '.*' to '.*', possible loss of data
375         #      unreferenced local variable (only C)
376         #      C4267: conversion from 'size_t' to 'int', possible loss of data
377         #      conversion from 'const char*' to 'void*', different 'const' qualifiers (only C)
378         #      unknown pragma (4068)
379         #      remark #280: selector expression is constant
380         if(NOT CMAKE_CONFIGURATION_TYPES)
381             GMX_TEST_CFLAG(CFLAGS_WARN "/wd4800;/wd4355;/wd4996;/wd4305;/wd4244;/wd4101;/wd4267;/wd4090;/wd4068;" GMXC_CFLAGS)
382             GMX_TEST_CXXFLAG(CXXFLAGS_WARN "/wd4800;/wd4355;/wd4996;/wd4305;/wd4244;/wd4267;/wd4068;" GMXC_CXXFLAGS)
383         else() # MSVC projects only use the C++ flags
384             GMX_TEST_CXXFLAG(CXXFLAGS_WARN "/wd4800;/wd4355;/wd4996;/wd4305;/wd4244;/wd4101;/wd4267;/wd4090;/wd4068;" GMXC_CXXFLAGS)
385         endif()
386     endif()
387
388     if (CMAKE_C_COMPILER_ID MATCHES "Clang")
389         if(NOT GMX_OPENMP)
390             GMX_TEST_CFLAG(CFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CFLAGS)
391         endif()
392         if (GMX_COMPILER_WARNINGS)
393             GMX_TEST_CFLAG(CFLAGS_WARN "-Wall;-Wno-unused;-Wunused-value;-Wunused-parameter" GMXC_CFLAGS)
394             GMX_TEST_CFLAG(CFLAGS_WARN_EXTRA "-Wpointer-arith" GMXC_CFLAGS_EXTRA)
395         endif()
396     endif()
397
398     if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
399         if (GMX_COMPILER_WARNINGS)
400             # If used, -Wall should precede other options that silence warnings it enables
401             GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wall" GMXC_CXXFLAGS)
402             if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0") #LLVM BUG #21629
403                 GMX_TEST_CXXFLAG(CXXFLAGS_WARN_NO_BRACES "-Wno-missing-braces" GMXC_CXXFLAGS)
404             endif()
405             GMX_TEST_CXXFLAG(CXXFLAGS_WARN_EXTRA "-Wextra;-Wno-missing-field-initializers;-Wpointer-arith;-Wmissing-prototypes" GMXC_CXXFLAGS)
406             GMX_TEST_CXXFLAG(CXXFLAGS_DEPRECATED "-Wdeprecated" GMXC_CXXFLAGS)
407             # Functions placed in headers for inlining are not always
408             # used in every translation unit that includes the files,
409             # so we must disable the warning that there are such
410             # functions that are unused.
411             GMX_TEST_CXXFLAG(CXXFLAGS_NO_UNUSED_FUNCTION "-Wno-unused-function" GMXC_CXXFLAGS)
412         endif()
413         if(NOT GMX_OPENMP)
414             GMX_TEST_CXXFLAG(CXXFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CXXFLAGS)
415         endif()
416     endif()
417
418     # Apple bastardized version of Clang
419     if(${CMAKE_C_COMPILER_ID} MATCHES "AppleClang")
420         if(${CMAKE_C_COMPILER_VERSION} VERSION_GREATER 11.0)
421             # Mac OS Catalina ships with a horribly broken compiler (version 11.0.0.11000033)
422             # that checks stack alignment by default, but their own C library
423             # does not align the stack properly. Embarrassing, Apple...
424             GMX_TEST_CFLAG(CFLAG_NO_STACK_CHECK "-fno-stack-check" GMXC_CFLAGS)
425         endif()
426     endif()
427
428     if(${CMAKE_CXX_COMPILER_ID} MATCHES "AppleClang")
429         if(${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER 11.0)
430             # Mac OS Catalina ships with a horribly broken compiler (version 11.0.0.11000033)
431             # that checks stack alignment by default, but their own C library
432             # does not align the stack properly. Embarrassing, Apple...
433             GMX_TEST_CXXFLAG(CXXFLAG_NO_STACK_CHECK "-fno-stack-check" GMXC_CXXFLAGS)
434         endif()
435     endif()
436
437     # Fujitsu compilers on PrimeHPC/Sparc64
438     if(${CMAKE_C_COMPILER_ID} MATCHES Fujitsu OR
439        (${CMAKE_C_COMPILER_ID} MATCHES unknown AND ${CMAKE_C_COMPILER} MATCHES ^fcc))
440         GMX_TEST_CFLAG(CFLAG_GNUCOMPAT "-Xg;-w" GMXC_CFLAGS)
441         GMX_TEST_CFLAG(CFLAG_OPT "-Kfast,reduction,swp,simd=2,uxsimd,fsimple;-x100" GMXC_CFLAGS)
442     endif()
443
444     if(${CMAKE_CXX_COMPILER_ID} MATCHES Fujitsu OR
445        (${CMAKE_CXX_COMPILER_ID} MATCHES unknown AND ${CMAKE_CXX_COMPILER} MATCHES ^FCC))
446         GMX_TEST_CXXFLAG(CXXFLAG_GNUCOMPAT "-Xg;-w" GMXC_CXXFLAGS)
447         GMX_TEST_CXXFLAG(CXXFLAG_OPT "-Kfast,reduction,swp,simd=2,uxsimd,fsimple;-x100" GMXC_CXXFLAGS)
448     endif()
449
450 endmacro()