diff options
author | Alan Antonuk <alan.antonuk@gmail.com> | 2012-10-18 23:19:43 -0400 |
---|---|---|
committer | Alan Antonuk <alan.antonuk@gmail.com> | 2012-10-20 02:45:25 -0400 |
commit | 511c9398539f30e6ebbee243112b29674b76581c (patch) | |
tree | a08343814ba4de731d201a9698ebe9ea2f2f0a6f /CMakeLists.txt | |
parent | 445567f442b2854d1f9309e46a225ab5111f237a (diff) | |
download | rabbitmq-c-github-ask-511c9398539f30e6ebbee243112b29674b76581c.tar.gz |
cmake: Detect if socket library is needed
Certain platforms require linking against a socket
and/or name resolution library. Detect this in the
CMakeLists.txt script and SOCKET_LIBRARIES to the
target_link_libraries of rabbitmq
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 3471aa4..a55dbd0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -135,6 +135,47 @@ endif() set(AMQP_CODEGEN_DIR ${RABBITMQ_CODEGEN_DIR} CACHE PATH "Path to rabbitmq-codegen" FORCE) mark_as_advanced(AMQP_CODEGEN_DIR) +include(CheckFunctionExists) +include(CheckLibraryExists) + +# Detect if we need to link against a socket library: +if (WIN32) + # Always use WinSock2 on Windows + set(SOCKET_LIBRARIES ws2_32) +else () + # Is it in the default link? + CHECK_FUNCTION_EXISTS(getaddrinfo HAVE_GETADDRINFO) + if (NOT (HAVE_GETADDRINFO EQUAL 1)) + CHECK_LIBRARY_EXISTS(socket getaddrinfo "" HAVE_GETADDRINFO2) + if (HAVE_GETADDRINFO2 EQUAL 1) + set(SOCKET_LIBRARIES socket) + else () + CHECK_LIBRARY_EXISTS("socket;nsl" getaddrinfo "" HAVE_GETADDRINFO3) + if (HAVE_GETADDRINFO3 EQUAL 1) + set(SOCKET_LIBRARIES socket nsl) + else () + message(FATAL_ERROR "Cannot find name resolution library (containing symbol getaddrinfo)") + endif () + endif () + endif () + + set(CMAKE_REQUIRED_LIBRARIES ${SOCKET_LIBRARIES}) + CHECK_FUNCTION_EXISTS(socket HAVE_SOCKET) + if (NOT HAVE_SOCKET EQUAL 1) + CHECK_LIBRARY_EXISTS(socket socket "" HAVE_SOCKET2) + if (NOT HAVE_SOCKET2 EQUAL 1) + set(SOCKET_LIBRARIES socket ${SOCKET_LIBRARIES}) + else () + CHECK_LIBRARY_EXISTS("socket;nsl" socket "" HAVE_SOCKET3) + if (HAVE_SOCKET3 EQUAL 1) + set(SOCKET_LIBRARIES socket nsl ${SOCKET_LIBRARIES}) + else () + message(FATAL_ERROR "Cannot find socket library (containing symbol socket)") + endif () + endif () + endif () +endif () + find_package(POPT) find_package(XmlTo) |