From 7cc7a3f37dfe28c4eadef08a2b13ff35ee42003c Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Sun, 8 Apr 2012 21:49:19 +0000 Subject: [PATCH] Suppressed hundreds of useless MSVC warnings (can be reenabled setting cmake variable ENABLE_NOISY_WARNINGS to ON). Fixed some of remaining warnings. --- 3rdparty/libjasper/CMakeLists.txt | 8 +- 3rdparty/libtiff/CMakeLists.txt | 5 +- 3rdparty/zlib/CMakeLists.txt | 2 +- CMakeLists.txt | 3 +- cmake/OpenCVCompilerOptions.cmake | 269 ++++++++++++----------- modules/contrib/src/colormap.cpp | 2 +- modules/contrib/src/facerec.cpp | 10 +- modules/contrib/src/spinimages.cpp | 14 +- modules/core/include/opencv2/core/operations.hpp | 13 +- modules/features2d/src/detectors.cpp | 4 +- modules/gpu/CMakeLists.txt | 16 +- modules/gpu/test/utility.cpp | 2 +- modules/highgui/CMakeLists.txt | 2 +- modules/highgui/src/cap_dshow.cpp | 4 +- modules/imgproc/src/pyramids.cpp | 2 +- modules/python/CMakeLists.txt | 8 +- modules/ts/CMakeLists.txt | 12 +- modules/ts/src/ts_perf.cpp | 2 +- modules/videostab/src/fast_marching.cpp | 3 +- modules/videostab/src/inpainting.cpp | 4 +- samples/c/CMakeLists.txt | 2 +- samples/cpp/CMakeLists.txt | 2 +- samples/gpu/CMakeLists.txt | 2 +- 23 files changed, 205 insertions(+), 186 deletions(-) diff --git a/3rdparty/libjasper/CMakeLists.txt b/3rdparty/libjasper/CMakeLists.txt index 9912e3b..ea99f57 100644 --- a/3rdparty/libjasper/CMakeLists.txt +++ b/3rdparty/libjasper/CMakeLists.txt @@ -22,8 +22,10 @@ file(GLOB lib_ext_hdrs jasper/*.h) add_library(${JASPER_LIBRARY} STATIC ${lib_srcs} ${lib_hdrs} ${lib_ext_hdrs}) if(MSVC) - string(REPLACE "/W3" "/W0" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") - string(REPLACE "/W4" "/W0" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + if(NOT ENABLE_NOISY_WARNINGS) + string(REPLACE "/W3" "/W0" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + string(REPLACE "/W4" "/W0" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + endif() add_definitions(-DJAS_WIN_MSVC_BUILD) endif() @@ -33,7 +35,7 @@ if(UNIX) endif() endif() -if(CMAKE_COMPILER_IS_GNUCXX) +if(CMAKE_COMPILER_IS_GNUCXX AND NOT ENABLE_NOISY_WARNINGS) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-implicit-function-declaration -Wno-unused") endif() diff --git a/3rdparty/libtiff/CMakeLists.txt b/3rdparty/libtiff/CMakeLists.txt index e184815..881eebd 100644 --- a/3rdparty/libtiff/CMakeLists.txt +++ b/3rdparty/libtiff/CMakeLists.txt @@ -82,8 +82,7 @@ set(lib_srcs if(UNIX) list(APPEND lib_srcs tif_unix.c) - if(CMAKE_COMPILER_IS_GNUCXX) - #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-strict-aliasing -Wno-int-to-pointer-cast") + if(CMAKE_COMPILER_IS_GNUCXX AND NOT ENABLE_NOISY_WARNINGS) set_source_files_properties(tif_unix.c PROPERTIES COMPILE_FLAGS "-w") endif() endif() @@ -92,7 +91,7 @@ if(WIN32) list(APPEND lib_srcs tif_win32.c) endif(WIN32) -if(MSVC) +if(MSVC AND NOT ENABLE_NOISY_WARNINGS) string(REPLACE "/W4" "/W0" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") string(REPLACE "/W4" "/W0" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") endif() diff --git a/3rdparty/zlib/CMakeLists.txt b/3rdparty/zlib/CMakeLists.txt index 6de6be1..d213565 100644 --- a/3rdparty/zlib/CMakeLists.txt +++ b/3rdparty/zlib/CMakeLists.txt @@ -82,7 +82,7 @@ if(UNIX) endif() endif() -if(MSVC) +if(MSVC AND NOT ENABLE_NOISY_WARNINGS) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4013") endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index 098e043..596873b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -166,6 +166,7 @@ OCV_OPTION(ENABLE_SSE3 "Enable SSE3 instructions" OCV_OPTION(ENABLE_SSSE3 "Enable SSSE3 instructions" OFF IF (CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) ) OCV_OPTION(ENABLE_SSE41 "Enable SSE4.1 instructions" OFF IF (CV_ICC OR CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) ) OCV_OPTION(ENABLE_SSE42 "Enable SSE4.2 instructions" OFF IF (CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) ) +OCV_OPTION(ENABLE_NOISY_WARNINGS "Show all warnings even if they are too noisy" OFF ) OCV_OPTION(OPENCV_WARNINGS_ARE_ERRORS "Treat warnings as errors" OFF ) # uncategorized options @@ -841,7 +842,7 @@ status(" Python:") status(" Interpreter:" PYTHON_EXECUTABLE THEN "${PYTHON_EXECUTABLE} (ver ${PYTHON_VERSION_FULL})" ELSE NO) status(" Libraries:" HAVE_opencv_python THEN ${PYTHON_LIBRARIES} ELSE NO) status(" numpy:" PYTHON_USE_NUMPY THEN "${PYTHON_NUMPY_INCLUDE_DIR} (ver ${PYTHON_NUMPY_VERSION})" ELSE "NO (Python wrappers can not be generated)") -status(" packages path:" PYTHON_EXECUTABLE THEN "${PYTHON_PACKAGES_PATH}" ELSE -) +status(" packages path:" PYTHON_EXECUTABLE THEN "${PYTHON_PACKAGES_PATH}" ELSE "-") if(ANDROID) status("") diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake index 47590a8..7454275 100644 --- a/cmake/OpenCVCompilerOptions.cmake +++ b/cmake/OpenCVCompilerOptions.cmake @@ -1,5 +1,5 @@ if (WIN32 AND CMAKE_GENERATOR MATCHES "(MinGW)|(MSYS)") - set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG" CACHE STRING "") + set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG" CACHE STRING "") endif() set(OPENCV_EXTRA_C_FLAGS "") @@ -10,143 +10,140 @@ set(OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE "") set(OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG "") if(MSVC) - set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS") - # 64-bit portability warnings, in MSVC8 - if(MSVC80) - set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /Wp64") - endif() - #if(MSVC90) - # set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /D _BIND_TO_CURRENT_CRT_VERSION=1 /D _BIND_TO_CURRENT_VCLIBS_VERSION=1") - #endif() - - if(BUILD_WITH_DEBUG_INFO) - set(OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE "${OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE} /debug") - endif() - - # Remove unreferenced functions: function level linking - set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /Gy") - set(OPENCV_EXTRA_C_FLAGS_DEBUG "${OPENCV_EXTRA_C_FLAGS_DEBUG} /bigobj") - if(BUILD_WITH_DEBUG_INFO) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} /Zi") - endif() + set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS") + # 64-bit portability warnings, in MSVC80 + if(MSVC80) + set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /Wp64") + endif() + + if(BUILD_WITH_DEBUG_INFO) + set(OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE "${OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE} /debug") + endif() + + # Remove unreferenced functions: function level linking + set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /Gy") + set(OPENCV_EXTRA_C_FLAGS_DEBUG "${OPENCV_EXTRA_C_FLAGS_DEBUG} /bigobj") + if(BUILD_WITH_DEBUG_INFO) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} /Zi") + endif() endif() if(CMAKE_COMPILER_IS_GNUCXX) - # High level of warnings. - set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -Wall") - - # The -Wno-long-long is required in 64bit systems when including sytem headers. - if(X86_64) - set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -Wno-long-long") - endif() - - # We need pthread's - if(UNIX AND NOT ANDROID) - set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -pthread") + # High level of warnings. + set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -Wall") + + # The -Wno-long-long is required in 64bit systems when including sytem headers. + if(X86_64) + set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -Wno-long-long") + endif() + + # We need pthread's + if(UNIX AND NOT ANDROID) + set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -pthread") + endif() + + if(OPENCV_WARNINGS_ARE_ERRORS) + set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -Werror") + endif() + + if(X86 AND NOT MINGW64 AND NOT X86_64 AND NOT APPLE) + set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -march=i686") + endif() + + # Other optimizations + if(ENABLE_OMIT_FRAME_POINTER) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -fomit-frame-pointer") + else() + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -fno-omit-frame-pointer") + endif() + if(ENABLE_FAST_MATH) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -ffast-math") + endif() + if(ENABLE_POWERPC) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -mcpu=G3 -mtune=G5") + endif() + if(ENABLE_SSE) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -msse") + endif() + if(ENABLE_SSE2) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -msse2") + endif() + + # SSE3 and further should be disabled under MingW because it generates compiler errors + if(NOT MINGW) + if(ENABLE_SSE3) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -msse3") endif() - if(OPENCV_WARNINGS_ARE_ERRORS) - set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -Werror") + if(${CMAKE_OPENCV_GCC_VERSION_NUM} GREATER 402) + set(HAVE_GCC43_OR_NEWER 1) endif() - - if(X86 AND NOT MINGW64 AND NOT X86_64 AND NOT APPLE) - set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -march=i686") + if(${CMAKE_OPENCV_GCC_VERSION_NUM} GREATER 401) + set(HAVE_GCC42_OR_NEWER 1) endif() - # Other optimizations - if(ENABLE_OMIT_FRAME_POINTER) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -fomit-frame-pointer") - else() - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -fno-omit-frame-pointer") - endif() - if(ENABLE_FAST_MATH) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -ffast-math") - endif() - if(ENABLE_POWERPC) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -mcpu=G3 -mtune=G5") - endif() - if(ENABLE_SSE) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -msse") - endif() - if(ENABLE_SSE2) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -msse2") - endif() - - # SSE3 and further should be disabled under MingW because it generates compiler errors - if(NOT MINGW) - if(ENABLE_SSE3) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -msse3") - endif() - - if(${CMAKE_OPENCV_GCC_VERSION_NUM} GREATER 402) - set(HAVE_GCC43_OR_NEWER 1) + if(HAVE_GCC42_OR_NEWER OR APPLE) + if(ENABLE_SSSE3) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -mssse3") + endif() + if(HAVE_GCC43_OR_NEWER) + if(ENABLE_SSE41) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -msse4.1") endif() - if(${CMAKE_OPENCV_GCC_VERSION_NUM} GREATER 401) - set(HAVE_GCC42_OR_NEWER 1) - endif() - - if(HAVE_GCC42_OR_NEWER OR APPLE) - if(ENABLE_SSSE3) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -mssse3") - endif() - if(HAVE_GCC43_OR_NEWER) - if(ENABLE_SSE41) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -msse4.1") - endif() - if(ENABLE_SSE42) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -msse4.2") - endif() - endif() - endif() - endif(NOT MINGW) - - if(X86 OR X86_64) - if(NOT APPLE AND CMAKE_SIZEOF_VOID_P EQUAL 4) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -mfpmath=387") + if(ENABLE_SSE42) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -msse4.2") endif() + endif() endif() + endif(NOT MINGW) - # Profiling? - if(ENABLE_PROFILING) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -pg -g") - elseif(NOT APPLE AND NOT ANDROID) - # Remove unreferenced functions: function level linking - set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -ffunction-sections") + if(X86 OR X86_64) + if(NOT APPLE AND CMAKE_SIZEOF_VOID_P EQUAL 4) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -mfpmath=387") endif() + endif() - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -DNDEBUG") - set(OPENCV_EXTRA_C_FLAGS_DEBUG "${OPENCV_EXTRA_C_FLAGS_DEBUG} -O0 -DDEBUG -D_DEBUG") - if(BUILD_WITH_DEBUG_INFO) - set(OPENCV_EXTRA_C_FLAGS_DEBUG "${OPENCV_EXTRA_C_FLAGS_DEBUG} -ggdb3") - endif() + # Profiling? + if(ENABLE_PROFILING) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -pg -g") + elseif(NOT APPLE AND NOT ANDROID) + # Remove unreferenced functions: function level linking + set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -ffunction-sections") + endif() + + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -DNDEBUG") + set(OPENCV_EXTRA_C_FLAGS_DEBUG "${OPENCV_EXTRA_C_FLAGS_DEBUG} -O0 -DDEBUG -D_DEBUG") + if(BUILD_WITH_DEBUG_INFO) + set(OPENCV_EXTRA_C_FLAGS_DEBUG "${OPENCV_EXTRA_C_FLAGS_DEBUG} -ggdb3") + endif() endif() if(MSVC) - # 64-bit MSVC compiler uses SSE/SSE2 by default - if(NOT MSVC64) - if(ENABLE_SSE) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} /arch:SSE") - endif() - if(ENABLE_SSE2) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} /arch:SSE2") - endif() - endif() - if(ENABLE_SSE3) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} /arch:SSE3") - endif() - if(ENABLE_SSE4_1) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} /arch:SSE4.1") - endif() - if (ENABLE_SSE OR ENABLE_SSE2 OR ENABLE_SSE3 OR ENABLE_SSE4_1) - set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} /Oi") + # 64-bit MSVC compiler uses SSE/SSE2 by default + if(NOT MSVC64) + if(ENABLE_SSE) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} /arch:SSE") endif() + if(ENABLE_SSE2) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} /arch:SSE2") + endif() + endif() + if(ENABLE_SSE3) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} /arch:SSE3") + endif() + if(ENABLE_SSE4_1) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} /arch:SSE4.1") + endif() + if(ENABLE_SSE OR ENABLE_SSE2 OR ENABLE_SSE3 OR ENABLE_SSE4_1) + set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} /Oi") + endif() endif() # Extra link libs if the user selects building static libs: if(NOT BUILD_SHARED_LIBS AND CMAKE_COMPILER_IS_GNUCXX AND NOT ANDROID) - # Android does not need these settings because they are already set by toolchain file - set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} stdc++) - set(OPENCV_EXTRA_C_FLAGS "-fPIC ${OPENCV_EXTRA_C_FLAGS}") + # Android does not need these settings because they are already set by toolchain file + set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} stdc++) + set(OPENCV_EXTRA_C_FLAGS "-fPIC ${OPENCV_EXTRA_C_FLAGS}") endif() # Add user supplied extra options (optimization, etc...) @@ -170,22 +167,26 @@ set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${OPENCV_E set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG}") if (WIN32 AND MSVC) - # avoid warnings from MSVC about overriding the /W* option - # we replace /W3 with /W4 only for C++ files, - # since all the 3rd-party libraries OpenCV uses are in C, - # and we do not care about their warnings. - string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") - string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") - - # allow extern "C" functions throw exceptions - string(REPLACE "/EHsc" "/EHsc-" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") - string(REPLACE "/EHsc" "/EHsc-" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") - string(REPLACE "/EHsc" "/EHsc-" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") - string(REPLACE "/EHsc" "/EHsc-" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - string(REPLACE "/EHsc" "/EHsc-" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") - string(REPLACE "/EHsc" "/EHsc-" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") - - string(REPLACE "/Zm1000" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - string(REPLACE "/Zm1000" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + # avoid warnings from MSVC about overriding the /W* option + # we replace /W3 with /W4 only for C++ files, + # since all the 3rd-party libraries OpenCV uses are in C, + # and we do not care about their warnings. + string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") + string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") + + # allow extern "C" functions throw exceptions + string(REPLACE "/EHsc" "/EHsc-" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + string(REPLACE "/EHsc" "/EHsc-" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") + string(REPLACE "/EHsc" "/EHsc-" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") + string(REPLACE "/EHsc" "/EHsc-" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + string(REPLACE "/EHsc" "/EHsc-" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") + string(REPLACE "/EHsc" "/EHsc-" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") + + string(REPLACE "/Zm1000" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + string(REPLACE "/Zm1000" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + + if(NOT ENABLE_NOISY_WARNINGS) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4251") #class 'std::XXX' needs to have dll-interface to be used by clients of YYY + endif() endif() diff --git a/modules/contrib/src/colormap.cpp b/modules/contrib/src/colormap.cpp index eca78dc..5eeb9bb 100644 --- a/modules/contrib/src/colormap.cpp +++ b/modules/contrib/src/colormap.cpp @@ -166,7 +166,7 @@ namespace colormap static Mat linear_colormap(InputArray X, InputArray r, InputArray g, InputArray b, float begin, float end, float n) { - return linear_colormap(X,r,g,b,linspace(begin,end,n)); + return linear_colormap(X,r,g,b,linspace(begin,end, cvRound(n))); } // Interpolates from a base colormap. diff --git a/modules/contrib/src/facerec.cpp b/modules/contrib/src/facerec.cpp index d7a529d..13a4af4 100644 --- a/modules/contrib/src/facerec.cpp +++ b/modules/contrib/src/facerec.cpp @@ -117,7 +117,7 @@ public: void train(InputArray src, InputArray labels); // Predicts the label of a query image in src. - int predict(const InputArray src) const; + int predict(InputArray src) const; // See FaceRecognizer::load. void load(const FileStorage& fs); @@ -495,8 +495,8 @@ inline void elbp_(InputArray _src, OutputArray _dst, int radius, int neighbors) dst.setTo(0); for(int n=0; n(-radius) * sin(2.0*CV_PI*n/static_cast(neighbors)); - float y = static_cast(radius) * cos(2.0*CV_PI*n/static_cast(neighbors)); + float x = static_cast(-radius * sin(2.0*CV_PI*n/static_cast(neighbors))); + float y = static_cast(radius * cos(2.0*CV_PI*n/static_cast(neighbors))); // relative indices int fx = static_cast(floor(x)); int fy = static_cast(floor(y)); @@ -514,7 +514,7 @@ inline void elbp_(InputArray _src, OutputArray _dst, int radius, int neighbors) for(int i=radius; i < src.rows-radius;i++) { for(int j=radius;j < src.cols-radius;j++) { // calculate interpolated value - float t = w1*src.at<_Tp>(i+fy,j+fx) + w2*src.at<_Tp>(i+fy,j+cx) + w3*src.at<_Tp>(i+cy,j+fx) + w4*src.at<_Tp>(i+cy,j+cx); + float t = static_cast(w1*src.at<_Tp>(i+fy,j+fx) + w2*src.at<_Tp>(i+fy,j+cx) + w3*src.at<_Tp>(i+cy,j+fx) + w4*src.at<_Tp>(i+cy,j+cx)); // floating point precision, so check some machine-dependent epsilon dst.at(i-radius,j-radius) += ((t > src.at<_Tp>(i,j)) || (std::abs(t-src.at<_Tp>(i,j)) < std::numeric_limits::epsilon())) << n; } @@ -543,7 +543,7 @@ histc_(const Mat& src, int minVal=0, int maxVal=255, bool normed=false) // Establish the number of bins. int histSize = maxVal-minVal+1; // Set the ranges. - float range[] = { minVal, maxVal } ; + float range[] = { static_cast(minVal), static_cast(maxVal) }; const float* histRange = { range }; // calc histogram calcHist(&src, 1, 0, Mat(), result, 1, &histSize, &histRange, true, false); diff --git a/modules/contrib/src/spinimages.cpp b/modules/contrib/src/spinimages.cpp index bd0f608..50c7cd7 100644 --- a/modules/contrib/src/spinimages.cpp +++ b/modules/contrib/src/spinimages.cpp @@ -442,7 +442,7 @@ void cv::Mesh3D::clearOctree(){ octree = Octree(); } float cv::Mesh3D::estimateResolution(float tryRatio) { - #if 0 +#if 0 const int neighbors = 3; const int minReasonable = 10; @@ -476,10 +476,10 @@ float cv::Mesh3D::estimateResolution(float tryRatio) sort(dist, less()); return resolution = (float)dist[ dist.size() / 2 ]; - #else +#else CV_Error(CV_StsNotImplemented, ""); return 1.f; - #endif +#endif } @@ -1182,14 +1182,14 @@ private: left.erase(pos); } else - break; + break; } if (group.size() >= 4) - groups.push_back(group); + groups.push_back(group); } - /* converting the data to final result */ + /* converting the data to final result */ for(size_t i = 0; i < groups.size(); ++i) { const group_t& group = groups[i]; @@ -1197,7 +1197,7 @@ private: vector< Vec2i > outgrp; for(citer pos = group.begin(); pos != group.end(); ++pos) { - const Match& m = allMatches[*pos]; + const Match& m = allMatches[*pos]; outgrp.push_back(Vec2i(subset[m.modelInd], scene.subset[m.sceneInd])); } result.push_back(outgrp); diff --git a/modules/core/include/opencv2/core/operations.hpp b/modules/core/include/opencv2/core/operations.hpp index f765f44..83947b2 100644 --- a/modules/core/include/opencv2/core/operations.hpp +++ b/modules/core/include/opencv2/core/operations.hpp @@ -3012,8 +3012,8 @@ public: size_t remaining = it->remaining, cn = DataType<_Tp>::channels; int _fmt = DataType<_Tp>::fmt; char fmt[] = { (char)((_fmt>>8)+'1'), (char)_fmt, '\0' }; - size_t remaining1 = remaining/cn; - count = count < remaining1 ? count : remaining1; + size_t remaining1 = remaining/cn; + count = count < remaining1 ? count : remaining1; vec.resize(count); it->readRaw( string(fmt), !vec.empty() ? (uchar*)&vec[0] : 0, count*sizeof(_Tp) ); } @@ -3030,8 +3030,13 @@ read( FileNodeIterator& it, vector<_Tp>& vec, size_t maxCount=(size_t)INT_MAX ) template static inline void read( const FileNode& node, vector<_Tp>& vec, const vector<_Tp>& default_value=vector<_Tp>() ) { - FileNodeIterator it = node.begin(); - read( it, vec ); + if(!node.node) + vec = default_value; + else + { + FileNodeIterator it = node.begin(); + read( it, vec ); + } } inline FileNodeIterator FileNode::begin() const diff --git a/modules/features2d/src/detectors.cpp b/modules/features2d/src/detectors.cpp index a8e8a15..9b3a668 100644 --- a/modules/features2d/src/detectors.cpp +++ b/modules/features2d/src/detectors.cpp @@ -195,7 +195,7 @@ DenseFeatureDetector::DenseFeatureDetector( float _initFeatureScale, int _featur void DenseFeatureDetector::detectImpl( const Mat& image, vector& keypoints, const Mat& mask ) const { - float curScale = initFeatureScale; + float curScale = static_cast(initFeatureScale); int curStep = initXyStep; int curBound = initImgBound; for( int curLevel = 0; curLevel < featureScaleLevels; curLevel++ ) @@ -208,7 +208,7 @@ void DenseFeatureDetector::detectImpl( const Mat& image, vector& keypo } } - curScale = curScale * featureScaleMul; + curScale = static_cast(curScale * featureScaleMul); if( varyXyStepWithScale ) curStep = static_cast( curStep * featureScaleMul + 0.5f ); if( varyImgBoundWithScale ) curBound = static_cast( curBound * featureScaleMul + 0.5f ); } diff --git a/modules/gpu/CMakeLists.txt b/modules/gpu/CMakeLists.txt index a403b68..5a98fae 100644 --- a/modules/gpu/CMakeLists.txt +++ b/modules/gpu/CMakeLists.txt @@ -33,18 +33,20 @@ if (HAVE_CUDA) #set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-keep") #set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-Xcompiler;/EHsc-;") - foreach(var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG) - string(REPLACE "/W4" "/W3" ${var} "${${var}}") - endforeach() - if(MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4211 /wd4201 /wd4100 /wd4505 /wd4408 /wd4251") + if(NOT ENABLE_NOISY_WARNINGS) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4211 /wd4201 /wd4100 /wd4505 /wd4408") + + foreach(var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG) + string(REPLACE "/W4" "/W3" ${var} "${${var}}") + endforeach() + + set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler /wd4251) + endif() foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_DEBUG CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG) string(REPLACE "/EHsc-" "/EHs" ${var} "${${var}}") endforeach() - - set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler /wd4251) endif() OCV_CUDA_COMPILE(cuda_objs ${lib_cuda} ${ncv_cuda}) diff --git a/modules/gpu/test/utility.cpp b/modules/gpu/test/utility.cpp index 9074494..bc73d30 100644 --- a/modules/gpu/test/utility.cpp +++ b/modules/gpu/test/utility.cpp @@ -195,7 +195,7 @@ Mat getMat(InputArray arr) return arr.getMat(); } -double checkNorm(InputArray m1, const InputArray m2) +double checkNorm(InputArray m1, InputArray m2) { return norm(getMat(m1), getMat(m2), NORM_INF); } diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index 22ff07c..f1b4231 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -267,7 +267,7 @@ set_target_properties(${the_module} PROPERTIES LINK_INTERFACE_LIBRARIES "") ocv_add_precompiled_headers(${the_module}) -if(CMAKE_COMPILER_IS_GNUCXX) +if(CMAKE_COMPILER_IS_GNUCXX AND NOT ENABLE_NOISY_WARNINGS) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations") endif() diff --git a/modules/highgui/src/cap_dshow.cpp b/modules/highgui/src/cap_dshow.cpp index 32b286a..4a6061f 100644 --- a/modules/highgui/src/cap_dshow.cpp +++ b/modules/highgui/src/cap_dshow.cpp @@ -3321,9 +3321,9 @@ bool CvCaptureCAM_DShow::setProperty( int property_id, double value ) { if( width != VI.getWidth(index) || height != VI.getHeight(index) )//|| fourcc != VI.getFourcc(index) ) { - int fps = VI.getFPS(index); + int fps = static_cast(VI.getFPS(index)); VI.stopDevice(index); - VI.setIdealFramerate(index,fps); + VI.setIdealFramerate(index, fps); VI.setupDeviceFourcc(index, width, height, fourcc); } width = height = fourcc = -1; diff --git a/modules/imgproc/src/pyramids.cpp b/modules/imgproc/src/pyramids.cpp index 9bc66f6..81462a6 100644 --- a/modules/imgproc/src/pyramids.cpp +++ b/modules/imgproc/src/pyramids.cpp @@ -308,7 +308,7 @@ pyrDown_( const Mat& _src, Mat& _dst, int borderType ) template void -pyrUp_( const Mat& _src, Mat& _dst, int borderType ) +pyrUp_( const Mat& _src, Mat& _dst, int) { const int PU_SZ = 3; typedef typename CastOp::type1 WT; diff --git a/modules/python/CMakeLists.txt b/modules/python/CMakeLists.txt index a7d1b68..d515aeb 100644 --- a/modules/python/CMakeLists.txt +++ b/modules/python/CMakeLists.txt @@ -70,7 +70,13 @@ set_target_properties(${the_module} PROPERTIES if(MSVC AND NOT BUILD_SHARED_LIBS) set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3") +endif() + +if(MSVC AND NOT ENABLE_NOISY_WARNINGS) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4100") #unreferenced formal parameter + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4127") #conditional expression is constant + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4505") #unreferenced local function has been removed + string(REPLACE "/W4" "/W3" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") endif() if(MSVC) diff --git a/modules/ts/CMakeLists.txt b/modules/ts/CMakeLists.txt index d4f4c52..b623750 100644 --- a/modules/ts/CMakeLists.txt +++ b/modules/ts/CMakeLists.txt @@ -3,7 +3,7 @@ if(IOS) endif() if(MINGW) - set(OPENCV_MODULE_TYPE STATIC) + set(OPENCV_MODULE_TYPE STATIC) endif() set(the_description "The ts module") @@ -13,12 +13,12 @@ ocv_module_include_directories() ocv_create_module() if(BUILD_SHARED_LIBS AND NOT MINGW) - add_definitions(-DGTEST_CREATE_SHARED_LIBRARY=1) - if (MSVC) - add_definitions( "/wd4251 /wd4275") - endif() + add_definitions(-DGTEST_CREATE_SHARED_LIBRARY=1) + if (MSVC AND NOT ENABLE_NOISY_WARNINGS) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4275") + endif() else() - add_definitions(-DGTEST_CREATE_SHARED_LIBRARY=0) + add_definitions(-DGTEST_CREATE_SHARED_LIBRARY=0) endif() ocv_add_precompiled_headers(${the_module}) diff --git a/modules/ts/src/ts_perf.cpp b/modules/ts/src/ts_perf.cpp index 7e6e79d..b9df881 100644 --- a/modules/ts/src/ts_perf.cpp +++ b/modules/ts/src/ts_perf.cpp @@ -147,7 +147,7 @@ void Regression::init(const std::string& testSuitName, const std::string& ext) storageOutPath += ext; } } - catch(cv::Exception& ex) + catch(cv::Exception&) { LOGE("Failed to open sanity data for reading: %s", storageInPath.c_str()); } diff --git a/modules/videostab/src/fast_marching.cpp b/modules/videostab/src/fast_marching.cpp index dd18e2f..70faeb1 100644 --- a/modules/videostab/src/fast_marching.cpp +++ b/modules/videostab/src/fast_marching.cpp @@ -105,7 +105,8 @@ void FastMarchingMethod::heapDown(int idx) if (l < size_ && narrowBand_[l] < narrowBand_[smallest]) smallest = l; if (r < size_ && narrowBand_[r] < narrowBand_[smallest]) smallest = r; - if (smallest == idx) break; + if (smallest == idx) + break; else { std::swap(indexOf(narrowBand_[idx]), indexOf(narrowBand_[smallest])); diff --git a/modules/videostab/src/inpainting.cpp b/modules/videostab/src/inpainting.cpp index 805458d..41703c6 100644 --- a/modules/videostab/src/inpainting.cpp +++ b/modules/videostab/src/inpainting.cpp @@ -292,7 +292,9 @@ public: } Point3_ cp = frame1(py1,px1), cq = frame1(qy1,qx1); - float distColor = sqr(cp.x-cq.x) + sqr(cp.y-cq.y) + sqr(cp.z-cq.z); + float distColor = sqr(static_cast(cp.x-cq.x)) + + sqr(static_cast(cp.y-cq.y)) + + sqr(static_cast(cp.z-cq.z)); float w = 1.f / (sqrt(distColor * (dx*dx + dy*dy)) + eps); uEst += w * (flowX(qy0,qx0) - dudx*dx - dudy*dy); diff --git a/samples/c/CMakeLists.txt b/samples/c/CMakeLists.txt index 68ae9be..13672e7 100644 --- a/samples/c/CMakeLists.txt +++ b/samples/c/CMakeLists.txt @@ -12,7 +12,7 @@ ocv_check_dependencies(${OPENCV_C_SAMPLES_REQUIRED_DEPS}) if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) project(c_samples) - if(CMAKE_COMPILER_IS_GNUCXX) + if(CMAKE_COMPILER_IS_GNUCXX AND NOT ENABLE_NOISY_WARNINGS) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function") endif() diff --git a/samples/cpp/CMakeLists.txt b/samples/cpp/CMakeLists.txt index 029f759..3f4bb6a 100644 --- a/samples/cpp/CMakeLists.txt +++ b/samples/cpp/CMakeLists.txt @@ -20,7 +20,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/gpu/include") endif() - if(CMAKE_COMPILER_IS_GNUCXX) + if(CMAKE_COMPILER_IS_GNUCXX AND NOT ENABLE_NOISY_WARNINGS) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function") endif() diff --git a/samples/gpu/CMakeLists.txt b/samples/gpu/CMakeLists.txt index 0f4ec25..c1bf36b 100644 --- a/samples/gpu/CMakeLists.txt +++ b/samples/gpu/CMakeLists.txt @@ -21,7 +21,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) ocv_include_directories(${CUDA_INCLUDE_DIRS}) endif() - if(CMAKE_COMPILER_IS_GNUCXX) + if(CMAKE_COMPILER_IS_GNUCXX AND NOT ENABLE_NOISY_WARNINGS) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function") endif() -- 2.7.4