From 4a3141accf717513689c71f87d0b4cb96068b8d2 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Thu, 17 May 2012 20:25:12 +0000 Subject: [PATCH] #1932 Fixed SSE instability on mingw32 --- cmake/OpenCVCompilerOptions.cmake | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake index c76c0488e..e84eb6c98 100644 --- a/cmake/OpenCVCompilerOptions.cmake +++ b/cmake/OpenCVCompilerOptions.cmake @@ -1,18 +1,3 @@ -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() - endif() - - if(CMAKE_COMPILER_IS_GNUCC) - foreach(flags CMAKE_C_FLAGS CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_DEBUG) - string(REPLACE "-O3" "-O2" ${flags} "${${flags}}") - endforeach() - endif() -endif() - if(MSVC) if(CMAKE_CXX_FLAGS STREQUAL CMAKE_CXX_FLAGS_INIT) # override cmake default exception handling option @@ -28,6 +13,21 @@ set(OPENCV_EXTRA_EXE_LINKER_FLAGS "") set(OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE "") set(OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG "") +if(MINGW) + # mingw compiler is known to produce unstable SSE code + # here we are trying to workaround the problem + include(CheckCXXCompilerFlag) + CHECK_CXX_COMPILER_FLAG(-mstackrealign HAVE_STACKREALIGN_FLAG) + if(HAVE_STACKREALIGN_FLAG) + set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -mstackrealign") + else() + CHECK_CXX_COMPILER_FLAG(-mpreferred-stack-boundary=2 HAVE_PREFERRED_STACKBOUNDARY_FLAG) + if(HAVE_PREFERRED_STACKBOUNDARY_FLAG) + set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -mstackrealign") + endif() + endif() +endif() + if(CMAKE_COMPILER_IS_GNUCXX) # High level of warnings. set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -Wall")