2 # Test C flags FLAGS, and set VARIABLE to true if the work. Also add the
4 MACRO(GMX_TEST_CFLAG VARIABLE FLAGS CFLAGSVAR)
5 IF(NOT DEFINED ${VARIABLE})
6 CHECK_C_COMPILER_FLAG("${FLAGS}" ${VARIABLE})
8 SET (${CFLAGSVAR} "${FLAGS} ${${CFLAGSVAR}}")
10 ENDIF(NOT DEFINED ${VARIABLE})
11 ENDMACRO(GMX_TEST_CFLAG VARIABLE FLAGS CFLAGSVAR)
13 # Test C++ flags FLAGS, and set VARIABLE to true if the work. Also add the
14 # flags to CXXFLAGSVAR.
15 MACRO(GMX_TEST_CXXFLAG VARIABLE FLAGS CXXFLAGSVAR)
16 IF(NOT DEFINED ${VARIABLE})
17 CHECK_CXX_COMPILER_FLAG("${FLAGS}" ${VARIABLE})
19 SET (${CXXFLAGSVAR} "${FLAGS} ${${CXXFLAGSVAR}}")
21 ENDIF(NOT DEFINED ${VARIABLE})
22 ENDMACRO(GMX_TEST_CXXFLAG VARIABLE FLAGS CXXFLAGSVAR)
25 # This is the actual exported function to be called
28 include(CheckCCompilerFlag)
29 include(CheckCXXCompilerFlag)
32 if(CMAKE_COMPILER_IS_GNUCC)
33 #flags are added in reverse order and -Wno* need to appear after -Wall
35 GMX_TEST_CFLAG(CFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CFLAGS)
37 GMX_TEST_CFLAG(CFLAGS_WARN "-Wall -Wno-unused -Wunused-value" GMXC_CFLAGS)
38 GMX_TEST_CFLAG(CFLAGS_WARN "-Wextra -Wno-missing-field-initializers -Wno-sign-compare" GMXC_CFLAGS)
40 GMX_TEST_CFLAG(CFLAGS_EXCESS_PREC "-fexcess-precision=fast" GMXC_CFLAGS_RELEASE)
41 GMX_TEST_CFLAG(CFLAGS_COPT "-fomit-frame-pointer -finline-functions -funroll-all-loops"
43 GMX_TEST_CFLAG(CFLAGS_NOINLINE "-fno-inline" GMXC_CFLAGS_DEBUG)
46 if(CMAKE_COMPILER_IS_GNUCXX)
48 GMX_TEST_CFLAG(CXXFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CXXFLAGS)
50 GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wall -Wno-unused -Wunused-value" GMXC_CXXFLAGS)
51 GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wextra -Wno-missing-field-initializers -Wno-sign-compare" GMXC_CXXFLAGS)
53 GMX_TEST_CXXFLAG(CXXFLAGS_EXCESS_PREC "-fexcess-precision=fast" GMXC_CXXFLAGS_RELEASE)
54 GMX_TEST_CXXFLAG(CXXFLAGS_COPT "-fomit-frame-pointer -finline-functions -funroll-all-loops"
55 GMXC_CXXFLAGS_RELEASE)
56 GMX_TEST_CXXFLAG(CXXFLAGS_NOINLINE "-fno-inline" GMXC_CXXFLAGS_DEBUG)
60 if (CMAKE_C_COMPILER_ID MATCHES "Intel")
63 GMX_TEST_CFLAG(CFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CFLAGS)
65 GMX_TEST_CFLAG(CFLAGS_WARN "-Wall" GMXC_CFLAGS)
66 GMX_TEST_CFLAG(CFLAGS_OPT "-std=gnu99" GMXC_CFLAGS)
67 GMX_TEST_CFLAG(CFLAGS_OPT "-ip -funroll-all-loops" GMXC_CFLAGS_RELEASE)
68 GMX_TEST_CFLAG(CFLAGS_SSE2 "-msse2" GMXC_CFLAGS_RELEASE)
69 GMX_TEST_CFLAG(CFLAGS_X86 "-mtune=core2" GMXC_CFLAGS_RELEASE)
70 GMX_TEST_CFLAG(CFLAGS_IA64 "-mtune=itanium2" GMXC_CFLAGS_RELEASE)
72 GMX_TEST_CFLAG(CXXFLAGS_WARN "/W2" GMXC_CXXFLAGS)
73 GMX_TEST_CFLAG(CFLAGS_SSE2 "/arch:SSE2" GMXC_CFLAGS_RELEASE)
74 GMX_TEST_CFLAG(CFLAGS_X86 "/Qip" GMXC_CFLAGS_RELEASE)
78 if (CMAKE_CXX_COMPILER_ID MATCHES "Intel")
81 GMX_TEST_CFLAG(CXXFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CXXFLAGS)
83 GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wall" GMXC_CXXFLAGS)
84 GMX_TEST_CXXFLAG(CXXFLAGS_OPT "-ip -funroll-all-loops" GMXC_CXXFLAGS_RELEASE)
85 GMX_TEST_CXXFLAG(CXXFLAGS_SSE2 "-msse2" GMXC_CXXFLAGS_RELEASE)
86 GMX_TEST_CXXFLAG(CXXFLAGS_X86 "-mtune=core2" GMXC_CXXFLAGS_RELEASE)
87 GMX_TEST_CXXFLAG(CXXFLAGS_IA64 "-mtune=itanium2"
88 GMXC_CXXFLAGS_RELEASE)
90 GMX_TEST_CXXFLAG(CXXFLAGS_WARN "/W2" GMXC_CXXFLAGS)
91 GMX_TEST_CXXFLAG(CXXFLAGS_SSE2 "/arch:SSE2" GMXC_CXXFLAGS_RELEASE)
92 GMX_TEST_CXXFLAG(CXXFLAGS_X86 "/Qip" GMXC_CXXFLAGS_RELEASE)
97 if (CMAKE_C_COMPILER_ID MATCHES "PGI")
98 GMX_TEST_CFLAG(CFLAGS_OPT "-fastsse" GMXC_CFLAGS_RELEASE)
100 if (CMAKE_CXX_COMPILER_ID MATCHES "PGI")
101 GMX_TEST_CXXFLAG(CXXFLAGS_OPT "-fastsse" GMXC_CXXFLAGS_RELEASE)
105 if (CMAKE_C_COMPILER_ID MATCHES "PathScale")
107 GMX_TEST_CFLAG(CFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CFLAGS)
109 GMX_TEST_CFLAG(CFLAGS_WARN "-Wall -Wno-unused -Wunused-value" GMXC_CFLAGS)
110 GMX_TEST_CFLAG(CFLAGS_OPT "-OPT:Ofast -fno-math-errno -ffast-math"
112 GMX_TEST_CFLAG(CFLAGS_LANG "-std=gnu99" GMXC_CFLAGS)
114 if (CMAKE_CXX_COMPILER_ID MATCHES "PathScale")
116 GMX_TEST_CFLAG(CXXFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CXXFLAGS)
118 GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wall -Wno-unused -Wunused-value" GMXC_CXXFLAGS)
119 GMX_TEST_CXXFLAG(CXXFLAGS_OPT "-OPT:Ofast -fno-math-errno -ffast-math"
120 GMXC_CXXFLAGS_RELEASE)
124 if (CMAKE_C_COMPILER_ID MATCHES "XL")
125 GMX_TEST_CFLAG(CFLAGS_OPT "-qarch=auto -qtune=auto" GMXC_CFLAGS)
126 GMX_TEST_CFLAG(CFLAGS_LANG "-qlanglvl=extc99" GMXC_CFLAGS)
128 if (CMAKE_CXX_COMPILER_ID MATCHES "XL")
129 GMX_TEST_CXXFLAG(CFLAGS_OPT "-qarch=auto -qtune=auto" GMXC_CXXFLAGS)
134 # disable warnings for:
135 # inconsistent dll linkage
136 GMX_TEST_CFLAG(CFLAGS_WARN "/wd4273" GMXC_CFLAGS)
137 GMX_TEST_CFLAG(CXXFLAGS_WARN "/wd4273" GMXC_CXXFLAGS)
140 if (CMAKE_C_COMPILER_ID MATCHES "Clang")
142 GMX_TEST_CFLAG(CFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CFLAGS)
144 GMX_TEST_CFLAG(CFLAGS_WARN "-Wall -Wno-unused -Wunused-value" GMXC_CFLAGS)
147 if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
149 GMX_TEST_CXXFLAG(CXXFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CXXFLAGS)
151 GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wall -Wno-unused -Wunused-value" GMXC_CXXFLAGS)
154 # now actually set the flags:
156 if ( NOT DEFINED GMXCFLAGS_SET AND NOT DEFINED ENV{CFLAGS} )
157 set(GMXCFLAGS_SET true CACHE INTERNAL "Whether to reset the C flags"
160 set(CMAKE_C_FLAGS "${GMXC_CFLAGS} ${CMAKE_C_FLAGS}"
161 CACHE STRING "Flags used by the compiler during all build types."
163 set(CMAKE_C_FLAGS_RELEASE "${GMXC_CFLAGS_RELEASE} ${CMAKE_C_FLAGS_RELEASE}"
164 CACHE STRING "Flags used by the compiler during release builds."
166 set(CMAKE_C_FLAGS_DEBUG "${GMXC_CFLAGS_DEBUG} ${CMAKE_C_FLAGS_DEBUG}"
167 CACHE STRING "Flags used by the compiler during debug builds."
172 if ( NOT DEFINED GMXCXXFLAGS_SET AND NOT DEFINED ENV{CXXFLAGS} )
173 set(GMXCXXFLAGS_SET true CACHE INTERNAL "Whether to reset the C++ flags"
175 set(CMAKE_CXX_FLAGS "${GMXC_CXXFLAGS} ${CMAKE_CXX_FLAGS}"
176 CACHE STRING "Flags used by the compiler during all build types."
178 set(CMAKE_CXX_FLAGS_RELEASE
179 "${GMXC_CXXFLAGS_RELEASE} ${CMAKE_CXX_FLAGS_RELEASE}"
180 CACHE STRING "Flags used by the compiler during release builds."
182 set(CMAKE_CXX_FLAGS_DEBUG
183 "${GMXC_CXXFLAGS_DEBUG} ${CMAKE_CXX_FLAGS_DEBUG}"
184 CACHE STRING "Flags used by the compiler during debug builds."
187 ENDMACRO(gmx_c_flags)