From 279bcb28430bc48366680b41516bd39853697fcb Mon Sep 17 00:00:00 2001 From: Artem Martynovich Date: Fri, 11 Sep 2015 13:39:19 +0500 Subject: [PATCH] Fix configure failure on 32-bit MSVC. Windows libraries being checked (ws2_32, rpcrt4, iphlpapi) contain functions following stdcall convention. While on 64-bit platform it makes no difference, on 32-bit it does. For example, function WSAGetLastError is mangled by MSVC like "_WSAGetLastError@0". CMake checks if a function FUNC is present in a library by compiling a simple C source containing function definition "char FUNC()" and then calling it. Since stdcall functions are mangled in such a way that requires correct number of arguments (written after "@"), checking for a function with non-zero number of arguments will fail. That is why we check for functions which have zero arguments and we also force stdcall convention. --- CMakeLists.txt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6466598b..00841963 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,10 +117,15 @@ check_include_files(windows.h ZMQ_HAVE_WINDOWS) check_include_files(sys/uio.h ZMQ_HAVE_UIO) check_include_files(sys/eventfd.h ZMQ_HAVE_EVENTFD) -check_library_exists(ws2_32 WSAStartup "" HAVE_WS2_32) -check_library_exists(ws2 WSAStartup "" HAVE_WS2) -check_library_exists(rpcrt4 UuidCreate "" HAVE_RPCRT4) -check_library_exists(iphlpapi GetNetworkParams "" HAVE_IPHLAPI) +if(MSVC) + # Force stdcall convention + set(CMAKE_REQUIRED_FLAGS "/Gz") +endif() +check_library_exists(ws2_32 WSAGetLastError "" HAVE_WS2_32) +check_library_exists(ws2 WSAGetLastError "" HAVE_WS2) +check_library_exists(rpcrt4 RpcErrorClearInformation "" HAVE_RPCRT4) +check_library_exists(iphlpapi GetAdapterOrderMap "" HAVE_IPHLAPI) +unset(CMAKE_REQUIRED_FLAGS) check_cxx_symbol_exists(SO_PEERCRED sys/socket.h ZMQ_HAVE_SO_PEERCRED) check_cxx_symbol_exists(LOCAL_PEERCRED sys/socket.h ZMQ_HAVE_LOCAL_PEERCRED)