Debian Codegraph @

cmake/FindPCAP.cmake

raw
1 # Note: copied from https://code.google.com/p/loganon/source/browse/cmake/FindPCAP.cmake
2 # added library name wpcap (for WinPcap)
3
4 ###################################################################
5 #
6 # Copyright (c) 2006 Frederic Heem, <[email protected]>
7 # All rights reserved.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
11 # are met:
12 #
13 # * Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 #
16 # * Redistributions in binary form must reproduce the above copyright
17 # notice, this list of conditions and the following disclaimer in
18 # the documentation and/or other materials provided with the
19 # distribution.
20 #
21 # * Neither the name of the Telsey nor the names of its
22 # contributors may be used to endorse or promote products derived
23 # from this software without specific prior written permission.
24 #
25 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 # POSSIBILITY OF SUCH DAMAGE.
37 #
38 ###################################################################
39 # - Find pcap
40 # Find the PCAP includes and library
41 # http://www.tcpdump.org/
42 #
43 # The environment variable PCAPDIR allows to specficy where to find
44 # libpcap in non standard location.
45 #
46 # PCAP_INCLUDE_DIRS - where to find pcap.h, etc.
47 # PCAP_LIBRARIES - List of libraries when using pcap.
48 # PCAP_FOUND - True if pcap found.
49
50
51 IF(EXISTS $ENV{PCAPDIR})
52 FIND_PATH(PCAP_INCLUDE_DIR
53 NAMES
54 pcap/pcap.h
55 pcap.h
56 PATHS
57 $ENV{PCAPDIR}
58 NO_DEFAULT_PATH
59 )
60
61 FIND_LIBRARY(PCAP_LIBRARY
62 NAMES
63 pcap
64 PATHS
65 $ENV{PCAPDIR}
66 NO_DEFAULT_PATH
67 )
68
69
70 ELSE(EXISTS $ENV{PCAPDIR})
71 FIND_PATH(PCAP_INCLUDE_DIR
72 NAMES
73 pcap/pcap.h
74 pcap.h
75 )
76
77 FIND_LIBRARY(PCAP_LIBRARY
78 NAMES
79 pcap wpcap
80 )
81
82 ENDIF(EXISTS $ENV{PCAPDIR})
83
84 SET(PCAP_INCLUDE_DIRS ${PCAP_INCLUDE_DIR})
85 SET(PCAP_LIBRARIES ${PCAP_LIBRARY})
86
87 IF(PCAP_INCLUDE_DIRS)
88 MESSAGE(STATUS "Pcap include dirs set to ${PCAP_INCLUDE_DIRS}")
89 ELSE(PCAP_INCLUDE_DIRS)
90 MESSAGE(FATAL " Pcap include dirs cannot be found")
91 ENDIF(PCAP_INCLUDE_DIRS)
92
93 IF(PCAP_LIBRARIES)
94 MESSAGE(STATUS "Pcap library set to ${PCAP_LIBRARIES}")
95 ELSE(PCAP_LIBRARIES)
96 MESSAGE(FATAL "Pcap library cannot be found")
97 ENDIF(PCAP_LIBRARIES)
98
99 #Functions
100 if ( 0 )# not needed in dynamips
101 INCLUDE(CheckFunctionExists)
102 SET(CMAKE_REQUIRED_INCLUDES ${PCAP_INCLUDE_DIRS})
103 SET(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARIES})
104 CHECK_FUNCTION_EXISTS("pcap_breakloop" HAVE_PCAP_BREAKLOOP)
105 CHECK_FUNCTION_EXISTS("pcap_datalink_name_to_val" HAVE_PCAP_DATALINK_NAME_TO_VAL)
106 CHECK_FUNCTION_EXISTS("pcap_datalink_val_to_name" HAVE_PCAP_DATALINK_VAL_TO_NAME)
107 CHECK_FUNCTION_EXISTS("pcap_findalldevs" HAVE_PCAP_FINDALLDEVS)
108 CHECK_FUNCTION_EXISTS("pcap_freecode" HAVE_PCAP_FREECODE)
109 CHECK_FUNCTION_EXISTS("pcap_get_selectable_fd" HAVE_PCAP_GET_SELECTABLE_FD)
110 CHECK_FUNCTION_EXISTS("pcap_lib_version" HAVE_PCAP_LIB_VERSION)
111 CHECK_FUNCTION_EXISTS("pcap_list_datalinks" HAVE_PCAP_LIST_DATALINKS)
112 CHECK_FUNCTION_EXISTS("pcap_open_dead" HAVE_PCAP_OPEN_DEAD)
113 CHECK_FUNCTION_EXISTS("pcap_set_datalink" HAVE_PCAP_SET_DATALINK)
114 endif ()
115
116
117 #Is pcap found ?
118 IF(PCAP_INCLUDE_DIRS AND PCAP_LIBRARIES)
119 SET( PCAP_FOUND "YES" )
120 ENDIF(PCAP_INCLUDE_DIRS AND PCAP_LIBRARIES)
121
122
123 MARK_AS_ADVANCED(
124 PCAP_LIBRARIES
125 PCAP_INCLUDE_DIRS
126 )