From 702f2fb52f90273b86ef6d1f117814bd08fcc542 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Thu, 27 Sep 2018 18:31:26 +0200 Subject: cmake: Fix checking for required system libraries Signed-off-by: Andreas Schneider Reviewed-by: Ralph Boehme --- ConfigureChecks.cmake | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index 9ced360..cb5bf53 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -70,25 +70,33 @@ check_function_exists(pledge HAVE_PLEDGE) if (UNIX) + find_library(DLFCN_LIBRARY dl) + if (DLFCN_LIBRARY) + string(APPEND _REQUIRED_LIBRARIES ${DLFCN_LIBRARY}) + else() + check_function_exists(dlopen HAVE_DLOPEN) + if (NOT HAVE_DLOPEN) + message(FATAL_ERROR "FATAL: No dlopen() function detected") + endif() + endif() + if (NOT LINUX) # libsocket (Solaris) check_library_exists(socket getaddrinfo "" HAVE_LIBSOCKET) if (HAVE_LIBSOCKET) - set(_REQUIRED_LIBRARIES ${_REQUIRED_LIBRARIES} socket) + string(APPEND _REQUIRED_LIBRARIES socket) endif (HAVE_LIBSOCKET) # libnsl/inet_pton (Solaris) check_library_exists(nsl inet_pton "" HAVE_LIBNSL) if (HAVE_LIBNSL) - set(_REQUIRED_LIBRARIES ${_REQUIRED_LIBRARIES} nsl) + string(APPEND _REQUIRED_LIBRARIES nsl) endif (HAVE_LIBNSL) endif (NOT LINUX) check_function_exists(getaddrinfo HAVE_GETADDRINFO) endif (UNIX) -set(SWRAP_REQUIRED_LIBRARIES ${_REQUIRED_LIBRARIES} CACHE INTERNAL "socket_wrapper required system libraries") - # STRUCTS check_struct_has_member("struct in_pktinfo" ipi_addr "sys/types.h;sys/socket.h;netinet/in.h" HAVE_STRUCT_IN_PKTINFO) set(CMAKE_REQUIRED_FLAGS -D_GNU_SOURCE) @@ -250,12 +258,6 @@ int main(void) { unset(CMAKE_REQUIRED_FLAGS) ########################################################### -check_library_exists(dl dlopen "" HAVE_LIBDL) -if (HAVE_LIBDL) - find_library(DLFCN_LIBRARY dl) - set(_REQUIRED_LIBRARIES ${_REQUIRED_LIBRARIES} ${DLFCN_LIBRARY}) -endif (HAVE_LIBDL) - if (OSX) set(HAVE_APPLE 1) endif (OSX) @@ -267,4 +269,4 @@ endif (NOT WIN32) check_type_size(pid_t SIZEOF_PID_T) -set(SWRAP_REQUIRED_LIBRARIES ${_REQUIRED_LIBRARIES} CACHE INTERNAL "swrap required system libraries") +set(SWRAP_REQUIRED_LIBRARIES ${_REQUIRED_LIBRARIES} CACHE INTERNAL "socket_wrapper required system libraries") -- cgit