Detect non-fatal warnings when trying CFlags for source
authorErik Lindahl <erik@kth.se>
Thu, 12 Jun 2014 08:30:44 +0000 (10:30 +0200)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Mon, 23 Jun 2014 15:27:12 +0000 (17:27 +0200)
We now first check the flag itself (and catch warnings),
after which we check if our SIMD source compiles with it.

Fixes #1461.

Change-Id: Ic6ae99f62c5657195a59dc83ab08399d3491249a

cmake/gmxFindFlagsForSource.cmake

index e5db8d1cef831bd35eb060586f51ba38bff7b106..d2533e72e40090e29bc336504bd7acb20f42c091 100644 (file)
@@ -47,10 +47,19 @@ FUNCTION(GMX_FIND_CFLAG_FOR_SOURCE VARIABLE DESCRIPTION SOURCE CFLAGSVAR)
         foreach(_testflag ${ARGN} "")
             message(STATUS "Try ${DESCRIPTION} = [${_testflag}]")
             set(CMAKE_REQUIRED_FLAGS "${${CFLAGSVAR}} ${_testflag}")
-            # make a valid variable name from the flag string: replace all non-alphanumerical chars
-            string(REGEX REPLACE "[^a-zA-Z0-9]+" "_" COMPILE_VARIABLE "C_FLAG_${_testflag}")
-            check_c_source_compiles("${SOURCE}" ${COMPILE_VARIABLE})
-            if(${${COMPILE_VARIABLE}})
+            # make valid variable names from the flag string: replace all non-alphanumerical chars
+            string(REGEX REPLACE "[^a-zA-Z0-9]+" "_" COMPILE_FLAG_VARIABLE "C_FLAG_${_testflag}")
+            string(REGEX REPLACE "[^a-zA-Z0-9]+" "_" COMPILE_SIMD_VARIABLE "C_SIMD_COMPILES_FLAG_${_testflag}")
+
+            # Check that the flag itself is fine, and that is does not generate warnings either
+            check_c_compiler_flag("${_testflag}" ${COMPILE_FLAG_VARIABLE})
+
+            if(${COMPILE_FLAG_VARIABLE})
+                # Check that we can compile SIMD source (this does not catch warnings)
+                check_c_source_compiles("${SOURCE}" ${COMPILE_SIMD_VARIABLE})
+            endif(${COMPILE_FLAG_VARIABLE})
+
+            if(${COMPILE_FLAG_VARIABLE} AND ${COMPILE_SIMD_VARIABLE})
                 set(${VARIABLE}_FLAG "${_testflag}" CACHE INTERNAL "${DESCRIPTION}")
                 set(${VARIABLE} 1 CACHE INTERNAL "Result of test for ${DESCRIPTION}" FORCE)
                 break()
@@ -82,10 +91,19 @@ FUNCTION(GMX_FIND_CXXFLAG_FOR_SOURCE VARIABLE DESCRIPTION SOURCE CXXFLAGSVAR)
         foreach(_testflag ${ARGN} "")
             message(STATUS "Try ${DESCRIPTION} = [${_testflag}]")
             set(CMAKE_REQUIRED_FLAGS "${${CXXFLAGSVAR}} ${_testflag}")
-            # make a valid variable name from the flag string: replace all non-alphanumerical chars
-            string(REGEX REPLACE "[^a-zA-Z0-9]+" "_" COMPILE_VARIABLE "CXX_FLAG_${_testflag}")
-            check_cxx_source_compiles("${SOURCE}" ${COMPILE_VARIABLE})
-            if(${${COMPILE_VARIABLE}})
+            # make valid variable names from the flag string: replace all non-alphanumerical chars
+            string(REGEX REPLACE "[^a-zA-Z0-9]+" "_" COMPILE_FLAG_VARIABLE "CXX_FLAG_${_testflag}")
+            string(REGEX REPLACE "[^a-zA-Z0-9]+" "_" COMPILE_SIMD_VARIABLE "CXX_SIMD_COMPILES_FLAG_${_testflag}")
+            
+            # Check that the flag itself is fine, and that is does not generate warnings either
+            check_cxx_compiler_flag("${_testflag}" ${COMPILE_FLAG_VARIABLE})
+
+            if(${COMPILE_FLAG_VARIABLE})
+                # Check that we can compile SIMD source (this does not catch warnings)
+                check_cxx_source_compiles("${SOURCE}" ${COMPILE_SIMD_VARIABLE})
+            endif(${COMPILE_FLAG_VARIABLE})
+
+            if(${COMPILE_FLAG_VARIABLE} AND ${COMPILE_SIMD_VARIABLE})
                 set(${VARIABLE}_FLAG "${_testflag}" CACHE INTERNAL "${DESCRIPTION}")
                 set(${VARIABLE} 1 CACHE INTERNAL "Result of test for ${DESCRIPTION}" FORCE)
                 break()