zmqpp icon indicating copy to clipboard operation
zmqpp copied to clipboard

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

Open FlorianWolters opened this issue 8 years ago • 3 comments

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.

    • https://github.com/zeromq/zmqpp/blob/develop/CMakeLists.txt#L121

      if(WIN32)
        target_link_libraries(zmqpp wsock32 ws2_32)
      endif()
      
    • https://github.com/zeromq/zmqpp/blob/develop/CMakeLists.txt#L126

      if(WIN32)
        target_link_libraries(zmqpp-static wsock32 ws2_32)
      endif()
      
  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.

FlorianWolters avatar Jan 22 '17 18:01 FlorianWolters

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

bluca avatar Jan 22 '17 19:01 bluca

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 avatar Jan 22 '17 21:01 FlorianWolters

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.

FlorianWolters avatar Mar 05 '17 09:03 FlorianWolters