diff --git a/CMakeLists.txt b/CMakeLists.txt index 63fbd1cf..a7410c07 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,8 @@ if(APPLE) endif(APPLE) include(GNUInstallDirs) +include(CMakePushCheckState) +include(CheckSourceCompiles) option(WITH_BUNDLED_DEPS "Build with bundled dependencies?" ON) option(WITH_TLS diff --git a/config.mk b/config.mk index 34d5163f..594a7267 100644 --- a/config.mk +++ b/config.mk @@ -318,7 +318,10 @@ ifeq ($(WITH_EC),yes) endif ifeq ($(WITH_ADNS),yes) - BROKER_LDADD:=$(BROKER_LDADD) -lanl + NEED_LIBANL:=$(shell printf 'int main(){return 0;}' | gcc -D_GNU_SOURCE -lanl -o /dev/null -x c - 2>/dev/null || echo yes) + ifeq ($(NEED_LIBANL),yes) + BROKER_LDADD+=-lanl + endif BROKER_CPPFLAGS:=$(BROKER_CPPFLAGS) -DWITH_ADNS endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d4bae7cd..6592d65c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -165,12 +165,31 @@ endif (WITH_DLT) set (MOSQ_LIBS ${MOSQ_LIBS} OpenSSL::SSL) # Check for getaddrinfo_a -include(CheckLibraryExists) -check_library_exists(anl getaddrinfo_a "" HAVE_GETADDRINFO_A) -if (HAVE_GETADDRINFO_A AND WITH_ADNS) - add_definitions("-DWITH_ADNS") - add_definitions(-DHAVE_GETADDRINFO_A) - set (MOSQ_LIBS ${MOSQ_LIBS} anl) +# Prior to glibc 2.34 this required linking with anl +if(WITH_ADNS) + cmake_push_check_state() + set(ANL_CODE " + #include + #include + int main(){ + return getaddrinfo_a(0, NULL, 0, NULL); + } + ") + check_source_compiles(C "${ANL_CODE}" HAVE_GETADDRINFO_A) + if(HAVE_GETADDRINFO_A) + add_definitions(mosquitto PRIVATE "WITH_ADNS") + else() + set(CMAKE_REQUIRED_LIBRARIES "anl") + check_source_compiles(C "${ANL_CODE}" HAVE_GETADDRINFO_A_LIBANL) + + if(HAVE_GETADDRINFO_A_LIBANL) + add_definitions(mosquitto PRIVATE "WITH_ADNS") + set (MOSQ_LIBS ${MOSQ_LIBS} anl) + else() + message(FATAL_ERROR "WITH_ADNS is set, but getaddrinfo_a() is not available.") + endif() + endif() + cmake_pop_check_state() endif (HAVE_GETADDRINFO_A AND WITH_ADNS)