Skip to content

Instantly share code, notes, and snippets.

@amroamroamro
Last active November 15, 2017 17:45
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/c8d64d7df7c9036af26fe60104d6e2b6 to your computer and use it in GitHub Desktop.
Save amroamroamro/c8d64d7df7c9036af26fe60104d6e2b6 to your computer and use it in GitHub Desktop.
MinGW patch for OpenCV 3.3.1
From 90cbdbb555eef10f4418574bc179c5106eece453 Mon Sep 17 00:00:00 2001
From: Amro <amroamroamro@gmail.com>
Date: Wed, 15 Nov 2017 19:13:45 +0200
Subject: [PATCH] fixes for MinGW
* fix generation of pkg-config (libs shouldnt have .dll suffix)
* 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 +++++++++
cmake/OpenCVUtils.cmake | 2 +-
modules/videoio/CMakeLists.txt | 2 +-
3 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/cmake/OpenCVPCHSupport.cmake b/cmake/OpenCVPCHSupport.cmake
index 12e804d90..373f01ad9 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/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake
index bef09c295..358e8fc73 100644
--- a/cmake/OpenCVUtils.cmake
+++ b/cmake/OpenCVUtils.cmake
@@ -1025,7 +1025,7 @@ endfunction()
macro(ocv_get_libname var_name)
get_filename_component(__libname "${ARGN}" NAME)
- string(REGEX REPLACE "^lib(.+).(a|so)(.[.0-9]+)?$" "\\1" __libname "${__libname}")
+ string(REGEX REPLACE "^lib(.+)\\.(a|so|dll)(\\.[.0-9]+)?$" "\\1" __libname "${__libname}")
set(${var_name} "${__libname}")
endmacro()
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.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment