Don't use -O3 on Mingw, as people report it as unreliable. Use -O2
authorOscar Fuentes <ofv@wanadoo.es>
Fri, 7 Jan 2011 20:31:03 +0000 (20:31 +0000)
committerOscar Fuentes <ofv@wanadoo.es>
Fri, 7 Jan 2011 20:31:03 +0000 (20:31 +0000)
instead.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123028 91177308-0d34-0410-b5e6-96231b3b80d8

CMakeLists.txt
cmake/modules/LLVMProcessSources.cmake

index 3f48b58f43852093584243e60b1d94862ddb5c0d..5e27c6f82e4703b0b7059c8c7a19ab4b3db55734 100644 (file)
@@ -317,6 +317,12 @@ if( MINGW )
   set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES}${LLVM_SYSTEM_LIBS}")
 endif()
 
+if( MINGW )
+  # People report that -O3 is unreliable on MinGW. The traditional
+  # build also uses -O2 for that reason:
+  llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
+endif()
+
 add_subdirectory(lib/Support)
 
 # Everything else depends on Support:
index 5f59eac451184041e2c824d22c6d2ec8dfc7b6be..98b61296db4721c3bded8d83c3c8adc82f8fbfa0 100644 (file)
@@ -1,5 +1,15 @@
 include(AddFileDependencies)
 
+macro(llvm_replace_compiler_option var old new)
+  # Replaces a compiler option or switch `old' in `var' by `new'.
+  # If `old' is not in `var', appends `new' to `var'.
+  # Example: llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
+  if( "${${var}}" MATCHES "(^| )${old}($| )" )
+    string( REGEX REPLACE "(^| )${old}($| )" " ${new}  " ${var} "${${var}}" )
+  else()
+    set( ${var} "${${var}} ${new}" )
+  endif()
+endmacro(llvm_replace_compiler_option)
 
 macro(add_td_sources srcs)
   file(GLOB tds *.td)