Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MinGW support #2360

Merged
merged 18 commits into from
Jun 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CppUnit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ if(NOT BUILD_SHARED_LIBS)
)
endif()

if(BUILD_SHARED_LIBS AND MINGW)
target_compile_definitions(CppUnit PUBLIC _DLL)
endif()

POCO_INSTALL(CppUnit)

configure_file(PocoCppUnit.pc.in ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/pkgconfig/PocoCppUnit.pc @ONLY)
Expand Down
2 changes: 1 addition & 1 deletion Crypto/include/Poco/Crypto/CipherKeyImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace Poco {
namespace Crypto {


class CipherKeyImpl: public RefCountedObject
class Crypto_API CipherKeyImpl: public RefCountedObject
/// An implementation of the CipherKey class for OpenSSL's crypto library.
{
public:
Expand Down
2 changes: 1 addition & 1 deletion Crypto/include/Poco/Crypto/ECKeyImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class X509Certificate;
class PKCS12Container;


class ECKeyImpl: public KeyPairImpl
class Crypto_API ECKeyImpl: public KeyPairImpl
/// Elliptic Curve key clas implementation.
{
public:
Expand Down
2 changes: 1 addition & 1 deletion Crypto/testsuite/src/CryptoTestSuite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "Poco/Platform.h"
// see https://github.com/openssl/openssl/blob/master/doc/man3/OPENSSL_Applink.pod
#if defined(POCO_OS_FAMILY_WINDOWS)
#if defined(_MSC_VER)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes I see, we use POCO_OS_FAMILY_WINDOWS and sometimes we use _MSC_VER .... May I ask what is the difference?

Copy link
Member Author

@ark0f ark0f Jun 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpenSSL for MinGW has no applink.c.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

#include "openssl/applink.c"
#endif
#include "CryptoTestSuite.h"
Expand Down
4 changes: 4 additions & 0 deletions Foundation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ if (NOT POCO_ENABLE_FPENVIRONMENT)
target_compile_definitions(Foundation PUBLIC POCO_NO_FPENVIRONMENT)
endif()

if(BUILD_SHARED_LIBS AND MINGW)
target_compile_definitions(Foundation PUBLIC _DLL)
endif()

POCO_INSTALL(Foundation)
POCO_GENERATE_PACKAGE(Foundation)

Expand Down
2 changes: 2 additions & 0 deletions Foundation/include/Poco/Foundation.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
#define POCO_DEPRECATED __attribute__((deprecated))
#elif defined(__clang__)
#define POCO_DEPRECATED __attribute__((deprecated))
#elif defined(__MINGW32__)
#define POCO_DEPRECATED __attribute__((deprecated))
#elif defined(_MSC_VER)
#define POCO_DEPRECATED __declspec(deprecated)
#else
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
3 changes: 2 additions & 1 deletion Foundation/src/Error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ namespace Poco {
LPWSTR lpMsgBuf = 0;
if (FormatMessageW(dwFlg, 0, errorCode, 0, (LPWSTR) & lpMsgBuf, 0, NULL))
UnicodeConverter::toUTF8(lpMsgBuf, errMsg);
#endif
LocalFree(lpMsgBuf);
#endif

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(reinterpret_cast<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(reinterpret_cast<HANDLE>(_pData->thread->native_handle()), mask) == 0)
{
throw SystemException("Failed to set affinity");
}
Expand Down
5 changes: 5 additions & 0 deletions Foundation/testsuite/src/FileTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
#include <set>


#ifndef MAX_PATH
#define MAX_PATH 260
#endif


using Poco::File;
using Poco::TemporaryFile;
using Poco::Path;
Expand Down
2 changes: 1 addition & 1 deletion JSON/include/Poco/JSON/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class JSON_API Array
// inlines
//

inline void Array::setEscapeUnicode(bool /*escape*/)
inline void Array::setEscapeUnicode(bool escape)
{
_escapeUnicode = escape;
}
Expand Down
2 changes: 1 addition & 1 deletion JSON/include/Poco/JSON/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ class JSON_API Object
// inlines
//

inline void Object::setEscapeUnicode(bool /*escape*/)
inline void Object::setEscapeUnicode(bool escape)
{
_escapeUnicode = escape;
}
Expand Down
2 changes: 0 additions & 2 deletions MongoDB/include/Poco/MongoDB/MongoDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
// MongoDB_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
//


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please read contribution documentation about code formatting

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

#if defined(_WIN32) && defined(POCO_DLL)
#if defined(MongoDB_EXPORTS)
#define MongoDB_API __declspec(dllexport)
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
17 changes: 13 additions & 4 deletions Net/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@ set_target_properties( Net
target_link_libraries(Net PUBLIC Poco::Foundation)
# Windows and WindowsCE need additional libraries
if(WIN32)
target_link_libraries(Net PUBLIC "iphlpapi.lib")
target_link_libraries(Net PUBLIC "iphlpapi")
if(WINCE)
target_link_libraries(Net PUBLIC "ws2.lib")
target_link_libraries(Net PUBLIC "ws2")
else()
target_link_libraries(Net PUBLIC "ws2_32.lib")
endif()
target_link_libraries(Net PUBLIC "ws2_32")
endif()

if(MINGW) # Needed by WinAPI in MinGW
string(REGEX MATCH "^[0-9]+\\.[0-9]+" WIN_VERSION ${CMAKE_SYSTEM_VERSION})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In cmake it is possible to verify version numbers with VERSION_LESS etc. See https://cmake.org/cmake/help/latest/command/if.html?highlight=version_less

Copy link
Member Author

@ark0f ark0f Jun 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't verify version, it calculate it from version like 6.0.141241 to 0x0600.

  • Take first two numbers 6 and 0, so we get 6.0
  • It take major version, so we get 6
  • It take minor version, so we get 0
  • Transform these two numbers to version like WinAPI. 256 * 6 + 0 = 1536 or 0x0600
    If windows version differ, WinAPI version will be different too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

string(REGEX REPLACE "\\.[0-9]+$" "" WIN_MAJOR_VERSION ${WIN_VERSION})
string(REGEX REPLACE "^[0-9]+\\." "" WIN_MINOR_VERSION ${WIN_VERSION})
math(EXPR WINAPI_VERSION "256 * ${WIN_MAJOR_VERSION} + ${WIN_MINOR_VERSION}")
set_source_files_properties(src/PollSet.cpp
PROPERTIES COMPILE_DEFINITIONS "_WIN32_WINNT=${WINAPI_VERSION}")
endif()
endif(WIN32)

target_include_directories(Net
Expand Down
40 changes: 20 additions & 20 deletions Net/include/Poco/Net/Net.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,26 @@ void Net_API uninitializeNetwork();
// Automate network initialization (only relevant on Windows).
//

#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(POCO_NO_AUTOMATIC_LIB_INIT) && !defined(__GNUC__)

extern "C" const struct Net_API NetworkInitializer pocoNetworkInitializer;

#if defined(Net_EXPORTS)
#if defined(_WIN64) || defined(_WIN32_WCE)
#define POCO_NET_FORCE_SYMBOL(s) __pragma(comment (linker, "/export:"#s))
#elif defined(_WIN32)
#define POCO_NET_FORCE_SYMBOL(s) __pragma(comment (linker, "/export:_"#s))
#endif
#else // !Net_EXPORTS
#if defined(_WIN64) || defined(_WIN32_WCE)
#define POCO_NET_FORCE_SYMBOL(s) __pragma(comment (linker, "/include:"#s))
#elif defined(_WIN32)
#define POCO_NET_FORCE_SYMBOL(s) __pragma(comment (linker, "/include:_"#s))
#endif
#endif // Net_EXPORTS

POCO_NET_FORCE_SYMBOL(pocoNetworkInitializer)

#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(POCO_NO_AUTOMATIC_LIB_INIT)
#if !defined(__GNUC__)
extern "C" const struct Net_API NetworkInitializer pocoNetworkInitializer;
#if defined(Net_EXPORTS)
#if defined(_WIN64) || defined(_WIN32_WCE)
#define POCO_NET_FORCE_SYMBOL(s) __pragma(comment (linker, "/export:"#s))
#elif defined(_WIN32)
#define POCO_NET_FORCE_SYMBOL(s) __pragma(comment (linker, "/export:_"#s))
#endif
#else // !Net_EXPORTS
#if defined(_WIN64) || defined(_WIN32_WCE)
#define POCO_NET_FORCE_SYMBOL(s) __pragma(comment (linker, "/include:"#s))
#elif defined(_WIN32)
#define POCO_NET_FORCE_SYMBOL(s) __pragma(comment (linker, "/include:_"#s))
#endif
#endif // Net_EXPORTS
#else // __GNUC__
#define POCO_NET_FORCE_SYMBOL(s) extern "C" const struct NetworkInitializer s;
#endif // !__GNUC__
POCO_NET_FORCE_SYMBOL(pocoNetworkInitializer)
#endif // POCO_OS_FAMILY_WINDOWS


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
7 changes: 4 additions & 3 deletions NetSSL_Win/src/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ 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
0, // Use the default provider
0, // Accept the default dwFlags
NULL); // pvPara is not used

Expand All @@ -101,7 +101,7 @@ 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
0, // Use the default provider
0, // No flags
NULL); // Not needed

Expand Down Expand Up @@ -270,7 +270,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/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ target_include_directories(PDF
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src
)

if(MINGW)
target_compile_definitions(PDF PRIVATE HPDF_DLL_MAKE_CDECL)
endif()

if (POCO_UNBUNDLED)
target_include_directories(PDF PUBLIC "${ZLIB_INCLUDE_DIRS}")
target_compile_definitions(PDF PUBLIC POCO_UNBUNDLED)
Expand Down
1 change: 0 additions & 1 deletion PageCompiler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ install(
if (POCO_ENABLE_SAMPLES)
# add_subdirectory(samples)
endif ()

5 changes: 5 additions & 0 deletions SQL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ if(MSVC AND NOT(MSVC_VERSION LESS 1400))
PROPERTIES COMPILE_FLAGS "/bigobj")
endif()

if(MINGW)
set_source_files_properties(src/StatementImpl.cpp
PROPERTIES COMPILE_FLAGS "-Wa,-mbig-obj")
endif()

add_library(SQL ${SRCS} )
add_library(Poco::SQL ALIAS SQL)
set_target_properties(SQL
Expand Down
2 changes: 1 addition & 1 deletion SQL/ODBC/include/Poco/SQL/ODBC/Connector.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ struct ODBC_API ODBCConnectorRegistrator
#endif
#endif // ODBC_EXPORTS
#else // !POCO_OS_FAMILY_WINDOWS
#define POCO_DATA_ODBC_FORCE_SYMBOL(s) extern "C" const struct ODBCConnectorRegistrator s;
#define POCO_DATA_ODBC_FORCE_SYMBOL(s) extern "C" const struct ODBCConnectorRegistrator s;
#endif // POCO_OS_FAMILY_WINDOWS
POCO_DATA_ODBC_FORCE_SYMBOL(pocoODBCConnectorRegistrator)
#endif // POCO_NO_AUTOMATIC_LIB_INIT
Expand Down
2 changes: 1 addition & 1 deletion SQL/PostgreSQL/include/Poco/SQL/PostgreSQL/Connector.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct PostgreSQL_API PostgreSQLConnectorRegistrator


#if !defined(POCO_NO_AUTOMATIC_LIB_INIT)
#if defined(POCO_OS_FAMILY_WINDOWS)
#if defined(_MSC_VER)
extern "C" const struct PostgreSQL_API PostgreSQLConnectorRegistrator pocoPostgreSQLConnectorRegistrator;
#if defined(PostgreSQL_EXPORTS)
#if defined(_WIN64)
Expand Down
1 change: 0 additions & 1 deletion SQL/include/Poco/SQL/SQL.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
// Poco_SQL_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
//

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please read contribution documentation about code formatting :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

#if defined(_WIN32) && defined(POCO_DLL)
#if defined(SQL_EXPORTS)
#define Poco_SQL_API __declspec(dllexport)
Expand Down
3 changes: 2 additions & 1 deletion Util/include/Poco/Util/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,8 @@ inline Poco::Timespan Application::uptime() const
return Poco::Util::Application::EXIT_CONFIG;\
} \
return pApp->run(); \
}
} \
POCO_WMAIN_WRAPPER()
#elif defined(POCO_VXWORKS)
#define POCO_APP_MAIN(App) \
int pocoAppMain(const char* appName, ...) \
Expand Down
5 changes: 3 additions & 2 deletions Util/include/Poco/Util/ServerApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class Util_API ServerApplication: public Application
//
// Macro to implement main()
//
#if defined(_WIN32) && !defined(__MINGW32__)
#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(POCO_NO_WSTRING)
#define POCO_SERVER_MAIN(App) \
int wmain(int argc, wchar_t** argv) \
{ \
Expand All @@ -246,7 +246,8 @@ class Util_API ServerApplication: public Application
std::cerr << exc.displayText() << std::endl; \
return Poco::Util::Application::EXIT_SOFTWARE; \
} \
}
} \
POCO_WMAIN_WRAPPER()
#elif defined(POCO_VXWORKS)
#define POCO_SERVER_MAIN(App) \
int pocoSrvMain(const char* appName, ...) \
Expand Down
20 changes: 20 additions & 0 deletions Util/include/Poco/Util/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@
#endif


//
// Define wrapper if wmain() is disabled in MinGW.
// Use option "-municode" to enable wmain().
// Required by Application and ServerApplication.
//
#if defined(__MINGW32__) && !defined(POCO_NO_WMAIN_WRAPPER)
#define POCO_WMAIN_WRAPPER() \
extern int _CRT_glob; \
extern "C" void __wgetmainargs(int*, wchar_t***, wchar_t***, int, int*); \
int main() { \
wchar_t **enpv, **argv; \
int argc, si = 0; \
__wgetmainargs(&argc, &argv, &enpv, _CRT_glob, &si); \
return wmain(argc, argv); \
}
#else
#define POCO_WMAIN_WRAPPER()
#endif


//
// Automatically link Util library.
//
Expand Down
2 changes: 2 additions & 0 deletions Util/testsuite/src/WinConfigurationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ void WinConfigurationTest::testConfiguration()
assertTrue (pView->getString("sub.foo", "default") == "bar");

std::string value;
#ifndef __MINGW32__
assertTrue (pReg->convertToRegFormat("A.B.C", value) == "A\\B");
#endif
assertTrue (value == "C");

Poco::Util::AbstractConfiguration::Keys keys;
Expand Down
Loading