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 GMX_TEST_CFLAG(CFLAGS_WARN "-Wall -Wno-unused" GMXC_CFLAGS)
35 GMX_TEST_CFLAG(CFLAGS_EXCESS_PREC "-fexcess-precision=fast" GMXC_CFLAGS)
36 GMX_TEST_CFLAG(CFLAGS_COPT "-fomit-frame-pointer -finline-functions -funroll-all-loops"
38 GMX_TEST_CFLAG(CFLAGS_NOINLINE "-fno-inline" GMXC_CFLAGS_DEBUG)
41 if(CMAKE_COMPILER_IS_GNUCXX)
42 GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wall -Wno-unused" GMXC_CXXFLAGS)
44 GMX_TEST_CXXFLAG(CXXFLAGS_EXCESS_PREC "-fexcess-precision=fast"
46 GMX_TEST_CXXFLAG(CXXFLAGS_COPT "-fomit-frame-pointer -finline-functions -funroll-all-loops"
47 GMXC_CXXFLAGS_RELEASE)
48 GMX_TEST_CXXFLAG(CXXFLAGS_NOINLINE "-fno-inline" GMXC_CXXFLAGS_DEBUG)
52 if (CMAKE_C_COMPILER_ID MATCHES "Intel")
54 GMX_TEST_CFLAG(CFLAGS_OPT "-ip -w -funroll-all-loops -std=gnu99"
56 GMX_TEST_CFLAG(CFLAGS_SSE2 "-msse2" GMXC_CFLAGS)
57 GMX_TEST_CFLAG(CFLAGS_X86 "-mtune=core2" GMXC_CFLAGS_RELEASE)
58 GMX_TEST_CFLAG(CFLAGS_IA64 "-mtune=itanium2" GMXC_CFLAGS_RELEASE)
60 GMX_TEST_CFLAG(CFLAGS_SSE2 "/arch:SSE2" GMXC_CFLAGS)
61 GMX_TEST_CFLAG(CFLAGS_X86 "/Qip" GMXC_CFLAGS_RELEASE)
65 if (CMAKE_CXX_COMPILER_ID MATCHES "Intel")
67 GMX_TEST_CXXFLAG(CXXFLAGS_OPT
68 "-ip -w -funroll-all-loops -std=gnu99"
70 GMX_TEST_CXXFLAG(CXXFLAGS_SSE2 "-msse2" GMXC_CXXFLAGS)
71 GMX_TEST_CXXFLAG(CXXFLAGS_X86 "-mtune=core2" GMXC_CXXFLAGS_RELEASE)
72 GMX_TEST_CXXFLAG(CXXFLAGS_IA64 "-mtune=itanium2"
73 GMXC_CXXFLAGS_RELEASE)
75 GMX_TEST_CXXFLAG(CXXFLAGS_SSE2 "/arch:SSE2" GMXC_CXXFLAGS)
76 GMX_TEST_CXXFLAG(CXXFLAGS_X86 "/Qip" GMXC_CXXFLAGS_RELEASE)
81 if (CMAKE_C_COMPILER_ID MATCHES "PGI")
82 GMX_TEST_CFLAG(CFLAGS_OPT "-fastsse" GMXC_CFLAGS_RELEASE)
84 if (CMAKE_CXX_COMPILER_ID MATCHES "PGI")
85 GMX_TEST_CXXFLAG(CXXFLAGS_OPT "-fastsse" GMXC_CXXFLAGS_RELEASE)
89 if (CMAKE_C_COMPILER_ID MATCHES "PathScale")
90 GMX_TEST_CFLAG(CFLAGS_OPT "-OPT:Ofast -fno-math-errno -ffast-math"
92 GMX_TEST_CFLAG(CFLAGS_LANG "-std=gnu99" GMXC_CFLAGS)
94 if (CMAKE_CXX_COMPILER_ID MATCHES "PathScale")
95 GMX_TEST_CXXFLAG(CXXFLAGS_OPT "-OPT:Ofast -fno-math-errno -ffast-math"
96 GMXC_CXXFLAGS_RELEASE)
100 if (CMAKE_C_COMPILER_ID MATCHES "XL")
101 GMX_TEST_CFLAG(CFLAGS_OPT "-qarch=auto -qtune=auto" GMXC_CFLAGS)
102 GMX_TEST_CFLAG(CFLAGS_LANG "-qlanglvl=extc99" GMXC_CFLAGS)
104 if (CMAKE_CXX_COMPILER_ID MATCHES "XL")
105 GMX_TEST_CXXFLAG(CFLAGS_OPT "-qarch=auto -qtune=auto" GMXC_CXXFLAGS)
109 # now actually set the flags:
111 if ( NOT DEFINED GMXCFLAGS_SET AND NOT DEFINED ENV{CFLAGS} )
112 set(GMXCFLAGS_SET true CACHE INTERNAL "Whether to reset the C flags"
115 set(CMAKE_C_FLAGS "${GMXC_CFLAGS} ${CMAKE_C_FLAGS}"
116 CACHE STRING "Flags used by the compiler during all build types."
118 set(CMAKE_C_FLAGS_RELEASE "${GMXC_CFLAGS_RELEASE} ${CMAKE_C_FLAGS_RELEASE}"
119 CACHE STRING "Flags used by the compiler during release builds."
121 set(CMAKE_C_FLAGS_DEBUG "${GMXC_CFLAGS_DEBUG} ${CMAKE_C_FLAGS_DEBUG}"
122 CACHE STRING "Flags used by the compiler during debug builds."
127 if ( NOT DEFINED GMXCXXFLAGS_SET AND NOT DEFINED ENV{CXXFLAGS} )
128 set(GMXCXXFLAGS_SET true CACHE INTERNAL "Whether to reset the C++ flags"
130 set(CMAKE_CXX_FLAGS "${GMXC_CXXFLAGS} ${CMAKE_CXX_FLAGS}"
131 CACHE STRING "Flags used by the compiler during all build types."
133 set(CMAKE_CXX_FLAGS_RELEASE
134 "${GMXC_CXXFLAGS_RELEASE} ${CMAKE_CXX_FLAGS_RELEASE}"
135 CACHE STRING "Flags used by the compiler during release builds."
137 set(CMAKE_CXX_FLAGS_DEBUG
138 "${GMXC_CXXFLAGS_DEBUG} ${CMAKE_CXX_FLAGS_DEBUG}"
139 CACHE STRING "Flags used by the compiler during debug builds."
142 ENDMACRO(gmx_c_flags)