Skip to content

Instantly share code, notes, and snippets.

@amroamroamro
Created February 23, 2018 23:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amroamroamro/de4ac4155f35451ebc6300f87cec1f06 to your computer and use it in GitHub Desktop.
Save amroamroamro/de4ac4155f35451ebc6300f87cec1f06 to your computer and use it in GitHub Desktop.
MinGW patch for OpenCV 3.4.0
From c68ef0b7e946e4e915f0972a3e5eb6bf6a425f59 Mon Sep 17 00:00:00 2001
From: Amro <amroamroamro@gmail.com>
Date: Fri, 23 Feb 2018 19:20:03 +0200
Subject: [PATCH] fixes for MinGW
* fix mingw detection in cmake file. When test is true, it defines
a macro which instructs DShow header not to use secure string
replacements not found in mingw
* dont pass gcc flags to windres which doesnt understand them
(another workaround is to set ENABLE_PRECOMPILED_HEADERS=OFF)
References:
* windres fix: https://github.com/mxe/mxe/pull/1485
* https://wiki.qt.io/How_to_setup_Qt_and_openCV_on_Windows#OpenCV
---
cmake/OpenCVPCHSupport.cmake | 9 +++++++++
modules/videoio/CMakeLists.txt | 2 +-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/cmake/OpenCVPCHSupport.cmake b/cmake/OpenCVPCHSupport.cmake
index 0e41130b0..b064892af 100644
--- a/cmake/OpenCVPCHSupport.cmake
+++ b/cmake/OpenCVPCHSupport.cmake
@@ -31,6 +31,15 @@ ELSE()
SET(PCHSupport_FOUND FALSE)
ENDIF()
+IF(CMAKE_COMPILER_IS_GNUCXX AND MINGW)
+ # in case of MinGW, we drop <FLAGS> because windres doesnt understand the
+ # various GCC flags like -Winvalid-pch or -include
+ # (it only accepts the -D and -I flags, i.e <DEFINES> and <INCLUDES>)
+ # https://github.com/Kitware/CMake/blob/master/Modules/Platform/Windows-windres.cmake
+ # https://sourceware.org/binutils/docs-2.28/binutils/windres.html
+ set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> -O coff <DEFINES> <INCLUDES> <SOURCE> <OBJECT>")
+ENDIF()
+
MACRO(_PCH_GET_COMPILE_FLAGS _out_compile_flags)
STRING(TOUPPER "CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}" _flags_var_name)
diff --git a/modules/videoio/CMakeLists.txt b/modules/videoio/CMakeLists.txt
index 0ded292f0..e8f6d593b 100644
--- a/modules/videoio/CMakeLists.txt
+++ b/modules/videoio/CMakeLists.txt
@@ -78,7 +78,7 @@ endif()
if (WIN32 AND HAVE_DSHOW)
list(APPEND videoio_srcs ${CMAKE_CURRENT_LIST_DIR}/src/cap_dshow.cpp)
list(APPEND videoio_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/cap_dshow.hpp)
- if (MINGW64)
+ if (MINGW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTRSAFE_NO_DEPRECATE")
endif()
endif()
--
2.15.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment