Implemented (buggy) gcc 4.1.x check in cmake.
authorSzilard Pall <pszilard@cbr.su.se>
Thu, 17 Jun 2010 01:08:07 +0000 (03:08 +0200)
committerSzilard Pall <pszilard@cbr.su.se>
Thu, 17 Jun 2010 01:08:07 +0000 (03:08 +0200)
CMakeLists.txt
cmake/gmxCheckGCCVersion.cmake [new file with mode: 0644]

index 12ac0ef2be2a3c6931f59bfe453e82ad6d41c4b7..1cf30686223ab149b52113aae1d520d5516a2586 100644 (file)
@@ -44,6 +44,7 @@ enable_language(C)
 option(GMX_IA32_ASM "Add SSE assembly files for IA32" OFF)
 option(GMX_X86_64_ASM "Add SSE assembly files for X86_64" OFF)
 option(USE_VERSION_H "Generate development version string/information" ON)
+option(GMX_DISABLE_GCC41_CHECK "Disable check for (buggy) gcc 4.1.x" OFF)
 
 #######################################################################
 # Check for options incompatible with OpenMM build                    #
@@ -292,6 +293,9 @@ endif (GMX_DLOPEN)
 include(CheckCCompilerFlag)
 include(CheckCXXCompilerFlag)
 
+# check for buggy GCC 4.1.x 
+include(gmxCheckGCCVersion)
+
 include(gmxCFlags)
 gmx_c_flags()
 
diff --git a/cmake/gmxCheckGCCVersion.cmake b/cmake/gmxCheckGCCVersion.cmake
new file mode 100644 (file)
index 0000000..0e38638
--- /dev/null
@@ -0,0 +1,47 @@
+# Check GCC version and if any of the 4.1.x family compiler suites is found
+# quit the build system generating process. 
+#
+# The GCC 4.1.x compilers contain an optimization related bug which might 
+# results in code that exhibits incorrect behaviour and often leads to 
+# exploding systems or crashes. 
+#
+# For further details see e.g. 
+# https://bugs.launchpad.net/ubuntu/+source/gcc-4.1/+bug/158799
+#
+# Szilard Pall (pszilard@cbr.su.se)
+#
+
+if(NOT GMX_DISABLE_GCC41_CHECK)
+
+if(CMAKE_COMPILER_IS_GNUCC)
+    # if we have -dumpversion flag use that, otherwise try the --version
+    execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
+        RESULT_VARIABLE _gcc_dumpversion_res
+        OUTPUT_VARIABLE _gcc_dumpversion_out
+        OUTPUT_STRIP_TRAILING_WHITESPACE)
+    # if gcc returned with error the -dumpversion is not available 
+    if(${_gcc_dumpversion_res} EQUAL 0)
+        if(${_gcc_dumpversion_out} MATCHES ".*4\\.1.*")
+            message(FATAL_ERROR " The GCC compiler in use seems to belong to the 4.1.x 
+                family (detected version: ${_gcc_dumpversion_out}). These compilers 
+                contain an optimization related bug which might results in code that 
+                exhibits incorrect behaviour and often leads to exploding systems or 
+                crashes. To disable this check set GMX_DISABLE_GCC41_CHECK=YES.")
+        endif()
+    else()    
+        message(WARNING " The GCC compiler in use does not support the -dumpversion flag. 
+            Will attempt parsing the version from the \"gcc --version\" output.")        
+        execute_process(COMMAND ${CMAKE_C_COMPILER} --version
+            OUTPUT_VARIABLE _gcc_version_out
+            OUTPUT_STRIP_TRAILING_WHITESPACE)            
+        if("${_gcc_version_out}" MATCHES ".*4\\.1.*")        
+            message(FATAL_ERROR " The GCC compiler in use seems to belong to the 4.1.x 
+                family. These compiler  compilers contain an optimization related bug 
+                which might results in code that exhibits incorrect behaviour and 
+                often leads to exploding systems or crashes. To disable this check set 
+                GMX_DISABLE_GCC41_CHECK=YES.")
+        endif()
+    endif()
+endif()
+
+endif()