Fix building uiqt on Windows with the cmake build system:
[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 find_path( PCAP_INCLUDE_DIR
13   NAMES
14   pcap/pcap.h
15   pcap.h
16   HINTS
17     "${PCAP_HINTS}/include"
18 )
19
20 find_library( PCAP_LIBRARY
21   NAMES
22     pcap
23     wpcap
24   HINTS
25     "${PCAP_HINTS}/lib"
26 )
27
28
29 include( FindPackageHandleStandardArgs )
30 find_package_handle_standard_args( PCAP DEFAULT_MSG PCAP_INCLUDE_DIR PCAP_LIBRARY )
31
32 if( PCAP_FOUND )
33   set( PCAP_INCLUDE_DIRS ${PCAP_INCLUDE_DIR} )
34   set( PCAP_LIBRARIES ${PCAP_LIBRARY} )
35 else()
36   set( PCAP_INCLUDE_DIRS )
37   set( PCAP_LIBRARIES )
38 endif()
39
40 #Functions
41 include( CMakePushCheckState )
42 include( CheckFunctionExists )
43 include( CheckVariableExists )
44
45 cmake_push_check_state()
46 set( CMAKE_REQUIRED_INCLUDES ${PCAP_INCLUDE_DIRS} )
47 set( CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARIES} )
48
49 check_function_exists( "pcap_open_dead" HAVE_PCAP_OPEN_DEAD )
50 check_function_exists( "pcap_freecode" HAVE_PCAP_FREECODE )
51 #
52 # Note: for pcap_breakloop() and pcap_findalldevs(), the autoconf script
53 # checks for more than just whether the function exists, it also checks
54 # for whether pcap.h declares it; Mac OS X software/security updates can
55 # update libpcap without updating the headers.
56 #
57 check_function_exists( "pcap_breakloop" HAVE_PCAP_BREAKLOOP )
58 /* FIXME: The code (at least) in dumpcap assumes that PCAP_CREATE is not
59  *        available on Windows */
60 if( NOT WIN32 )
61   check_function_exists( "pcap_create" HAVE_PCAP_CREATE )
62 endif()
63 check_function_exists( "pcap_datalink_name_to_val" HAVE_PCAP_DATALINK_NAME_TO_VAL )
64 check_function_exists( "pcap_datalink_val_to_description" HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION )
65 check_function_exists( "pcap_datalink_val_to_name" HAVE_PCAP_DATALINK_VAL_TO_NAME )
66 check_function_exists( "pcap_findalldevs" HAVE_PCAP_FINDALLDEVS )
67 check_function_exists( "pcap_free_datalinks" HAVE_PCAP_FREE_DATALINKS )
68 check_function_exists( "pcap_get_selectable_fd" HAVE_PCAP_GET_SELECTABLE_FD )
69 check_function_exists( "pcap_lib_version" HAVE_PCAP_LIB_VERSION )
70 check_function_exists( "pcap_list_datalinks" HAVE_PCAP_LIST_DATALINKS )
71 check_function_exists( "pcap_set_datalink" HAVE_PCAP_SET_DATALINK )
72 check_function_exists( "bpf_image" HAVE_BPF_IMAGE )
73 # Remote pcap checks
74 check_function_exists( "pcap_open" H_PCAP_OPEN )
75 check_function_exists( "pcap_findalldevs_ex" H_FINDALLDEVS_EX )
76 check_function_exists( "pcap_createsrcstr" H_CREATESRCSTR )
77 if( H_PCAP_OPEN AND H_FINDALLDEVS_EX AND H_CREATESRCSTR )
78   set( HAVE_PCAP_REMOTE 1 )
79   set( HAVE_REMOTE 1 )
80 endif()
81
82 cmake_pop_check_state()
83
84 mark_as_advanced( PCAP_LIBRARIES PCAP_INCLUDE_DIRS )