Fix CMake checks of PCap functions, along with AirPCap
[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 "$ENV{WIRESHARK_TARGET_PLATFORM}" MATCHES "64" )
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 #Functions
47 include( CMakePushCheckState )
48 include( CheckFunctionExists )
49 include( CheckVariableExists )
50
51 cmake_push_check_state()
52 set( CMAKE_REQUIRED_INCLUDES ${PCAP_INCLUDE_DIRS} )
53 set( CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARIES} )
54
55 check_function_exists( "pcap_open_dead" HAVE_PCAP_OPEN_DEAD )
56 check_function_exists( "pcap_freecode" HAVE_PCAP_FREECODE )
57 #
58 # Note: for pcap_breakloop() and pcap_findalldevs(), the autoconf script
59 # checks for more than just whether the function exists, it also checks
60 # for whether pcap.h declares it; Mac OS X software/security updates can
61 # update libpcap without updating the headers.
62 #
63 check_function_exists( "pcap_breakloop" HAVE_PCAP_BREAKLOOP )
64 # FIXME: The code (at least) in dumpcap assumes that PCAP_CREATE is not
65 #        available on Windows
66 if( NOT WIN32 )
67   check_function_exists( "pcap_create" HAVE_PCAP_CREATE )
68 endif()
69 check_function_exists( "pcap_datalink_name_to_val" HAVE_PCAP_DATALINK_NAME_TO_VAL )
70 check_function_exists( "pcap_datalink_val_to_description" HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION )
71 check_function_exists( "pcap_datalink_val_to_name" HAVE_PCAP_DATALINK_VAL_TO_NAME )
72 check_function_exists( "pcap_findalldevs" HAVE_PCAP_FINDALLDEVS )
73 check_function_exists( "pcap_free_datalinks" HAVE_PCAP_FREE_DATALINKS )
74 check_function_exists( "pcap_get_selectable_fd" HAVE_PCAP_GET_SELECTABLE_FD )
75 check_function_exists( "pcap_lib_version" HAVE_PCAP_LIB_VERSION )
76 check_function_exists( "pcap_list_datalinks" HAVE_PCAP_LIST_DATALINKS )
77 check_function_exists( "pcap_set_datalink" HAVE_PCAP_SET_DATALINK )
78 check_function_exists( "bpf_image" HAVE_BPF_IMAGE )
79 check_function_exists( "pcap_setsampling" HAVE_PCAP_SETSAMPLING )
80 # Remote pcap checks
81 check_function_exists( "pcap_open" HAVE_PCAP_OPEN )
82 check_function_exists( "pcap_findalldevs_ex" H_FINDALLDEVS_EX )
83 check_function_exists( "pcap_createsrcstr" H_CREATESRCSTR )
84 if( HAVE_PCAP_OPEN AND H_FINDALLDEVS_EX AND H_CREATESRCSTR )
85   set( HAVE_PCAP_REMOTE 1 )
86   set( HAVE_REMOTE 1 )
87 endif()
88
89 cmake_pop_check_state()
90
91 mark_as_advanced( PCAP_LIBRARIES PCAP_INCLUDE_DIRS )