Skip to content

Commit

Permalink
Add MinGW support (not full yet).
Browse files Browse the repository at this point in the history
TODO list:
* Fix tests compilation (undefined reference to CppUnit::...)
* Fix SQLs compilation (No rule to make target '${LIBNAME}.dll.a', needed by '${LIBNAME}.dll'.  Stop.)
* Fix crypto executables compilation
* Test static compilation
* Test MSVC compilation
* Add unicode support

See pocoproject#2356
  • Loading branch information
ark0f committed Jun 2, 2018
1 parent 94576ba commit a7380c1
Show file tree
Hide file tree
Showing 44 changed files with 188 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CppParser/include/Poco/CppParser/CppParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
// CppParser_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
//
#if defined(__MINGW32__) && defined(POCO_DLL)
#define CppParser_EXPORTS
#endif

#if (defined(_WIN32) || defined(__CYGWIN__)) && defined(POCO_DLL)
#if defined(CppParser_EXPORTS)
#define CppParser_API __declspec(dllexport)
Expand Down
4 changes: 4 additions & 0 deletions CppUnit/include/Poco/CppUnit/CppUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
// CppUnit_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
//
#if defined(__MINGW32__) && defined(POCO_DLL)
#define CppUnit_EXPORTS
#endif

#if defined(_WIN32) && defined(POCO_DLL)
#if defined(CppUnit_EXPORTS)
#define CppUnit_API __declspec(dllexport)
Expand Down
4 changes: 4 additions & 0 deletions Crypto/include/Poco/Crypto/Crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ enum RSAPaddingMode
// Crypto_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
//
#if defined(__MINGW32__) && defined(POCO_DLL)
#define Crypto_EXPORTS
#endif

#if defined(_WIN32)
#if defined(POCO_DLL)
#if defined(Crypto_EXPORTS)
Expand Down
5 changes: 5 additions & 0 deletions Crypto/samples/genrsakey/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
set(SAMPLE_NAME "genrsakey")

# Set flags to enable unicode
if(MINGW)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -municode")
endif()

set(LOCAL_SRCS "")
aux_source_directory(src LOCAL_SRCS)

Expand Down
5 changes: 5 additions & 0 deletions Encodings/Compiler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
set(POCO_EXENAME "EncodingsCompiler")

# Set flags to enable unicode
if(MINGW)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -municode")
endif()

# Sources
file(GLOB SRCS_G "src/*.cpp")
POCO_SOURCES_AUTO( SRCS ${SRCS_G})
Expand Down
4 changes: 4 additions & 0 deletions Encodings/include/Poco/Encodings.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
// Encodings_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
//
#if defined(__MINGW32__) && defined(POCO_DLL)
#define Encodings_EXPORTS
#endif

#if defined(_WIN32) && defined(POCO_DLL)
#if defined(Encodings_EXPORTS)
#define Encodings_API __declspec(dllexport)
Expand Down
6 changes: 5 additions & 1 deletion Foundation/include/Poco/Foundation.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
//
// Ensure that POCO_DLL is default unless POCO_STATIC is defined
//
#if defined(_WIN32) && defined(_DLL)
#if defined(_WIN32) && (defined(_DLL) || defined(__MINGW32__))
#if !defined(POCO_DLL) && !defined(POCO_STATIC)
#define POCO_DLL
#endif
Expand All @@ -44,6 +44,10 @@
// Foundation_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
//
#if defined(__MINGW32__) && defined(POCO_DLL)
#define Foundation_EXPORTS
#endif

