Skip to content

Commit 03fe1cb

Browse files
author
Hugo Lindström
committed
Support building shared libraries on WINCE.
1 parent 4dadf17 commit 03fe1cb

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

cmake/templates/dllmain.cpp.in

+8-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@ namespace cv {
1818
extern __declspec(dllimport) bool __termination; // Details: #12750
1919
}
2020

21+
#ifdef _WIN32_WCE
22+
#define DLL_MAIN_ARG0 HANDLE
23+
#else
24+
#define DLL_MAIN_ARG0 HINSTANCE
25+
#endif
26+
2127
extern "C"
22-
BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID lpReserved);
28+
BOOL WINAPI DllMain(DLL_MAIN_ARG0, DWORD fdwReason, LPVOID lpReserved);
2329

2430
extern "C"
25-
BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID lpReserved)
31+
BOOL WINAPI DllMain(DLL_MAIN_ARG0, DWORD fdwReason, LPVOID lpReserved)
2632
{
2733
if (fdwReason == DLL_THREAD_DETACH || fdwReason == DLL_PROCESS_DETACH)
2834
{

modules/core/src/glob.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,15 @@ const char dir_separators[] = "/";
139139

140140
static bool isDir(const cv::String& path, DIR* dir)
141141
{
142-
#if defined _WIN32 || defined WINCE
142+
#if defined _WIN32 || defined _WIN32_WCE
143143
DWORD attributes;
144144
BOOL status = TRUE;
145145
if (dir)
146146
attributes = dir->data.dwFileAttributes;
147147
else
148148
{
149149
WIN32_FILE_ATTRIBUTE_DATA all_attrs;
150-
#ifdef WINRT
150+
#if defined WINRT || defined _WIN32_WCE
151151
wchar_t wpath[MAX_PATH];
152152
size_t copied = mbstowcs(wpath, path.c_str(), MAX_PATH);
153153
CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1));

modules/core/src/utils/datafile.cpp

+11-4
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,20 @@ static cv::String getModuleLocation(const void* addr)
115115
#endif
116116
if (m)
117117
{
118-
char path[MAX_PATH];
119-
const size_t path_size = sizeof(path)/sizeof(*path);
120-
size_t sz = GetModuleFileNameA(m, path, path_size); // no unicode support
118+
TCHAR path[MAX_PATH];
119+
const size_t path_size = sizeof(path) / sizeof(*path);
120+
size_t sz = GetModuleFileName(m, path, path_size);
121121
if (sz > 0 && sz < path_size)
122122
{
123-
path[sz] = '\0';
123+
path[sz] = TCHAR('\0');
124+
#ifdef _UNICODE
125+
char char_path[MAX_PATH];
126+
size_t copied = wcstombs(char_path, path, MAX_PATH);
127+
CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1));
128+
return cv::String(char_path);
129+
#else
124130
return cv::String(path);
131+
#endif
125132
}
126133
}
127134
#elif defined(__linux__)

platforms/wince/arm-wince-headless-overrides.cmake

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ if(WINCE)
33
# Try_Compile succeed and therefore also C/C++ ABI Detetection work
44
# https://gitlab.kitware.com/cmake/cmake/blob/master/Modules/Platform/Windows-
55
# MSVC.cmake
6-
set(CMAKE_C_STANDARD_LIBRARIES_INIT "coredll.lib")
6+
set(CMAKE_C_STANDARD_LIBRARIES_INIT "coredll.lib oldnames.lib")
77
set(CMAKE_CXX_STANDARD_LIBRARIES_INIT ${CMAKE_C_STANDARD_LIBRARIES_INIT})
88
foreach(ID EXE SHARED MODULE)
99
string(APPEND CMAKE_${ID}_LINKER_FLAGS_INIT
10-
" /NODEFAULTLIB:libc.lib /NODEFAULTLIB:oldnames.lib")
10+
" /NODEFAULTLIB:libc.lib")
1111
endforeach()
1212
endif()

platforms/wince/readme.md

+8
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ For headless WEC2013, this configuration may not be limited to but is known to w
5757
-DWITH_TIFF=OFF `
5858
```
5959

60+
## Configuring to build as shared
61+
Building OpenCV as shared libraries is as easy as appending
62+
```
63+
-DBUILD_SHARED_LIBS=ON `
64+
-DBUILD_ZLIB=ON
65+
```
66+
to the build configuration.
67+
6068
## Building
6169
You are required to build using Unicode:
6270
`cmake --build . -- /p:CharacterSet=Unicode`

0 commit comments

Comments
 (0)