From 771af4f32dd8c2609491743eda8cdd8adbe9c39e Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Tue, 1 Sep 2015 00:59:08 +0300 Subject: [PATCH] Some changes to support mingw-w64 - IPP is disabled by default when compiler is mingw (couldn't make it work) - fixed some warnings - fixed some `__GNUC__` version checks (for correctness and convenience) - removed UTF-8 BOM from hough.cpp (fixes #5253) --- CMakeLists.txt | 2 +- modules/core/include/opencv2/core/base.hpp | 4 ++-- .../core/include/opencv2/core/cuda.inl.hpp | 4 ++-- modules/core/src/system.cpp | 3 +++ .../cudalegacy/NCVHaarObjectDetection.hpp | 4 ++-- modules/cudalegacy/src/cuda/NPP_staging.cu | 2 +- modules/features2d/src/agast.cpp | 2 +- modules/features2d/src/agast_score.cpp | 2 +- modules/highgui/src/window_w32.cpp | 4 ++-- modules/imgcodecs/src/grfmt_jpeg.cpp | 2 +- modules/imgcodecs/src/grfmt_png.cpp | 2 +- modules/imgproc/src/hough.cpp | 2 +- modules/videoio/src/cap_dshow.cpp | 5 +++++ platforms/android/build_sdk.py | 21 ++++++++++--------- 14 files changed, 34 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f378e745..e69fa970b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -171,7 +171,7 @@ OCV_OPTION(WITH_GSTREAMER "Include Gstreamer support" ON OCV_OPTION(WITH_GSTREAMER_0_10 "Enable Gstreamer 0.10 support (instead of 1.x)" OFF ) OCV_OPTION(WITH_GTK "Include GTK support" ON IF (UNIX AND NOT APPLE AND NOT ANDROID) ) OCV_OPTION(WITH_GTK_2_X "Use GTK version 2" OFF IF (UNIX AND NOT APPLE AND NOT ANDROID) ) -OCV_OPTION(WITH_IPP "Include Intel IPP support" ON IF (X86_64 OR X86) AND NOT WINRT) +OCV_OPTION(WITH_IPP "Include Intel IPP support" ON IF (X86_64 OR X86) AND NOT WINRT AND NOT MINGW ) OCV_OPTION(WITH_JASPER "Include JPEG2K support" ON IF (NOT IOS) ) OCV_OPTION(WITH_JPEG "Include JPEG support" ON) OCV_OPTION(WITH_WEBP "Include WebP support" ON IF (NOT IOS AND NOT WINRT) ) diff --git a/modules/core/include/opencv2/core/base.hpp b/modules/core/include/opencv2/core/base.hpp index c701a8e41..262ce911a 100644 --- a/modules/core/include/opencv2/core/base.hpp +++ b/modules/core/include/opencv2/core/base.hpp @@ -271,7 +271,7 @@ enum BorderTypes { # endif #endif #ifndef CV_StaticAssert -# if defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC_MINOR__ > 2) +# if defined(__GNUC__) && (__GNUC__*100 + __GNUC_MINOR__ > 302) # define CV_StaticAssert(condition, reason) ({ extern int __attribute__((error("CV_StaticAssert: " reason " " #condition))) CV_StaticAssert(); ((condition) ? 0 : CV_StaticAssert()); }) # else template struct CV_StaticAssert_failed; @@ -296,7 +296,7 @@ enum BorderTypes { CV_DO_PRAGMA(warning(push)) \ CV_DO_PRAGMA(warning(disable: 4996)) #define CV_SUPPRESS_DEPRECATED_END CV_DO_PRAGMA(warning(pop)) -#elif defined (__clang__) || ((__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) +#elif defined (__clang__) || ((__GNUC__) && (__GNUC__*100 + __GNUC_MINOR__ > 405)) #define CV_SUPPRESS_DEPRECATED_START \ CV_DO_PRAGMA(GCC diagnostic push) \ CV_DO_PRAGMA(GCC diagnostic ignored "-Wdeprecated-declarations") diff --git a/modules/core/include/opencv2/core/cuda.inl.hpp b/modules/core/include/opencv2/core/cuda.inl.hpp index 1285b1a23..d9ab2ae4f 100644 --- a/modules/core/include/opencv2/core/cuda.inl.hpp +++ b/modules/core/include/opencv2/core/cuda.inl.hpp @@ -578,7 +578,7 @@ int DeviceInfo::deviceID() const inline size_t DeviceInfo::freeMemory() const { - size_t _totalMemory, _freeMemory; + size_t _totalMemory = 0, _freeMemory = 0; queryMemory(_totalMemory, _freeMemory); return _freeMemory; } @@ -586,7 +586,7 @@ size_t DeviceInfo::freeMemory() const inline size_t DeviceInfo::totalMemory() const { - size_t _totalMemory, _freeMemory; + size_t _totalMemory = 0, _freeMemory = 0; queryMemory(_totalMemory, _freeMemory); return _totalMemory; } diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index bf1a71a8f..743341daf 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -1191,6 +1191,9 @@ TLSData& getCoreTlsData() #pragma warning(disable:4447) // Disable warning 'main' signature found without threading model #endif +extern "C" +BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID lpReserved); + extern "C" BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID lpReserved) { diff --git a/modules/cudalegacy/include/opencv2/cudalegacy/NCVHaarObjectDetection.hpp b/modules/cudalegacy/include/opencv2/cudalegacy/NCVHaarObjectDetection.hpp index 6b84e8b25..50d3de325 100644 --- a/modules/cudalegacy/include/opencv2/cudalegacy/NCVHaarObjectDetection.hpp +++ b/modules/cudalegacy/include/opencv2/cudalegacy/NCVHaarObjectDetection.hpp @@ -69,7 +69,7 @@ // Guaranteed size cross-platform classifier structures // //============================================================================== -#if defined __GNUC__ && __GNUC__ > 2 && __GNUC_MINOR__ > 4 +#if defined __GNUC__ && (__GNUC__*100 + __GNUC_MINOR__ > 204) typedef Ncv32f __attribute__((__may_alias__)) Ncv32f_a; #else typedef Ncv32f Ncv32f_a; @@ -208,7 +208,7 @@ struct HaarClassifierNodeDescriptor32 } }; -#if defined __GNUC__ && __GNUC__ > 2 && __GNUC_MINOR__ > 4 +#if defined __GNUC__ && (__GNUC__*100 + __GNUC_MINOR__ > 204) typedef Ncv32u __attribute__((__may_alias__)) Ncv32u_a; #else typedef Ncv32u Ncv32u_a; diff --git a/modules/cudalegacy/src/cuda/NPP_staging.cu b/modules/cudalegacy/src/cuda/NPP_staging.cu index 639798ed7..a96f44ff9 100644 --- a/modules/cudalegacy/src/cuda/NPP_staging.cu +++ b/modules/cudalegacy/src/cuda/NPP_staging.cu @@ -1593,7 +1593,7 @@ NCVStatus nppsStCompact_32s(Ncv32s *d_src, Ncv32u srcLen, } -#if defined __GNUC__ && __GNUC__ > 2 && __GNUC_MINOR__ > 4 +#if defined __GNUC__ && (__GNUC__*100 + __GNUC_MINOR__ > 204) typedef Ncv32u __attribute__((__may_alias__)) Ncv32u_a; #else typedef Ncv32u Ncv32u_a; diff --git a/modules/features2d/src/agast.cpp b/modules/features2d/src/agast.cpp index 01532a538..cd58ac278 100644 --- a/modules/features2d/src/agast.cpp +++ b/modules/features2d/src/agast.cpp @@ -45,7 +45,7 @@ The references are: #include "precomp.hpp" #include "agast_score.hpp" -#ifdef _WIN32 +#ifdef _MSC_VER #pragma warning( disable : 4127 ) #endif diff --git a/modules/features2d/src/agast_score.cpp b/modules/features2d/src/agast_score.cpp index 33682354c..7b1835402 100644 --- a/modules/features2d/src/agast_score.cpp +++ b/modules/features2d/src/agast_score.cpp @@ -44,7 +44,7 @@ The references are: #include "agast_score.hpp" -#ifdef _WIN32 +#ifdef _MSC_VER #pragma warning( disable : 4127 ) #endif diff --git a/modules/highgui/src/window_w32.cpp b/modules/highgui/src/window_w32.cpp index 957f01a84..08a137ab2 100644 --- a/modules/highgui/src/window_w32.cpp +++ b/modules/highgui/src/window_w32.cpp @@ -2036,8 +2036,8 @@ icvCreateTrackbar( const char* trackbar_name, const char* window_name, trackbar = icvFindTrackbarByName(window,trackbar_name); if( !trackbar ) { - TBBUTTON tbs = {0}; - TBBUTTONINFO tbis = {0}; + TBBUTTON tbs = {}; + TBBUTTONINFO tbis = {}; RECT rect; int bcount; int len = (int)strlen( trackbar_name ); diff --git a/modules/imgcodecs/src/grfmt_jpeg.cpp b/modules/imgcodecs/src/grfmt_jpeg.cpp index 14a2b415d..6502db941 100644 --- a/modules/imgcodecs/src/grfmt_jpeg.cpp +++ b/modules/imgcodecs/src/grfmt_jpeg.cpp @@ -213,7 +213,7 @@ ImageDecoder JpegDecoder::newDecoder() const bool JpegDecoder::readHeader() { - bool result = false; + volatile bool result = false; close(); JpegState* state = new JpegState; diff --git a/modules/imgcodecs/src/grfmt_png.cpp b/modules/imgcodecs/src/grfmt_png.cpp index 95a605f63..5a5f40bb9 100644 --- a/modules/imgcodecs/src/grfmt_png.cpp +++ b/modules/imgcodecs/src/grfmt_png.cpp @@ -140,7 +140,7 @@ void PngDecoder::readDataFromBuf( void* _png_ptr, uchar* dst, size_t size ) bool PngDecoder::readHeader() { - bool result = false; + volatile bool result = false; close(); png_structp png_ptr = png_create_read_struct( PNG_LIBPNG_VER_STRING, 0, 0, 0 ); diff --git a/modules/imgproc/src/hough.cpp b/modules/imgproc/src/hough.cpp index e11df27f0..c5bb2e20e 100644 --- a/modules/imgproc/src/hough.cpp +++ b/modules/imgproc/src/hough.cpp @@ -1,4 +1,4 @@ -/*M/////////////////////////////////////////////////////////////////////////////////////// +/*M/////////////////////////////////////////////////////////////////////////////////////// // // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. // diff --git a/modules/videoio/src/cap_dshow.cpp b/modules/videoio/src/cap_dshow.cpp index 88814c83e..4380b9b2c 100644 --- a/modules/videoio/src/cap_dshow.cpp +++ b/modules/videoio/src/cap_dshow.cpp @@ -93,6 +93,11 @@ Thanks to: #pragma warning(disable: 4995) #endif +#ifdef __MINGW32__ +// MinGW does not understand COM interfaces +#pragma GCC diagnostic ignored "-Wnon-virtual-dtor" +#endif + #include #include #include diff --git a/platforms/android/build_sdk.py b/platforms/android/build_sdk.py index 068f24998..e2c2d18ea 100755 --- a/platforms/android/build_sdk.py +++ b/platforms/android/build_sdk.py @@ -10,16 +10,16 @@ class Fail(Exception): def __str__(self): return "ERROR" if self.t is None else self.t -def execute(cmd): +def execute(cmd, shell=False): try: log.info("Executing: %s" % cmd) - retcode = subprocess.call(cmd) + retcode = subprocess.call(cmd, shell=shell) if retcode < 0: raise Fail("Child was terminated by signal:" %s -retcode) elif retcode > 0: raise Fail("Child returned: %s" % retcode) except OSError as e: - raise Fail("Execution failed: %s" % e) + raise Fail("Execution failed: %s" % e.strerror) def rm_one(d): d = os.path.abspath(d) @@ -180,7 +180,7 @@ class Builder: log.info("Generating XML config: %s", xmlname) ET.ElementTree(r).write(xmlname, encoding="utf-8") execute(["ninja", "opencv_engine"]) - execute(["ant", "-f", os.path.join(apkdest, "build.xml"), "debug"]) + execute(["ant", "-f", os.path.join(apkdest, "build.xml"), "debug"], shell=True) # TODO: Sign apk def build_javadoc(self): @@ -278,12 +278,13 @@ if __name__ == "__main__": log.info("Detected OpenCV version: %s", builder.opencv_version) log.info("Detected Engine version: %s", builder.engine_version) - for one in args.extra_pack: - i = one.find(":") - if i > 0 and i < len(one) - 1: - builder.add_extra_pack(one[:i], one[i+1:]) - else: - raise Fail("Bad extra pack provided: %s, should be in form ':'" % one) + if args.extra_pack: + for one in args.extra_pack: + i = one.find(":") + if i > 0 and i < len(one) - 1: + builder.add_extra_pack(one[:i], one[i+1:]) + else: + raise Fail("Bad extra pack provided: %s, should be in form ':'" % one) engines = [] for i, abi in enumerate(ABIs):