From 794d7a3143e80ca102a5a7b7dedd3ba7a09d0c34 Mon Sep 17 00:00:00 2001 From: Tony Theodore Date: Mon, 12 Mar 2018 20:19:27 +1100 Subject: [PATCH 1/2] Problem: certain windows header files are actually lowercase Solution: change case of `WinSock2.h Iphlpapi.h Rpc.h` to match the files on disk. This is only noticeable when cross-compiling from a case-sensitive system so wouldn't get picked up in MSVC or mingw builds running on a windows machine. MSDN uses capitalised versions in prose and lowercase in code examples: https://msdn.microsoft.com/en-us/library/windows/desktop/ms737629(v=vs.85).aspx Fixes #2978, the missing library message is a little misleading. --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e10537c349..fe515f1153 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -192,13 +192,13 @@ endif () if (ZMQ_HAVE_WINDOWS) # Cannot use check_library_exists because the symbol is always declared as char(*)(void) set(CMAKE_REQUIRED_LIBRARIES "ws2_32.lib") - check_symbol_exists (WSAStartup "WinSock2.h" HAVE_WS2_32) + check_symbol_exists (WSAStartup "winsock2.h" HAVE_WS2_32) set(CMAKE_REQUIRED_LIBRARIES "rpcrt4.lib") - check_symbol_exists (UuidCreateSequential "Rpc.h" HAVE_RPCRT4) + check_symbol_exists (UuidCreateSequential "rpc.h" HAVE_RPCRT4) set(CMAKE_REQUIRED_LIBRARIES "iphlpapi.lib") - check_symbol_exists (GetAdaptersAddresses "winsock2.h;Iphlpapi.h" HAVE_IPHLAPI) + check_symbol_exists (GetAdaptersAddresses "winsock2.h;iphlpapi.h" HAVE_IPHLAPI) set(CMAKE_REQUIRED_LIBRARIES "") # TODO: This not the symbol we're looking for. What is the symbol? From c7876c097fe493572d67f00d5326bc0bcb31d928 Mon Sep 17 00:00:00 2001 From: Tony Theodore Date: Mon, 12 Mar 2018 20:20:02 +1100 Subject: [PATCH 2/2] Problem: mingw static/shared builds have different preprocessor defines Solution: remove objects optimisation in library build (similar to #2860) and set PUBLIC compile definitions on all static builds instead of MSVC only. --- CMakeLists.txt | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fe515f1153..9d8bf0dca5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -911,20 +911,27 @@ if (MSVC) DEBUG_POSTFIX "${MSVC_TOOLSET}-mt-sgd-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}" COMPILE_FLAGS "/DZMQ_STATIC" OUTPUT_NAME "libzmq") - - target_compile_definitions(libzmq-static - PUBLIC ZMQ_STATIC - ) - endif() else () # avoid building everything twice for shared + static # only on *nix, as Windows needs different preprocessor defines in static builds - add_library (objects OBJECT ${sources}) - set_property(TARGET objects PROPERTY POSITION_INDEPENDENT_CODE ON) + if (NOT MINGW) + add_library (objects OBJECT ${sources}) + set_property(TARGET objects PROPERTY POSITION_INDEPENDENT_CODE ON) + target_include_directories (objects + PUBLIC + $ + $ + $ + ) + endif () if (BUILD_SHARED) - add_library (libzmq SHARED $ ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig} ${CMAKE_CURRENT_BINARY_DIR}/version.rc) + if (MINGW) + add_library (libzmq SHARED ${sources} ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig} ${CMAKE_CURRENT_BINARY_DIR}/version.rc) + else () + add_library (libzmq SHARED $ ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig} ${CMAKE_CURRENT_BINARY_DIR}/version.rc) + endif () # NOTE: the SOVERSION and VERSION MUST be the same as the one generated by libtool! It is NOT the same as the version of the package. set_target_properties (libzmq PROPERTIES COMPILE_DEFINITIONS "DLL_EXPORT" @@ -949,19 +956,22 @@ else () endif() if (BUILD_STATIC) - add_library (libzmq-static STATIC $ ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig} ${CMAKE_CURRENT_BINARY_DIR}/version.rc) + if (MINGW) + add_library (libzmq-static STATIC ${sources} ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig} ${CMAKE_CURRENT_BINARY_DIR}/version.rc) + else () + add_library (libzmq-static STATIC $ ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig} ${CMAKE_CURRENT_BINARY_DIR}/version.rc) + endif () set_target_properties (libzmq-static PROPERTIES PUBLIC_HEADER "${public_headers}" - COMPILE_DEFINITIONS "ZMQ_STATIC" OUTPUT_NAME "zmq" PREFIX "lib") endif() - target_include_directories (objects - PUBLIC - $ - $ - $ +endif () + +if (BUILD_STATIC) + target_compile_definitions(libzmq-static + PUBLIC ZMQ_STATIC ) endif ()