Warning, /plasma/libksysguard/cmake/Findlibpcap.cmake is written in an unsupported language. File is not indexed.

0001 # SPDX-FileCopyrightText: 1995-2017 The Regents of the University of California
0002 # through the Lawrence Berkeley National Laboratory and the
0003 # International Computer Science Institute. All rights reserved.
0004 # SPDX-License-Identifier: BSD-3-Clause
0005 
0006 # - Try to find libpcap include dirs and libraries
0007 #
0008 # Usage of this module as follows:
0009 #
0010 #     find_package(libpcap)
0011 #
0012 # Variables used by this module, they can change the default behaviour and need
0013 # to be set before calling find_package:
0014 #
0015 #  PCAP_ROOT_DIR             Set this variable to the root installation of
0016 #                            libpcap if the module has problems finding the
0017 #                            proper installation path.
0018 #
0019 # Variables defined by this module:
0020 #
0021 #  PCAP_FOUND                System has libpcap, include and library dirs found
0022 #  PCAP_INCLUDE_DIR          The libpcap include directories.
0023 #  PCAP_LIBRARY              The libpcap library (possibly includes a thread
0024 #                            library e.g. required by pf_ring's libpcap)
0025 #  HAVE_PF_RING              If a found version of libpcap supports PF_RING
0026 
0027 find_path(PCAP_ROOT_DIR
0028     NAMES include/pcap.h
0029 )
0030 
0031 find_path(PCAP_INCLUDE_DIR
0032     NAMES pcap.h
0033     HINTS ${PCAP_ROOT_DIR}/include
0034 )
0035 
0036 find_library(PCAP_LIBRARY
0037     NAMES pcap
0038     HINTS ${PCAP_ROOT_DIR}/lib
0039 )
0040 
0041 include(FindPackageHandleStandardArgs)
0042 find_package_handle_standard_args(libpcap DEFAULT_MSG
0043     PCAP_LIBRARY
0044     PCAP_INCLUDE_DIR
0045 )
0046 
0047 include(CheckCSourceCompiles)
0048 set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY})
0049 check_c_source_compiles("int main() { return 0; }" PCAP_LINKS_SOLO)
0050 set(CMAKE_REQUIRED_LIBRARIES)
0051 
0052 # check if linking against libpcap also needs to link against a thread library
0053 if (NOT PCAP_LINKS_SOLO)
0054     find_package(Threads)
0055     if (THREADS_FOUND)
0056         set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
0057         check_c_source_compiles("int main() { return 0; }" PCAP_NEEDS_THREADS)
0058         set(CMAKE_REQUIRED_LIBRARIES)
0059     endif ()
0060     if (THREADS_FOUND AND PCAP_NEEDS_THREADS)
0061         set(_tmp ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
0062         list(REMOVE_DUPLICATES _tmp)
0063         set(PCAP_LIBRARY ${_tmp}
0064             CACHE STRING "Libraries needed to link against libpcap" FORCE)
0065     else ()
0066         message(FATAL_ERROR "Couldn't determine how to link against libpcap")
0067     endif ()
0068 endif ()
0069 
0070 include(CheckFunctionExists)
0071 set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY})
0072 check_function_exists(pcap_get_pfring_id HAVE_PF_RING)
0073 set(CMAKE_REQUIRED_LIBRARIES)
0074 
0075 mark_as_advanced(
0076     PCAP_ROOT_DIR
0077     PCAP_INCLUDE_DIR
0078     PCAP_LIBRARY
0079 )