Browse Source

Fix Cmake libpcap detection logic (#943)

* Fix cmake informational log messages

* If the correct library name is used find_library works better

* Re-enable remaining find_library users

* Reorder cmake to make libpcap detection work
pull/945/head
Hamish Coleman 3 years ago
committed by GitHub
parent
commit
e9fccd9932
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 47
      CMakeLists.txt
  2. 4
      configure.ac

47
CMakeLists.txt

@ -50,7 +50,7 @@ if(N2N_OPTION_USE_PTHREAD)
if(NOT PTHREAD_LIB) if(NOT PTHREAD_LIB)
MESSAGE(FATAL_ERROR "libpthread not found.") MESSAGE(FATAL_ERROR "libpthread not found.")
endif(NOT PTHREAD_LIB) endif(NOT PTHREAD_LIB)
MESSAGE(INFO "Using libpthread.") MESSAGE(STATUS "Using libpthread.")
ADD_DEFINITIONS("-DHAVE_PTHREAD") ADD_DEFINITIONS("-DHAVE_PTHREAD")
endif(N2N_OPTION_USE_PTHREAD) endif(N2N_OPTION_USE_PTHREAD)
@ -69,54 +69,49 @@ if(N2N_OPTION_USE_OPENSSL)
endif(N2N_OPTION_USE_OPENSSL) endif(N2N_OPTION_USE_OPENSSL)
if(N2N_OPTION_USE_ZSTD) if(N2N_OPTION_USE_ZSTD)
# TODO: the find_library() call works for some of the config, but not others find_library(LIBZSTD zstd)
#find_library(LIBZSTD libzstd) if(NOT LIBZSTD)
#if(NOT LIBZSTD) MESSAGE(FATAL_ERROR "libzstd not found.")
# MESSAGE(FATAL_ERROR "libzstd not found.") endif(NOT LIBZSTD)
#endif(NOT LIBZSTD) MESSAGE(STATUS "Using libztd.")
MESSAGE(INFO "Using libztd.")
add_definitions(-DN2N_HAVE_ZSTD) add_definitions(-DN2N_HAVE_ZSTD)
endif(N2N_OPTION_USE_ZSTD) endif(N2N_OPTION_USE_ZSTD)
if(N2N_OPTION_USE_PCAPLIB) if(N2N_OPTION_USE_PCAPLIB)
# TODO: the find_library() call works for some of the config, but not others find_library(PCAP_LIB pcap)
#find_library(PCAP_LIB pcap) if(NOT PCAP_LIB)
#if(NOT PCAP_LIB) MESSAGE(FATAL_ERROR "libpcap not found.")
# MESSAGE(FATAL_ERROR "libpcap not found.") endif(NOT PCAP_LIB)
#endif(NOT PCAP_LIB)
# Set var needed for check_function_exists()
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIB})
# TODO # TODO
# - this is different to the configure.ac logic # - pcap_set_immediate_mode has been available since libpcap 1.5 in 2013
# probably should remove this check
check_function_exists(pcap_set_immediate_mode HAVE_PCAP_IMMEDIATE_MODE) check_function_exists(pcap_set_immediate_mode HAVE_PCAP_IMMEDIATE_MODE)
IF(NOT HAVE_PCAP_IMMEDIATE_MODE) IF(NOT HAVE_PCAP_IMMEDIATE_MODE)
MESSAGE(FATAL_ERROR "libpcap not support pcap_set_immediate_mode()") MESSAGE(FATAL_ERROR "libpcap not support pcap_set_immediate_mode()")
ENDIF(NOT HAVE_PCAP_IMMEDIATE_MODE) ENDIF(NOT HAVE_PCAP_IMMEDIATE_MODE)
MESSAGE(INFO "Using libpcap.") MESSAGE(STATUS "Using libpcap.")
ADD_DEFINITIONS("-DHAVE_PCAP_IMMEDIATE_MODE") ADD_DEFINITIONS("-DHAVE_PCAP_IMMEDIATE_MODE")
add_executable(n2n-decode tools/n2n-decode.c) add_executable(n2n-decode tools/n2n-decode.c)
target_link_libraries(n2n-decode n2n pcap) target_link_libraries(n2n-decode n2n pcap)
install(TARGETS n2n-decode RUNTIME DESTINATION bin) install(TARGETS n2n-decode RUNTIME DESTINATION bin)
# TODO:
# - This variable is also set elsewhere, I dont think it works this way
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIB})
endif(N2N_OPTION_USE_PCAPLIB) endif(N2N_OPTION_USE_PCAPLIB)
if(N2N_OPTION_USE_CAPLIB) if(N2N_OPTION_USE_CAPLIB)
# Linux Capabilities # Linux Capabilities
# TODO: the find_library() call works for some of the config, but not others find_library(CAP_LIB cap)
#find_library(CAP_LIB cap) if(NOT CAP_LIB)
#if(NOT CAP_LIB) MESSAGE(FATAL_ERROR "libcap not found.")
# MESSAGE(FATAL_ERROR "libcap not found.") endif(NOT CAP_LIB)
#endif(NOT CAP_LIB) MESSAGE(STATUS "Using libcap.")
MESSAGE(INFO "Using libpcap.")
ADD_DEFINITIONS("-DHAVE_LIBCAP") ADD_DEFINITIONS("-DHAVE_LIBCAP")
# TODO:
# - This variable is also set elsewhere, I dont think it works this way
set(CMAKE_REQUIRED_LIBRARIES ${CAP_LIB})
endif(N2N_OPTION_USE_CAPLIB) endif(N2N_OPTION_USE_CAPLIB)
if(N2N_OPTION_USE_PORTMAPPING) if(N2N_OPTION_USE_PORTMAPPING)

4
configure.ac

@ -92,6 +92,10 @@ AS_IF([test "x$enable_pcap" != xno],
AC_DEFINE([N2N_HAVE_PCAP], [1], [Have PCAP library]) AC_DEFINE([N2N_HAVE_PCAP], [1], [Have PCAP library])
N2N_LIBS="-lpcap ${N2N_LIBS}" N2N_LIBS="-lpcap ${N2N_LIBS}"
ADDITIONAL_TOOLS="$ADDITIONAL_TOOLS n2n-decode" ADDITIONAL_TOOLS="$ADDITIONAL_TOOLS n2n-decode"
# TODO
# - pcap_set_immediate_mode has been available since libpcap 1.5
# in 2013 - probably should remove this check
AC_CHECK_LIB([pcap], [pcap_set_immediate_mode], AC_CHECK_LIB([pcap], [pcap_set_immediate_mode],
AC_DEFINE([HAVE_PCAP_IMMEDIATE_MODE], [1], [Have pcap_immediate_mode]) AC_DEFINE([HAVE_PCAP_IMMEDIATE_MODE], [1], [Have pcap_immediate_mode])
) )

Loading…
Cancel
Save