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 6 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
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ cmake_minimum_required(VERSION 3.2.0)

project(Poco)

if(WINCE AND MINGW)
message(FATAL_ERROR "MinGW does not support WinCE")
Copy link
Member Author

Choose a reason for hiding this comment

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

I think I should delete this. CMake will cope with this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think also we should remove this.... mingw will not work at all on wince ...

endif()

option(POCO_VERBOSE_MESSAGES "Enable informational messages during configure" ON)

file(STRINGS "${PROJECT_SOURCE_DIR}/libversion" SHARED_LIBRARY_VERSION)
Expand Down Expand Up @@ -81,6 +85,10 @@ else()
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
endif()

if(BUILD_SHARED_LIBS AND MINGW)
add_definitions(-D_DLL)
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't use "add_definitons". Use target_compile_definitons ... See also CMake-contribution-rules

Copy link
Member Author

@ark0f ark0f Jun 5, 2018

Choose a reason for hiding this comment

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

Define _DDL use almost all packages and dependencies. Do you offer to define it for every target? Or you offer define as PUBLIC?

Copy link
Contributor

Choose a reason for hiding this comment

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

You should ask your self, if it is mandatory to set also _DLL into your project they use the compiled poco library ? Mostly I checked in the code if this preprocessor definiton is in the header file .... if not, then it can be PRIVATE (it is only need to compile the poco librarie) ... if it is in the header file, then you should investigate is this header file published with the compiled library ... if yes then it is mostly mandatory that you added this as PUBLIC because it is needed to use the compiled poco library into your project. You should not added these to every target. Added with target_compile_definition with PUBLIC there where it is used and this definiton will be provided to the other targets they use this target. For example for me we should add this on the Poco::Foundation target. All of the other targets depends on Poco::Foundation and get this definiton ...See also target_compile_definitions I found that _DLL is used in Crypto.h, CppUnit.h, Foundation,h, NetSSL.h, pngconf.h .... I see also we have POCO_DLL ... hmmm is this the same?

endif()

# allow disabling of internally built OpenSSL# (see below for details)
# if POCO pre-built OpenSSL directory is found, and POCO_DISABLE_INTERNAL_OPENSSL=OFF,
# the internal OpenSSL build will be used
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
1 change: 1 addition & 0 deletions Crypto/samples/genrsakey/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
add_executable(genrsakey src/genrsakey.cpp)
target_link_libraries(genrsakey PUBLIC Poco::Crypto Poco::Util Poco::XML)
POCO_ENABLE_EXE_WMAIN(genrsakey)
Copy link
Member

Choose a reason for hiding this comment

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

@Bjoe can you please confirm this is the right thing to do

Copy link
Contributor

Choose a reason for hiding this comment

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

See my review comment...

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: 3 additions & 1 deletion Encodings/Compiler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ install(
ARCHIVE DESTINATION lib${LIB_SUFFIX}
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)
)

POCO_ENABLE_EXE_WMAIN(EncodingsCompiler)
7 changes: 7 additions & 0 deletions Foundation/include/Poco/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@
#endif


// Define if unicode is not available in MinGW
// To enable unicode use option "-municode"
#if defined(__MINGW32__) && (!defined(_UNICODE) || !defined(UNICODE))
#define POCO_NO_MINGW_UNICODE
#endif


