From 63786c389fe9462141005e55ae4837ff6fed9d5c Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Mon, 29 Jul 2013 04:38:18 -0700 Subject: [PATCH] Warning and review notes fixes. WITH_WINRT -> ENABLE_WINRT_MODE; Some temporary char* replaced with Ptr; Build fix for regular WIN32; Windows Platform SDK and MSVC search added to cmake; Warinig fixes. --- CMakeLists.txt | 13 ++++++++-- cmake/OpenCVCRTLinkage.cmake | 37 +++++++++++++++++++++------- cmake/checks/winrttest.cpp | 6 +++++ modules/contrib/src/inputoutput.cpp | 35 +++++++++++++------------- modules/core/CMakeLists.txt | 2 +- modules/core/src/glob.cpp | 10 +++----- modules/core/src/system.cpp | 24 +++++++++--------- modules/core/test/test_main.cpp | 4 +++ modules/ts/include/opencv2/ts/ts.hpp | 4 +++ 9 files changed, 89 insertions(+), 46 deletions(-) create mode 100644 cmake/checks/winrttest.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 419cc68e27..46881c4531 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -147,7 +147,6 @@ OCV_OPTION(WITH_PVAPI "Include Prosilica GigE support" ON OCV_OPTION(WITH_GIGEAPI "Include Smartek GigE support" ON IF (NOT ANDROID AND NOT IOS) ) OCV_OPTION(WITH_QT "Build with Qt Backend support" OFF IF (NOT ANDROID AND NOT IOS) ) OCV_OPTION(WITH_WIN32UI "Build with Win32 UI Backend support" ON IF WIN32 ) -OCV_OPTION(WITH_WINRT "Build with Windows Runtime support" OFF IF WIN32 ) OCV_OPTION(WITH_QUICKTIME "Use QuickTime for Video I/O insted of QTKit" OFF IF APPLE ) OCV_OPTION(WITH_TBB "Include Intel TBB support" OFF IF (NOT IOS) ) OCV_OPTION(WITH_CSTRIPES "Include C= support" OFF IF WIN32 ) @@ -213,7 +212,7 @@ OCV_OPTION(ENABLE_SSE42 "Enable SSE4.2 instructions" OCV_OPTION(ENABLE_AVX "Enable AVX instructions" OFF IF ((MSVC OR 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 ) - +OCV_OPTION(ENABLE_WINRT_MODE "Build with Windows Runtime support" OFF IF WIN32 ) # uncategorized options # =================================================== @@ -604,6 +603,16 @@ if(ANDROID) status(" Android examples:" BUILD_ANDROID_EXAMPLES AND CAN_BUILD_ANDROID_PROJECTS THEN YES ELSE NO) endif() +# ================== Windows RT features ================== +if(WIN32) +status("") + status(" Windows RT support:" HAVE_WINRT THEN YES ELSE NO) + if (ENABLE_WINRT_MODE) + status(" Windows SDK v8.0:" ${WINDOWS_SDK_PATH}) + status(" Visual Studio 2012:" ${VISUAL_STUDIO_PATH}) + endif() +endif(WIN32) + # ========================== GUI ========================== status("") status(" GUI: ") diff --git a/cmake/OpenCVCRTLinkage.cmake b/cmake/OpenCVCRTLinkage.cmake index d5e4f27e9d..295b914b68 100644 --- a/cmake/OpenCVCRTLinkage.cmake +++ b/cmake/OpenCVCRTLinkage.cmake @@ -4,18 +4,37 @@ endif() #INCLUDE (CheckIncludeFiles) -if (WITH_WINRT) - #CHECK_INCLUDE_FILES("wrl/client.h" HAVE_WINRT) - TRY_COMPILE(HAVE_WINRT - "${OPENCV_BINARY_DIR}/CMakeFiles/CMakeTmp" - "${OpenCV_SOURCE_DIR}/cmake/checks/winrttest.cpp" - CMAKE_FLAGS "\"kernel.lib\" \"user32.lib\"" - OUTPUT_VARIABLE OUTPUT) +if (ENABLE_WINRT_MODE) + set(HAVE_WINRT True) + + # search Windows Platform SDK + message(STATUS "Checking for Windows Platfrom SDK") + GET_FILENAME_COMPONENT(WINDOWS_SDK_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v8.0;InstallationFolder]" ABSOLUTE CACHE) + if (WINDOWS_SDK_PATH STREQUAL "") + message(ERROR "Windows Platform SDK 8.0 was not found!") + set(HAVE_WINRT False) + endif() + + #search for Visual Studio 11.0 install directory + message(STATUS "Checking for Visual Studio 2012") + GET_FILENAME_COMPONENT(VISUAL_STUDIO_PATH [HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\11.0\\Setup\\VS;ProductDir] REALPATH CACHE) + if (VISUAL_STUDIO_PATH STREQUAL "") + message(ERROR "Visual Studio 2012 was not found!") + set(HAVE_WINRT False) + endif() + + if (HAVE_WINRT) + TRY_COMPILE(HAVE_WINRT + "${OPENCV_BINARY_DIR}/CMakeFiles/CMakeTmp" + "${OpenCV_SOURCE_DIR}/cmake/checks/winrttest.cpp" + CMAKE_FLAGS "\"kernel.lib\" \"user32.lib\"" + OUTPUT_VARIABLE OUTPUT) + endif() + if (HAVE_WINRT) add_definitions(/DWINVER=0x0602 /DNTDDI_VERSION=NTDDI_WIN8 /D_WIN32_WINNT=0x0602) endif() - message(STATUS "Windows RT: ${HAVE_WINRT}") -endif(WITH_WINRT) +endif(ENABLE_WINRT_MODE) if(NOT BUILD_SHARED_LIBS AND BUILD_WITH_STATIC_CRT) foreach(flag_var diff --git a/cmake/checks/winrttest.cpp b/cmake/checks/winrttest.cpp new file mode 100644 index 0000000000..4172afe557 --- /dev/null +++ b/cmake/checks/winrttest.cpp @@ -0,0 +1,6 @@ +#include + +int main(int, char**) +{ + return 0; +} \ No newline at end of file diff --git a/modules/contrib/src/inputoutput.cpp b/modules/contrib/src/inputoutput.cpp index f545d15f70..e04740faee 100644 --- a/modules/contrib/src/inputoutput.cpp +++ b/modules/contrib/src/inputoutput.cpp @@ -20,17 +20,16 @@ namespace cv #ifdef HAVE_WINRT WIN32_FIND_DATAW FindFileData; #else - WIN32_FIND_DATA FindFileData; + WIN32_FIND_DATAA FindFileData; #endif HANDLE hFind; #ifdef HAVE_WINRT size_t size = mbstowcs(NULL, path_f.c_str(), path_f.size()); - wchar_t* wpath = (wchar_t*)malloc((size+1)*sizeof(wchar_t)); + Ptr wpath = new wchar_t[size+1]; wpath[size] = 0; mbstowcs(wpath, path_f.c_str(), path_f.size()); hFind = FindFirstFileExW(wpath, FindExInfoStandard, &FindFileData, FindExSearchNameMatch, NULL, 0); - free(wpath); #else hFind = FindFirstFileA((LPCSTR)path_f.c_str(), &FindFileData); #endif @@ -48,22 +47,19 @@ namespace cv FindFileData.dwFileAttributes == FILE_ATTRIBUTE_SYSTEM || FindFileData.dwFileAttributes == FILE_ATTRIBUTE_READONLY) { - char* fname; + cv::Ptr fname; #ifdef HAVE_WINRT size_t asize = wcstombs(NULL, FindFileData.cFileName, 0); - fname = (char*)malloc((asize+1)*sizeof(char)); + fname = new char[asize+1]; fname[asize] = 0; wcstombs(fname, FindFileData.cFileName, asize); #else fname = FindFileData.cFileName; #endif if (addPath) - list.push_back(path + "/" + fname); + list.push_back(path + "/" + std::string(fname)); else - list.push_back(fname); - #ifdef HAVE_WINRT - free(fname); - #endif + list.push_back(std::string(fname)); } } #ifdef HAVE_WINRT @@ -108,17 +104,16 @@ namespace cv #ifdef HAVE_WINRT WIN32_FIND_DATAW FindFileData; #else - WIN32_FIND_DATA FindFileData; + WIN32_FIND_DATAA FindFileData; #endif HANDLE hFind; #ifdef HAVE_WINRT size_t size = mbstowcs(NULL, path_f.c_str(), path_f.size()); - wchar_t* wpath = (wchar_t*)malloc((size+1)*sizeof(wchar_t)); + Ptr wpath = new wchar_t[size+1]; wpath[size] = 0; mbstowcs(wpath, path_f.c_str(), path_f.size()); hFind = FindFirstFileExW(wpath, FindExInfoStandard, &FindFileData, FindExSearchNameMatch, NULL, 0); - free(wpath); #else hFind = FindFirstFileA((LPCSTR)path_f.c_str(), &FindFileData); #endif @@ -130,14 +125,20 @@ namespace cv { do { +#ifdef HAVE_WINRT if (FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY && wcscmp(FindFileData.cFileName, L".") != 0 && wcscmp(FindFileData.cFileName, L"..") != 0) +#else + if (FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY && + strcmp(FindFileData.cFileName, ".") != 0 && + strcmp(FindFileData.cFileName, "..") != 0) +#endif { - char* fname; + cv::Ptr fname; #ifdef HAVE_WINRT size_t asize = wcstombs(NULL, FindFileData.cFileName, 0); - fname = (char*)malloc((asize+1)*sizeof(char)); + fname = new char[asize+1]; fname[asize] = 0; wcstombs(fname, FindFileData.cFileName, asize); #else @@ -145,9 +146,9 @@ namespace cv #endif if (addPath) - list.push_back(path + "/" + fname); + list.push_back(path + "/" + std::string(fname)); else - list.push_back(fname); + list.push_back(std::string(fname)); } } #ifdef HAVE_WINRT diff --git a/modules/core/CMakeLists.txt b/modules/core/CMakeLists.txt index 8b61232040..fe13daabbc 100644 --- a/modules/core/CMakeLists.txt +++ b/modules/core/CMakeLists.txt @@ -3,7 +3,7 @@ ocv_add_module(core ${ZLIB_LIBRARIES}) ocv_module_include_directories(${ZLIB_INCLUDE_DIR}) if (HAVE_WINRT) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /ZW /GS /Gm- /AI\"C:/Program Files/Windows Kits/8.0/References/CommonConfiguration/Neutral\" /AI\"C:/Program Files/Microsoft Visual Studio 11.0/VC/vcpackages\"") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /ZW /GS /Gm- /AI\"${WINDOWS_SDK_PATH}/References/CommonConfiguration/Neutral\" /AI\"${VISUAL_STUDIO_PATH}/vcpackages\"") endif() if(HAVE_CUDA) diff --git a/modules/core/src/glob.cpp b/modules/core/src/glob.cpp index b531832a44..e39cba0163 100644 --- a/modules/core/src/glob.cpp +++ b/modules/core/src/glob.cpp @@ -68,7 +68,7 @@ namespace ~DIR() { if (ent.d_name) - free((void*)ent.d_name); + delete[] ent.d_name; } #endif }; @@ -80,12 +80,11 @@ namespace #ifdef HAVE_WINRT cv::String full_path = cv::String(path) + "\\*"; size_t size = mbstowcs(NULL, full_path.c_str(), full_path.size()); - wchar_t* wfull_path = (wchar_t*)malloc((size+1)*sizeof(wchar_t)); + cv::Ptr wfull_path = new wchar_t[size+1]; wfull_path[size] = 0; mbstowcs(wfull_path, full_path.c_str(), full_path.size()); dir->handle = ::FindFirstFileExW(wfull_path, FindExInfoStandard, &dir->data, FindExSearchNameMatch, NULL, 0); - free(wfull_path); #else dir->handle = ::FindFirstFileExA((cv::String(path) + "\\*").c_str(), FindExInfoStandard, &dir->data, FindExSearchNameMatch, NULL, 0); @@ -107,7 +106,7 @@ namespace return 0; } size_t asize = wcstombs(NULL, dir->data.cFileName, 0); - char* aname = (char*)malloc((asize+1)*sizeof(char)); + char* aname = new char[asize+1]; aname[asize] = 0; wcstombs(aname, dir->data.cFileName, asize); dir->ent.d_name = aname; @@ -148,11 +147,10 @@ static bool isDir(const cv::String& path, DIR* dir) WIN32_FILE_ATTRIBUTE_DATA all_attrs; #ifdef HAVE_WINRT size_t size = mbstowcs(NULL, path.c_str(), path.size()); - wchar_t* wpath = (wchar_t*)malloc((size+1)*sizeof(wchar_t)); + cv::Ptr wpath = new wchar_t[size+1]; wpath[size] = 0; mbstowcs(wpath, path.c_str(), path.size()); ::GetFileAttributesExW(wpath, GetFileExInfoStandard, &all_attrs); - free(wpath); #else ::GetFileAttributesExA(path.c_str(), GetFileExInfoStandard, &all_attrs); #endif diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index 9279f4a224..7e01ca5ea4 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -89,15 +89,14 @@ std::wstring GetTempPathWinRT() std::wstring GetTempFileNameWinRT(std::wstring prefix) { - wchar_t guidStr[120]; - GUID* g = 0x00; - g = new GUID; - CoCreateGuid(g); + wchar_t guidStr[40]; + GUID g; + CoCreateGuid(&g); wchar_t* mask = L"%08x_%04x_%04x_%02x%02x_%02x%02x%02x%02x%02x%02x"; - swprintf(&guidStr[0],mask, 120, g->Data1,g->Data2,g->Data3,UINT(g->Data4[0]), - UINT(g->Data4[1]),UINT(g->Data4[2]),UINT(g->Data4[3]),UINT(g->Data4[4]), - UINT(g->Data4[5]),UINT(g->Data4[6]),UINT(g->Data4[7])); - delete g; + swprintf(&guidStr[0], sizeof(guidStr)/sizeof(wchar_t), mask, + g.Data1, g.Data2, g.Data3, UINT(g.Data4[0]), UINT(g.Data4[1]), + UINT(g.Data4[2]), UINT(g.Data4[3]), UINT(g.Data4[4]), + UINT(g.Data4[5]), UINT(g.Data4[6]), UINT(g.Data4[7])); return prefix + std::wstring(guidStr); } @@ -389,7 +388,7 @@ string tempfile( const char* suffix ) { #ifdef HAVE_WINRT std::wstring temp_dir = L""; - wchar_t* opencv_temp_dir = _wgetenv(L"OPENCV_TEMP_PATH"); + const wchar_t* opencv_temp_dir = _wgetenv(L"OPENCV_TEMP_PATH"); if (opencv_temp_dir) temp_dir = std::wstring(opencv_temp_dir); #else @@ -413,11 +412,10 @@ string tempfile( const char* suffix ) DeleteFileW(temp_file.c_str()); size_t asize = wcstombs(NULL, temp_file.c_str(), 0); - char* aname = (char*)malloc((asize+1)*sizeof(char)); + Ptr aname = new char[asize+1]; aname[asize] = 0; wcstombs(aname, temp_file.c_str(), asize); fname = std::string(aname); - free(aname); RoUninitialize(); #else char temp_dir2[MAX_PATH + 1] = { 0 }; @@ -804,6 +802,10 @@ cvGetModuleInfo( const char* name, const char **version, const char **plugin_lis } #if defined CVAPI_EXPORTS && defined WIN32 && !defined WINCE +#ifdef HAVE_WINRT + #pragma warning(disable:4447) // Disable warning 'main' signature found without threading model +#endif + BOOL WINAPI DllMain( HINSTANCE, DWORD fdwReason, LPVOID ); BOOL WINAPI DllMain( HINSTANCE, DWORD fdwReason, LPVOID ) diff --git a/modules/core/test/test_main.cpp b/modules/core/test/test_main.cpp index 6b24993447..3294fab2b0 100644 --- a/modules/core/test/test_main.cpp +++ b/modules/core/test/test_main.cpp @@ -1,3 +1,7 @@ +#ifdef HAVE_WINRT + #pragma warning(disable:4447) // Disable warning 'main' signature found without threading model +#endif + #include "test_precomp.hpp" CV_TEST_MAIN("cv") diff --git a/modules/ts/include/opencv2/ts/ts.hpp b/modules/ts/include/opencv2/ts/ts.hpp index eafcb89023..384046fd77 100644 --- a/modules/ts/include/opencv2/ts/ts.hpp +++ b/modules/ts/include/opencv2/ts/ts.hpp @@ -10,6 +10,10 @@ #include // for va_list +#ifdef HAVE_WINRT + #pragma warning(disable:4447) // Disable warning 'main' signature found without threading model +#endif + #ifdef _MSC_VER #pragma warning( disable: 4127 ) #endif