#if (defined(_WIN32) || defined(_WIN32_WCE)) && defined(POCO_DLL)
#if defined(Foundation_EXPORTS)
#define Foundation_API __declspec(dllexport)
Expand Down
1 change: 0 additions & 1 deletion Foundation/include/Poco/UnWindows.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
#include <windows.h>
#ifdef __MINGW32__
#include <Winsock2.h>
#include <Iphlpapi.h>
#include <ws2tcpip.h>
#endif // __MINGW32__
#endif
Expand Down
12 changes: 10 additions & 2 deletions Foundation/src/Error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,19 @@ namespace Poco {
{
std::string errMsg;
DWORD dwFlg = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS;
#if !defined(POCO_NO_WSTRING)

LPWSTR lpMsgBuf = 0;
if (FormatMessageW(dwFlg, 0, errorCode, 0, (LPWSTR) & lpMsgBuf, 0, NULL))
if (FormatMessageW(dwFlg, 0, errorCode, 0, (LPWSTR) & lpMsgBuf, 0, NULL)) {
#if !defined(POCO_NO_WSTRING)
UnicodeConverter::toUTF8(lpMsgBuf, errMsg);
#else
std::wstring filename = lpMsgBuf;
int size = WideCharToMultiByte(CP_UTF8, 0, &filename[0], (int) filename.size(), NULL, 0, NULL, NULL);
errMsg.resize(size);
WideCharToMultiByte(CP_UTF8, 0, &filename[0], (int) filename.size(), &errMsg[0], (int) errMsg.size(),
NULL, NULL);
#endif
}
LocalFree(lpMsgBuf);
return errMsg;
}
Expand Down
8 changes: 5 additions & 3 deletions Foundation/src/Thread_STD_WIN32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#include "Poco/Thread_STD.h"
#include "Poco/Thread.h"
#include "Poco/Exception.h"

#if defined(POCO_OS_FAMILY_WINDOWS)
#include "Poco/UnWindows.h"
#endif

namespace Poco {

Expand All @@ -28,7 +30,7 @@ void ThreadImpl::setPriorityImpl(int prio)
_pData->policy = 0;
if (_pData->started && !_pData->joined && _pData->thread)
{
if (SetThreadPriority(_pData->thread->native_handle(), _pData->prio) == 0)
if (SetThreadPriority((HANDLE) _pData->thread->native_handle(), _pData->prio) == 0)
throw SystemException("cannot set thread priority");
}
}
Expand Down Expand Up @@ -66,7 +68,7 @@ void ThreadImpl::setAffinityImpl(int cpu)
mask <<= cpu;
if (_pData->started && !_pData->joined && _pData->thread)
{
if (SetThreadAffinityMask(_pData->thread->native_handle(), mask) == 0)
if (SetThreadAffinityMask((HANDLE) _pData->thread->native_handle(), mask) == 0)
{
throw SystemException("Failed to set affinity");
}
Expand Down
3 changes: 3 additions & 0 deletions Foundation/testsuite/src/FileTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include <set>


#define MAX_PATH 260


using Poco::File;
using Poco::TemporaryFile;
using Poco::Path;
Expand Down
4 changes: 4 additions & 0 deletions JSON/include/Poco/JSON/JSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
// JSON_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
//
#if defined(__MINGW32__) && defined(POCO_DLL)
#define JSON_EXPORTS
#endif

#if defined(_WIN32) && defined(POCO_DLL)
#if defined(JSON_EXPORTS)
#define JSON_API __declspec(dllexport)
Expand Down
4 changes: 3 additions & 1 deletion MongoDB/include/Poco/MongoDB/MongoDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
// MongoDB_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
//

#if defined(__MINGW32__) && defined(POCO_DLL)
#define MongoDB_EXPORTS
#endif

#if defined(_WIN32) && defined(POCO_DLL)
#if defined(MongoDB_EXPORTS)
Expand Down
2 changes: 1 addition & 1 deletion MongoDB/include/Poco/MongoDB/UpdateRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Poco {
namespace MongoDB {


class UpdateRequest: public RequestMessage
class MongoDB_API UpdateRequest: public RequestMessage
/// This request is used to update a document in a database
/// using the OP_UPDATE client request.
{
Expand Down
4 changes: 2 additions & 2 deletions Net/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ POCO_HEADERS_AUTO( SRCS ${HDRS_G})
# Windows and WindowsCE need additional libraries
if(WIN32)
if(WINCE)
set(SYSLIBS ${SYSLIBS} "ws2.lib" "iphlpapi.lib")
set(SYSLIBS ${SYSLIBS} "ws2" "iphlpapi")
else()
set(SYSLIBS ${SYSLIBS} "ws2_32.lib" "iphlpapi.lib")
set(SYSLIBS ${SYSLIBS} "ws2_32" "iphlpapi")
endif()
endif(WIN32)

Expand Down
4 changes: 4 additions & 0 deletions Net/include/Poco/Net/Net.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
// Net_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
//
#if defined(__MINGW32__) && defined(POCO_DLL)
#define Net_EXPORTS
#endif

#if defined(_WIN32) && defined(POCO_DLL)
#if defined(Net_EXPORTS)
#define Net_API __declspec(dllexport)
Expand Down
5 changes: 5 additions & 0 deletions Net/samples/WebSocketServer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
set(SAMPLE_NAME "WebSocketServer")

# Set flags to enable unicode
if(MINGW)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -municode")
endif()

set(LOCAL_SRCS "")
aux_source_directory(src LOCAL_SRCS)

Expand Down
3 changes: 1 addition & 2 deletions Net/src/PollSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <set>


#if defined(_WIN32) && _WIN32_WINNT >= 0x0600
#if defined(_WIN32) && _WIN32_WINNT >= 0x0600 && !defined(__MINGW32__)
#ifndef POCO_HAVE_FD_POLL
#define POCO_HAVE_FD_POLL 1
#endif
Expand All @@ -44,7 +44,6 @@
namespace Poco {
namespace Net {


#if defined(POCO_HAVE_FD_EPOLL)


Expand Down
4 changes: 4 additions & 0 deletions NetSSL_OpenSSL/include/Poco/Net/NetSSL.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
// NetSSL_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
//
#if defined(__MINGW32__) && defined(POCO_DLL)
#define NetSSL_EXPORTS
#endif

#if defined(_WIN32)
#if defined(POCO_DLL)
#if defined(NetSSL_EXPORTS)
Expand Down
5 changes: 5 additions & 0 deletions NetSSL_OpenSSL/samples/TwitterClient/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
set(SAMPLE_NAME "TwitterCLient")

# Set flags to enable unicode
if(MINGW)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -municode")
endif()

set(LOCAL_SRCS "")
aux_source_directory(src LOCAL_SRCS)

Expand Down
4 changes: 4 additions & 0 deletions NetSSL_Win/include/Poco/Net/NetSSL.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
// NetSSL_Win_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
//
#if defined(__MINGW32__) && defined(POCO_DLL)
#define NetSSL_Win_EXPORTS
#endif

#if (defined(_WIN32) || defined(__CYGWIN__)) && defined(POCO_DLL)
#if defined(NetSSL_Win_EXPORTS)
#define NetSSL_Win_API __declspec(dllexport)
Expand Down
2 changes: 1 addition & 1 deletion NetSSL_Win/samples/HTTPSTimeServer/src/HTTPSTimeServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class TimeRequestHandler: public HTTPRequestHandler
SecureStreamSocket socket = static_cast<HTTPServerRequestImpl&>(request).socket();
if (socket.havePeerCertificate())
{
X509Certificate cert = socket.peerCertificate();
auto cert = socket.peerCertificate();
app.logger().information("Client certificate: " + cert.subjectName());
}
else
Expand Down
15 changes: 12 additions & 3 deletions NetSSL_Win/src/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ void Context::init()
_hMemCertStore = CertOpenStore(
CERT_STORE_PROV_MEMORY, // The memory provider type
0, // The encoding type is not needed
NULL, // Use the default provider
#ifdef _MSC_VER // Use the default provider
NULL,
#else
0,
#endif
0, // Accept the default dwFlags
NULL); // pvPara is not used

Expand All @@ -101,7 +105,11 @@ void Context::init()
_hCollectionCertStore = CertOpenStore(
CERT_STORE_PROV_COLLECTION, // A collection store
0, // Encoding type; not used with a collection store
NULL, // Use the default provider
#ifdef _MSC_VER // Use the default provider
NULL,
#else
0,
#endif
0, // No flags
NULL); // Not needed

Expand Down Expand Up @@ -270,7 +278,8 @@ void Context::acquireSchannelCredentials(CredHandle& credHandle) const
if (_pCert)
{
schannelCred.cCreds = 1; // how many cred are stored in &pCertContext
schannelCred.paCred = &const_cast<PCCERT_CONTEXT>(_pCert);
auto ppContext = const_cast<PCCERT_CONTEXT*>(&_pCert);
schannelCred.paCred = ppContext;
}

schannelCred.grbitEnabledProtocols = proto();
Expand Down
4 changes: 4 additions & 0 deletions PDF/include/Poco/PDF/PDF.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
// PDF_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
//
#if defined(__MINGW32__) && defined(POCO_DLL)
#define PDF_EXPORTS
#endif

#if defined(_WIN32) && defined(POCO_DLL)
#if defined(PDF_EXPORTS)
#define PDF_API __declspec(dllexport)
Expand Down
5 changes: 5 additions & 0 deletions PageCompiler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
set(POCO_EXENAME "PageCompiler")

# Set flags to enable unicode
if(MINGW)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -municode")
endif()

# Sources
file(GLOB SRCS_G "src/*.cpp")
POCO_SOURCES_AUTO( SRCS ${SRCS_G})
Expand Down
5 changes: 5 additions & 0 deletions PageCompiler/File2Page/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
set(POCO_EXENAME "File2Page")

# Set flags to enable unicode
if(MINGW)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -municode")
endif()

# Sources
file(GLOB SRCS_G "src/*.cpp")
POCO_SOURCES_AUTO( SRCS ${SRCS_G})
Expand Down
4 changes: 4 additions & 0 deletions Redis/include/Poco/Redis/Redis.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
// Redis_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
//
#if defined(__MINGW32__) && defined(POCO_DLL)
#define Redis_EXPORTS
#endif

#if defined(_WIN32) && defined(POCO_DLL)
#if defined(Redis_EXPORTS)
#define Redis_API __declspec(dllexport)
Expand Down
6 changes: 6 additions & 0 deletions SQL/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
set(LIBNAME "SQL")
set(POCO_LIBNAME "Poco${LIBNAME}")

# Fix error "too many sections"
if(MINGW)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wa,-mbig-obj")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wa,-mbig-obj")
endif()

# Sources
file(GLOB SRCS_G "src/*.cpp")
POCO_SOURCES_AUTO( SRCS ${SRCS_G})
Expand Down
4 changes: 4 additions & 0 deletions SQL/MySQL/include/Poco/SQL/MySQL/MySQL.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
// ODBC_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
//
#if defined(__MINGW32__) && defined(POCO_DLL)
#define MySQL_EXPORTS
#endif

#if defined(_WIN32) && defined(POCO_DLL)
#if defined(MySQL_EXPORTS)
#define MySQL_API __declspec(dllexport)
Expand Down
5 changes: 5 additions & 0 deletions SQL/ODBC/include/Poco/SQL/ODBC/ODBC.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
// ODBC_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
//
#if defined(__MINGW32__) && defined(POCO_DLL)
#define ODBC_EXPORTS
#endif


#if defined(_WIN32) && defined(POCO_DLL)
#if defined(ODBC_EXPORTS)
#define ODBC_API __declspec(dllexport)
Expand Down
Loading

0 comments on commit a7380c1

Please sign in to comment.