From 07658aeb74a81bc776ceb556a79cc17c25804e8f Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Mon, 14 May 2012 14:19:28 +0000 Subject: [PATCH] Fixed replacement of -O3 with -O2 for mingw compiler #1896 --- cmake/OpenCVCompilerOptions.cmake | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake index 8f13fa68f1..5218b2a06d 100644 --- a/cmake/OpenCVCompilerOptions.cmake +++ b/cmake/OpenCVCompilerOptions.cmake @@ -1,5 +1,16 @@ -if (WIN32 AND CMAKE_GENERATOR MATCHES "(MinGW)|(MSYS)") - set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG" CACHE STRING "") +if (WIN32) + # mingw compiler is known to produce unstable SSE code with -O3 hence we are trying to use -O2 instead + if(CMAKE_COMPILER_IS_GNUCXX) + foreach(flags CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG) + string(REPLACE "-O3" "-O2" ${flags} "${${flags}}") + endforeach() + endforeach() + + if(CMAKE_COMPILER_IS_GNUC) + foreach(flags CMAKE_C_FLAGS CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_DEBUG) + string(REPLACE "-O3" "-O2" ${flags} "${${flags}}") + endforeach() + endforeach() endif() if(MSVC)