zeromq / zmqpp

0mq 'highlevel' C++ bindings
http://zeromq.github.io/zmqpp
Mozilla Public License 2.0
438 stars 195 forks source link

CMake build does not work with Microsoft Windows operating system, both for MinGW and MSVC #182

Open FlorianWolters opened 7 years ago

FlorianWolters commented 7 years ago

The CMakeLists.txt generates compiler and linker errors when building with Microsoft Windows and/or the Microsoft Visual C++ (MSVC) compiler. The following changes must be applied to the CMakeLists.txt:

  1. Add Winsock to the libraries to link.

  2. Wrap the CMAKE_CXX_FLAGS modifications into an if-condition, so they get only applied when compiling with GCC/MinGW (https://github.com/zeromq/zmqpp/blob/develop/CMakeLists.txt#L18-26).

    if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)

    ...

    endif()

Off-Topic: Overall the build looks fragile. Would be nice if GCC/MinGW-w64/Clang/MSVC would all work equally. libzmq (and zmqpp) should use a CMake Package. I had to introduce a lot of custom builds steps (renaming of generated libraries, this issue, etc) in order to successfully build ZeroMQ with CMake for both MinGW-w64 and MSVC from sources.

bluca commented 7 years ago

Could you please a PR to fix those?

Also the following changes to libzmq: https://github.com/zeromq/libzmq/pull/2295 were made to avoid the need of an external findpackage. But I don't use Windows so can't comment on more than that

FlorianWolters commented 7 years ago

Yes, I will create a PR tomorrow. Ah, I see: https://github.com/zeromq/libzmq/pull/2295 seems to implement exactly what I mean: The modern CMake-Package approach as described in the link posted by myself.

FlorianWolters commented 7 years ago

Sorry, I totally forgot this one. The MinGW 6.3.0 build seems to work now in the develop head, but the VC 14.0 build fails with another error now. Sadly I do not have the time at the moment to fix the broken build, I've also spotted problems regarding optional build of static and shared libraries and so on. For example, a Find Module (or better: rely on the Package Configuration in the ZeroMQ library) should be used instead of the two variables ZEROMQ_LIB_DIR and ZEROMQ_INCLUDE_DIR. The person fixing the zmqpp build should read https://cgold.readthedocs.io/en/latest/tutorials/libraries/static-shared.html and https://cmake.org/cmake/help/latest/command/find_package.html.

tl;dr: It is not a good idea to build both shared and static libraries in one build configuration. Instead two separate build configurations (i.e. also out-of-source builds) should be used.