// Define to override system-provided
// minimum thread priority value on POSIX
// platforms (returned by Poco::Thread::getMinOSPriority()).
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((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
4 changes: 4 additions & 0 deletions Foundation/testsuite/src/FileTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#include <set>


#ifndef MAX_PATH
#define MAX_PATH 260
#endif

using Poco::File;
using Poco::TemporaryFile;
using Poco::Path;
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
6 changes: 3 additions & 3 deletions Net/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ 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")
target_link_libraries(Net PUBLIC "ws2_32")
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Well I don't know yet if this will work with microsoft compile. But ws2_32 is better then ws2_32.lib .... I would like to investigate if cmake support .lib suffix for microsoft compiler...

endif()
endif(WIN32)

Expand Down
1 change: 1 addition & 0 deletions Net/samples/WebSocketServer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ if(WINCE)
set_target_properties(WebSocketServer PROPERTIES LINK_FLAGS "/ENTRY:wmainCRTStartup")
endif()
target_link_libraries(WebSocketServer PUBLIC Poco::Net Poco::Util Poco::JSON)
POCO_ENABLE_EXE_WMAIN(WebSocketServer)
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 {


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

#if defined(POCO_HAVE_FD_EPOLL)


Expand Down
1 change: 1 addition & 0 deletions NetSSL_OpenSSL/samples/TwitterClient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ add_executable(TwitterCLient
src/Twitter.cpp
)
target_link_libraries(TwitterCLient PUBLIC Poco::NetSSL Poco::Util Poco::JSON Poco::XML)
POCO_ENABLE_EXE_WMAIN(TwitterCLient)
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)
add_definitions(-DHPDF_DLL_MAKE_CDECL)
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't use add_definitons ... use target_compile_definitons. See also CMake-contribution-rules

endif()

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

POCO_ENABLE_EXE_WMAIN( "${POCO_EXENAME}" )

3 changes: 3 additions & 0 deletions PageCompiler/File2Page/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ install(
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)

POCO_ENABLE_EXE_WMAIN(File2Page)

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/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
1 change: 1 addition & 0 deletions SevenZip/samples/un7zip/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
add_executable(un7zip src/un7zip.cpp)
target_link_libraries(un7zip PUBLIC Poco::SevenZip Poco::Util Poco::XML)
POCO_ENABLE_EXE_WMAIN(un7zip)
2 changes: 1 addition & 1 deletion Util/include/Poco/Util/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ inline Poco::Timespan Application::uptime() const
//
// Macro to implement main()
//
#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(POCO_NO_WSTRING)
#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(POCO_NO_WSTRING) && !defined(POCO_NO_MINGW_UNICODE)
#define POCO_APP_MAIN(App) \
int wmain(int argc, wchar_t** argv) \
{ \
Expand Down
2 changes: 1 addition & 1 deletion 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(_WIN32) && !defined(POCO_NO_MINGW_UNICODE)
Copy link
Contributor

Choose a reason for hiding this comment

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

No unicode ? I was expected you should have wmain for unicode support?

Copy link
Member Author

@ark0f ark0f Jun 6, 2018

Choose a reason for hiding this comment

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

Option -municode affect to WinAPI too. For example InetPton. It is define to InetPtonA or to InetPtonW. If option -municode set, InetPton will be InetPtonW. If not, InetPton will be InetPtonA.
What does mean A or W:
https://msdn.microsoft.com/en-us/library/windows/desktop/dd374089(v=vs.85).aspx

Copy link
Member

Choose a reason for hiding this comment

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

As stated in the URL

A Windows code page version with the letter "A" used to indicate "ANSI"
A Unicode version with the letter "W" used to indicate "wide"

#define POCO_SERVER_MAIN(App) \
int wmain(int argc, wchar_t** argv) \
{ \
Expand Down
1 change: 1 addition & 0 deletions Util/samples/SampleApp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ if(WINCE)
set_target_properties(SampleApp PROPERTIES LINK_FLAGS "/ENTRY:wmainCRTStartup")
endif()
target_link_libraries(SampleApp PUBLIC Poco::Util Poco::JSON Poco::XML)
POCO_ENABLE_EXE_WMAIN(SampleApp)
1 change: 1 addition & 0 deletions Util/samples/SampleServer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ if(WINCE)
set_target_properties(SampleServer PROPERTIES LINK_FLAGS "/ENTRY:wmainCRTStartup")
endif()
target_link_libraries(SampleServer PUBLIC Poco::Util Poco::JSON Poco::XML)
POCO_ENABLE_EXE_WMAIN(SampleServer)
1 change: 1 addition & 0 deletions Util/samples/pkill/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ if(WINCE)
set_target_properties(pkill PROPERTIES LINK_FLAGS "/ENTRY:wmainCRTStartup")
endif()
target_link_libraries(pkill PUBLIC Poco::Util Poco::JSON Poco::XML)
POCO_ENABLE_EXE_WMAIN(pkill)
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
1 change: 1 addition & 0 deletions Zip/samples/unzip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ if(WINCE)
set_target_properties(sample-unzip PROPERTIES LINK_FLAGS "/ENTRY:wmainCRTStartup")
endif()
target_link_libraries(sample-unzip PUBLIC Poco::Zip Poco::Util Poco::XML)
POCO_ENABLE_EXE_WMAIN(sample-unzip)
1 change: 1 addition & 0 deletions Zip/samples/zip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ if(WINCE)
set_target_properties(sample-zip PROPERTIES LINK_FLAGS "/ENTRY:wmainCRTStartup")
endif()
target_link_libraries(sample-zip PUBLIC Poco::Zip Poco::Util Poco::XML)
POCO_ENABLE_EXE_WMAIN(sample-zip)
21 changes: 15 additions & 6 deletions cmake/PocoMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ if (WIN32)
endif ()
find_program(CMAKE_MC_COMPILER mc.exe HINTS "${sdk_bindir}" "${kit_bindir}" "${kit81_bindir}" ${kit10_bindir}
DOC "path to message compiler")
if (NOT CMAKE_MC_COMPILER)
if (NOT CMAKE_MC_COMPILER AND NOT MINGW)
message(FATAL_ERROR "message compiler not found: required to build")
endif (NOT CMAKE_MC_COMPILER)
message(STATUS "Found message compiler: ${CMAKE_MC_COMPILER}")
mark_as_advanced(CMAKE_MC_COMPILER)
endif (NOT CMAKE_MC_COMPILER AND NOT MINGW)
if(CMAKE_MC_COMPILER)
message(STATUS "Found message compiler: ${CMAKE_MC_COMPILER}")
mark_as_advanced(CMAKE_MC_COMPILER)
endif(CMAKE_MC_COMPILER)
endif(WIN32)

# Accept older ENABLE_<COMPONENT>, ENABLE_TESTS and ENABLE_SAMPLES and
Expand Down Expand Up @@ -183,7 +185,7 @@ endmacro()


macro(POCO_MESSAGES out name)
if (WIN32)
if (WIN32 AND CMAKE_MC_COMPILER)
foreach(msg ${ARGN})
get_filename_component(msg_name ${msg} NAME)
get_filename_component(msg_path ${msg} ABSOLUTE)
Expand Down Expand Up @@ -212,7 +214,14 @@ macro(POCO_MESSAGES out name)
source_group("${name}\\Message Files" FILES ${ARGN})
list(APPEND ${out} ${ARGN})

endif (WIN32)
endif (WIN32 AND CMAKE_MC_COMPILER)
endmacro()


macro(POCO_ENABLE_EXE_WMAIN target_name)
if(MINGW)
set_target_properties("${target_name}" PROPERTIES LINK_FLAGS "-municode")
Copy link
Contributor

Choose a reason for hiding this comment

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

-municode is needed to compile unicode applications. Should be activated when Uniicode support is enabled in poco or?
I found also this

Help! I get an error: unrecognized command line option "-municode"!

in MinGW wikiUnicode applications

Normaly CMake takes care that it works on all compilers and platforms. See also CMake rulse:

  1. Don't make any assumption about the platform or compiler!

I would like to investigate if cmake has any support for such compile flag.

Copy link
Member Author

@ark0f ark0f Jun 5, 2018

Choose a reason for hiding this comment

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

Try to compile application with wmain using MinGW. You'll get undefined reference to WinMain, if you don't add this option. Also see https://stackoverflow.com/a/11706847.
And quote from MinGW wiki:

While it is not necessary to define _UNICODE or UNICODE to compile the above code, -municode is needed for linking because it uses wmain() instead of the traditional main().

Copy link
Contributor

Choose a reason for hiding this comment

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

But wmain is needed when you will have unicode support or? For me it looks like this depends on POCO_ENBALE_WSTRING .... but I'm still investigating...

endif()
endmacro()


Expand Down