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)
34 #Fix for LLVM OpenMP bug (redmine 900). Needs to run before OpenMP flags are set below.
36 exec_program(${CMAKE_C_COMPILER} ARGS --version OUTPUT_VARIABLE _compiler_output)
37 if(_compiler_output MATCHES "llvm.*4\\.2")
38 message(STATUS "OpenMP multithreading not supported with llvm-gcc 4.2, disabled")
39 set(GMX_OPENMP OFF CACHE BOOL
40 "OpenMP multithreading not not supported with llvm-gcc 4.2, disabled!" FORCE)
44 #flags are added in reverse order and -Wno* need to appear after -Wall
46 GMX_TEST_CFLAG(CFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CFLAGS)
48 GMX_TEST_CFLAG(CFLAGS_WARN "-Wall -Wno-unused -Wunused-value" GMXC_CFLAGS)
49 GMX_TEST_CFLAG(CFLAGS_WARN "-Wextra -Wno-missing-field-initializers -Wno-sign-compare" GMXC_CFLAGS)
51 GMX_TEST_CFLAG(CFLAGS_EXCESS_PREC "-fexcess-precision=fast" GMXC_CFLAGS_RELEASE)
52 GMX_TEST_CFLAG(CFLAGS_COPT "-fomit-frame-pointer -funroll-all-loops"
54 GMX_TEST_CFLAG(CFLAGS_NOINLINE "-fno-inline" GMXC_CFLAGS_DEBUG)
57 if(CMAKE_COMPILER_IS_GNUCXX)
59 GMX_TEST_CFLAG(CXXFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CXXFLAGS)
61 GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wall -Wno-unused -Wunused-value" GMXC_CXXFLAGS)
62 GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wextra -Wno-missing-field-initializers -Wno-sign-compare" GMXC_CXXFLAGS)
64 GMX_TEST_CXXFLAG(CXXFLAGS_EXCESS_PREC "-fexcess-precision=fast" GMXC_CXXFLAGS_RELEASE)
65 GMX_TEST_CXXFLAG(CXXFLAGS_COPT "-fomit-frame-pointer -funroll-all-loops"
66 GMXC_CXXFLAGS_RELEASE)
67 GMX_TEST_CXXFLAG(CXXFLAGS_NOINLINE "-fno-inline" GMXC_CXXFLAGS_DEBUG)
71 if (CMAKE_C_COMPILER_ID MATCHES "Intel")
74 GMX_TEST_CFLAG(CFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CFLAGS)
76 GMX_TEST_CFLAG(CFLAGS_WARN "-Wall" GMXC_CFLAGS)
77 GMX_TEST_CFLAG(CFLAGS_OPT "-std=gnu99" GMXC_CFLAGS)
78 GMX_TEST_CFLAG(CFLAGS_OPT "-ip -funroll-all-loops" GMXC_CFLAGS_RELEASE)
79 GMX_TEST_CFLAG(CFLAGS_SSE2 "-msse2" GMXC_CFLAGS_RELEASE)
80 GMX_TEST_CFLAG(CFLAGS_X86 "-mtune=core2" GMXC_CFLAGS_RELEASE)
81 GMX_TEST_CFLAG(CFLAGS_IA64 "-mtune=itanium2" GMXC_CFLAGS_RELEASE)
83 GMX_TEST_CFLAG(CXXFLAGS_WARN "/W2" GMXC_CXXFLAGS)
84 GMX_TEST_CFLAG(CFLAGS_SSE2 "/arch:SSE2" GMXC_CFLAGS_RELEASE)
85 GMX_TEST_CFLAG(CFLAGS_X86 "/Qip" GMXC_CFLAGS_RELEASE)
89 if (CMAKE_CXX_COMPILER_ID MATCHES "Intel")
92 GMX_TEST_CFLAG(CXXFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CXXFLAGS)
94 GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wall" GMXC_CXXFLAGS)
95 GMX_TEST_CXXFLAG(CXXFLAGS_OPT "-ip -funroll-all-loops" GMXC_CXXFLAGS_RELEASE)
96 GMX_TEST_CXXFLAG(CXXFLAGS_SSE2 "-msse2" GMXC_CXXFLAGS_RELEASE)
97 GMX_TEST_CXXFLAG(CXXFLAGS_X86 "-mtune=core2" GMXC_CXXFLAGS_RELEASE)
98 GMX_TEST_CXXFLAG(CXXFLAGS_IA64 "-mtune=itanium2"
99 GMXC_CXXFLAGS_RELEASE)
101 GMX_TEST_CXXFLAG(CXXFLAGS_WARN "/W2" GMXC_CXXFLAGS)
102 GMX_TEST_CXXFLAG(CXXFLAGS_SSE2 "/arch:SSE2" GMXC_CXXFLAGS_RELEASE)
103 GMX_TEST_CXXFLAG(CXXFLAGS_X86 "/Qip" GMXC_CXXFLAGS_RELEASE)
108 if (CMAKE_C_COMPILER_ID MATCHES "PGI")
109 GMX_TEST_CFLAG(CFLAGS_OPT "-fastsse" GMXC_CFLAGS_RELEASE)
111 if (CMAKE_CXX_COMPILER_ID MATCHES "PGI")
112 GMX_TEST_CXXFLAG(CXXFLAGS_OPT "-fastsse" GMXC_CXXFLAGS_RELEASE)
116 if (CMAKE_C_COMPILER_ID MATCHES "PathScale")
118 GMX_TEST_CFLAG(CFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CFLAGS)
120 GMX_TEST_CFLAG(CFLAGS_WARN "-Wall -Wno-unused -Wunused-value" GMXC_CFLAGS)
121 GMX_TEST_CFLAG(CFLAGS_OPT "-OPT:Ofast -fno-math-errno -ffast-math"
123 GMX_TEST_CFLAG(CFLAGS_LANG "-std=gnu99" GMXC_CFLAGS)
125 if (CMAKE_CXX_COMPILER_ID MATCHES "PathScale")
127 GMX_TEST_CFLAG(CXXFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CXXFLAGS)
129 GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wall -Wno-unused -Wunused-value" GMXC_CXXFLAGS)
130 GMX_TEST_CXXFLAG(CXXFLAGS_OPT "-OPT:Ofast -fno-math-errno -ffast-math"
131 GMXC_CXXFLAGS_RELEASE)
135 if (CMAKE_C_COMPILER_ID MATCHES "XL")
136 GMX_TEST_CFLAG(CFLAGS_OPT "-qarch=auto -qtune=auto" GMXC_CFLAGS)
137 GMX_TEST_CFLAG(CFLAGS_LANG "-qlanglvl=extc99" GMXC_CFLAGS)
139 if (CMAKE_CXX_COMPILER_ID MATCHES "XL")
140 GMX_TEST_CXXFLAG(CFLAGS_OPT "-qarch=auto -qtune=auto" GMXC_CXXFLAGS)
145 # disable warnings for:
146 # inconsistent dll linkage
147 GMX_TEST_CFLAG(CFLAGS_WARN "/wd4273" GMXC_CFLAGS)
148 GMX_TEST_CFLAG(CXXFLAGS_WARN "/wd4273" GMXC_CXXFLAGS)
151 if (CMAKE_C_COMPILER_ID MATCHES "Clang")
153 GMX_TEST_CFLAG(CFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CFLAGS)
155 GMX_TEST_CFLAG(CFLAGS_WARN "-Wall -Wno-unused -Wunused-value" GMXC_CFLAGS)
158 if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
160 GMX_TEST_CXXFLAG(CXXFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CXXFLAGS)
162 GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wall -Wno-unused -Wunused-value" GMXC_CXXFLAGS)
165 # now actually set the flags:
167 if ( NOT DEFINED GMXCFLAGS_SET AND NOT DEFINED ENV{CFLAGS} )
168 set(GMXCFLAGS_SET true CACHE INTERNAL "Whether to reset the C flags"
171 set(CMAKE_C_FLAGS "${GMXC_CFLAGS} ${CMAKE_C_FLAGS}"
172 CACHE STRING "Flags used by the compiler during all build types."
174 set(CMAKE_C_FLAGS_RELEASE "${GMXC_CFLAGS_RELEASE} ${CMAKE_C_FLAGS_RELEASE}"
175 CACHE STRING "Flags used by the compiler during release builds."
177 set(CMAKE_C_FLAGS_DEBUG "${GMXC_CFLAGS_DEBUG} ${CMAKE_C_FLAGS_DEBUG}"
178 CACHE STRING "Flags used by the compiler during debug builds."
183 if ( NOT DEFINED GMXCXXFLAGS_SET AND NOT DEFINED ENV{CXXFLAGS} )
184 set(GMXCXXFLAGS_SET true CACHE INTERNAL "Whether to reset the C++ flags"
186 set(CMAKE_CXX_FLAGS "${GMXC_CXXFLAGS} ${CMAKE_CXX_FLAGS}"
187 CACHE STRING "Flags used by the compiler during all build types."
189 set(CMAKE_CXX_FLAGS_RELEASE
190 "${GMXC_CXXFLAGS_RELEASE} ${CMAKE_CXX_FLAGS_RELEASE}"
191 CACHE STRING "Flags used by the compiler during release builds."
193 set(CMAKE_CXX_FLAGS_DEBUG
194 "${GMXC_CXXFLAGS_DEBUG} ${CMAKE_CXX_FLAGS_DEBUG}"
195 CACHE STRING "Flags used by the compiler during debug builds."
198 ENDMACRO(gmx_c_flags)