|
@@ -0,0 +1,74 @@
|
|
1
|
+# - Try to find libpcap include dirs and libraries
|
|
2
|
+#
|
|
3
|
+# Usage of this module as follows:
|
|
4
|
+#
|
|
5
|
+# find_package(PCAP)
|
|
6
|
+#
|
|
7
|
+# Variables used by this module, they can change the default behaviour and need
|
|
8
|
+# to be set before calling find_package:
|
|
9
|
+#
|
|
10
|
+# PCAP_ROOT_DIR Set this variable to the root installation of
|
|
11
|
+# libpcap if the module has problems finding the
|
|
12
|
+# proper installation path.
|
|
13
|
+#
|
|
14
|
+# Variables defined by this module:
|
|
15
|
+#
|
|
16
|
+# PCAP_FOUND System has libpcap, include and library dirs found
|
|
17
|
+# PCAP_INCLUDE_DIR The libpcap include directories.
|
|
18
|
+# PCAP_LIBRARY The libpcap library (possibly includes a thread
|
|
19
|
+# library e.g. required by pf_ring's libpcap)
|
|
20
|
+# HAVE_PF_RING If a found version of libpcap supports PF_RING
|
|
21
|
+
|
|
22
|
+find_path(PCAP_ROOT_DIR
|
|
23
|
+ NAMES include/pcap.h
|
|
24
|
+ )
|
|
25
|
+
|
|
26
|
+find_path(PCAP_INCLUDE_DIR
|
|
27
|
+ NAMES pcap.h
|
|
28
|
+ HINTS ${PCAP_ROOT_DIR}/include
|
|
29
|
+ )
|
|
30
|
+
|
|
31
|
+find_library(PCAP_LIBRARY
|
|
32
|
+ NAMES pcap
|
|
33
|
+ HINTS ${PCAP_ROOT_DIR}/lib
|
|
34
|
+ )
|
|
35
|
+
|
|
36
|
+include(FindPackageHandleStandardArgs)
|
|
37
|
+find_package_handle_standard_args(PCAP DEFAULT_MSG
|
|
38
|
+ PCAP_LIBRARY
|
|
39
|
+ PCAP_INCLUDE_DIR
|
|
40
|
+ )
|
|
41
|
+
|
|
42
|
+include(CheckCSourceCompiles)
|
|
43
|
+set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY})
|
|
44
|
+check_c_source_compiles("int main() { return 0; }" PCAP_LINKS_SOLO)
|
|
45
|
+set(CMAKE_REQUIRED_LIBRARIES)
|
|
46
|
+
|
|
47
|
+# check if linking against libpcap also needs to link against a thread library
|
|
48
|
+if (NOT PCAP_LINKS_SOLO)
|
|
49
|
+ find_package(Threads)
|
|
50
|
+ if (THREADS_FOUND)
|
|
51
|
+ set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
|
|
52
|
+ check_c_source_compiles("int main() { return 0; }" PCAP_NEEDS_THREADS)
|
|
53
|
+ set(CMAKE_REQUIRED_LIBRARIES)
|
|
54
|
+ endif ()
|
|
55
|
+ if (THREADS_FOUND AND PCAP_NEEDS_THREADS)
|
|
56
|
+ set(_tmp ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
|
|
57
|
+ list(REMOVE_DUPLICATES _tmp)
|
|
58
|
+ set(PCAP_LIBRARY ${_tmp}
|
|
59
|
+ CACHE STRING "Libraries needed to link against libpcap" FORCE)
|
|
60
|
+ else ()
|
|
61
|
+ message(FATAL_ERROR "Couldn't determine how to link against libpcap")
|
|
62
|
+ endif ()
|
|
63
|
+endif ()
|
|
64
|
+
|
|
65
|
+include(CheckFunctionExists)
|
|
66
|
+set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY})
|
|
67
|
+check_function_exists(pcap_get_pfring_id HAVE_PF_RING)
|
|
68
|
+set(CMAKE_REQUIRED_LIBRARIES)
|
|
69
|
+
|
|
70
|
+mark_as_advanced(
|
|
71
|
+ PCAP_ROOT_DIR
|
|
72
|
+ PCAP_INCLUDE_DIR
|
|
73
|
+ PCAP_LIBRARY
|
|
74
|
+)
|