Revert "Get rid of HAVE_REMOTE."
[metze/wireshark/wip.git] / cmake / modules / FindPCAP.cmake
1 #
2 # - Find pcap and winpcap
3 # Find the native PCAP includes and library
4 #
5 #  PCAP_INCLUDE_DIRS - where to find pcap.h, etc.
6 #  PCAP_LIBRARIES    - List of libraries when using pcap.
7 #  PCAP_FOUND        - True if pcap found.
8
9 include( FindWSWinLibs )
10 FindWSWinLibs( "WpdPack" "PCAP_HINTS" )
11
12 # The 64-bit wpcap.lib is under /x64
13 set ( _PLATFORM_SUBDIR "" )
14 if( WIN32 AND "${WIRESHARK_TARGET_PLATFORM}" STREQUAL "win64" )
15   set ( _PLATFORM_SUBDIR "/x64" )
16 endif()
17
18 find_path( PCAP_INCLUDE_DIR
19   NAMES
20   pcap/pcap.h
21   pcap.h
22   HINTS
23     "${PCAP_HINTS}/include"
24 )
25
26 find_library( PCAP_LIBRARY
27   NAMES
28     pcap
29     wpcap
30   HINTS
31     "${PCAP_HINTS}/lib${_PLATFORM_SUBDIR}"
32 )
33
34
35 include( FindPackageHandleStandardArgs )
36 find_package_handle_standard_args( PCAP DEFAULT_MSG PCAP_INCLUDE_DIR PCAP_LIBRARY )
37
38 if( PCAP_FOUND )
39   set( PCAP_INCLUDE_DIRS ${PCAP_INCLUDE_DIR} )
40   set( PCAP_LIBRARIES ${PCAP_LIBRARY} )
41 else()
42   set( PCAP_INCLUDE_DIRS )
43   set( PCAP_LIBRARIES )
44 endif()
45
46 if( PCAP_FOUND )
47   #Functions
48   include( CMakePushCheckState )
49   include( CheckFunctionExists )
50   include( CheckVariableExists )
51
52   cmake_push_check_state()
53   set( CMAKE_REQUIRED_INCLUDES ${PCAP_INCLUDE_DIRS} )
54   set( CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARIES} )
55
56   check_function_exists( "pcap_open_dead" HAVE_PCAP_OPEN_DEAD )
57   check_function_exists( "pcap_freecode" HAVE_PCAP_FREECODE )
58   #
59   # Note: for pcap_breakloop() and pcap_findalldevs(), the autoconf script
60   # checks for more than just whether the function exists, it also checks
61   # for whether pcap.h declares it; macOS software/security updates can
62   # update libpcap without updating the headers.
63   #
64   check_function_exists( "pcap_breakloop" HAVE_PCAP_BREAKLOOP )
65   check_function_exists( "pcap_create" HAVE_PCAP_CREATE )
66   if( HAVE_PCAP_CREATE OR WIN32 )
67     #
68     # If we have pcap_create(), we have pcap_set_buffer_size(), and
69     # can set the capture buffer size.
70     #
71     # Otherwise, if this is Windows, we have pcap_setbuff(), and can
72     # set the capture buffer size.
73     #
74     set( CAN_SET_CAPTURE_BUFFER_SIZE TRUE )
75   endif()
76   check_function_exists( "pcap_datalink_name_to_val" HAVE_PCAP_DATALINK_NAME_TO_VAL )
77   check_function_exists( "pcap_datalink_val_to_description" HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION )
78   check_function_exists( "pcap_datalink_val_to_name" HAVE_PCAP_DATALINK_VAL_TO_NAME )
79   check_function_exists( "pcap_findalldevs" HAVE_PCAP_FINDALLDEVS )
80   check_function_exists( "pcap_free_datalinks" HAVE_PCAP_FREE_DATALINKS )
81   check_function_exists( "pcap_get_selectable_fd" HAVE_PCAP_GET_SELECTABLE_FD )
82   check_function_exists( "pcap_lib_version" HAVE_PCAP_LIB_VERSION )
83   check_function_exists( "pcap_list_datalinks" HAVE_PCAP_LIST_DATALINKS )
84   check_function_exists( "pcap_set_datalink" HAVE_PCAP_SET_DATALINK )
85   check_function_exists( "bpf_image" HAVE_BPF_IMAGE )
86   check_function_exists( "pcap_setsampling" HAVE_PCAP_SETSAMPLING )
87   check_function_exists( "pcap_set_tstamp_precision" HAVE_PCAP_SET_TSTAMP_PRECISION )
88   # Remote pcap checks
89   check_function_exists( "pcap_open" HAVE_PCAP_OPEN )
90   if( HAVE_PCAP_OPEN )
91     set( HAVE_PCAP_REMOTE 1 )
92     set( HAVE_REMOTE 1 )
93   endif()
94
95   cmake_pop_check_state()
96 endif()
97
98 mark_as_advanced( PCAP_LIBRARIES PCAP_INCLUDE_DIRS )