Merge pull request #311 from proller/libanl

fix static linking with libanl.a on ubuntu 16.10
This commit is contained in:
alexey-milovidov 2017-01-09 21:36:40 +04:00 committed by GitHub
commit 319ded229e
3 changed files with 34 additions and 9 deletions

View File

@ -15,12 +15,11 @@ if(WIN32)
set(SYSLIBS ${SYSLIBS} "ws2.lib" "iphlpapi.lib")
else()
set(SYSLIBS ${SYSLIBS} "ws2_32.lib" "iphlpapi.lib")
endif()
elseif(NOT APPLE AND NOT CMAKE_SYSTEM MATCHES "FreeBSD")
if (USE_STATIC_LIBRARIES)
set(SYSLIBS ${SYSLIBS} "libanl.a")
else()
set(SYSLIBS ${SYSLIBS} "anl")
endif()
else()
include(cmake/test_anl.cmake)
if (HAVE_GETADDRINFO_A)
set(SYSLIBS ${SYSLIBS} "${ANL_LIB}")
endif()
endif(WIN32)

View File

@ -0,0 +1,26 @@
#
# On ubuntu 16.10 static link libanl.a fails with -fPIC error
#
include(CheckCXXSourceRuns)
if (USE_STATIC_LIBRARIES)
set(ANL_LIB_NAME "libanl.a")
else()
set(ANL_LIB_NAME "anl")
endif()
find_library(ANL_LIB NAMES ${ANL_LIB_NAME})
set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES} ${ANL_LIB}")
check_cxx_source_runs("
#include <netdb.h>
int main() { getaddrinfo_a(GAI_NOWAIT, nullptr, 0, nullptr); return 0;}
" HAVE_GETADDRINFO_A)
#message(STATUS "test_anl: USE_STATIC_LIBRARIES=${USE_STATIC_LIBRARIES} ANL_LIB_NAME=${ANL_LIB_NAME} ANL_LIB=${ANL_LIB} HAVE_GETADDRINFO_A=${HAVE_GETADDRINFO_A}")
if (HAVE_GETADDRINFO_A)
add_definitions(-DHAVE_GETADDRINFO_A=1)
endif ()

View File

@ -34,7 +34,7 @@
/// set default DNS timeout to 60 seconds
const Poco::Timespan Poco::Net::DNS::DEFAULT_DNS_TIMEOUT = Poco::Timespan(60, 0);
#if !defined(__APPLE__) && !defined(__FreeBSD__)
#if HAVE_GETADDRINFO_A
/** getaddrinfo иногда работает бесконечно долго.
* Этот код использует getaddrinfo_a c некоторым таймаутом.
*
@ -224,7 +224,7 @@ HostEntry DNS::hostByName(const std::string& hostname, const Poco::Timespan * ti
struct addrinfo hints;
std::memset(&hints, 0, sizeof(hints));
hints.ai_flags = hintFlags;
#if !defined(__APPLE__) && !defined(__FreeBSD__)
#if HAVE_GETADDRINFO_A
int rc = GetAddrinfo::instance().getaddrinfo(hostname.c_str(), NULL, &hints, &pAI, timeout_);
#else
(void)timeout_;
@ -278,7 +278,7 @@ HostEntry DNS::hostByAddress(const IPAddress& address, const Poco::Timespan * ti
struct addrinfo hints;
std::memset(&hints, 0, sizeof(hints));
hints.ai_flags = hintFlags;
#if !defined(__APPLE__) && !defined(__FreeBSD__)
#if HAVE_GETADDRINFO_A
int rc = GetAddrinfo::instance().getaddrinfo(fqname, NULL, &hints, &pAI, timeout_);
#else
(void)timeout_;