Changeset View
Changeset View
Standalone View
Standalone View
cmake/Findlibpcap.cmake
- This file was added.
1 | # Copyright (c) 1995-2017, The Regents of the University of California | ||||
---|---|---|---|---|---|
2 | # through the Lawrence Berkeley National Laboratory and the | ||||
3 | # International Computer Science Institute. All rights reserved. | ||||
4 | # | ||||
5 | # Redistribution and use in source and binary forms, with or without | ||||
6 | # modification, are permitted provided that the following conditions are met: | ||||
7 | # | ||||
8 | # (1) Redistributions of source code must retain the above copyright | ||||
9 | # notice, this list of conditions and the following disclaimer. | ||||
10 | # | ||||
11 | # (2) Redistributions in binary form must reproduce the above copyright | ||||
12 | # notice, this list of conditions and the following disclaimer in the | ||||
13 | # documentation and/or other materials provided with the distribution. | ||||
14 | # | ||||
15 | # (3) Neither the name of the University of California, Lawrence Berkeley | ||||
16 | # National Laboratory, U.S. Dept. of Energy, International Computer | ||||
17 | # Science Institute, nor the names of contributors may be used to endorse | ||||
18 | # or promote products derived from this software without specific prior | ||||
19 | # written permission. | ||||
20 | # | ||||
21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||||
22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||||
23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||||
24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||||
25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||||
26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||||
27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||||
28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||||
29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||||
30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||||
31 | # POSSIBILITY OF SUCH DAMAGE. | ||||
32 | # | ||||
33 | # Note that some files in the distribution may carry their own copyright | ||||
34 | # notices. | ||||
35 | | ||||
36 | | ||||
37 | # - Try to find libpcap include dirs and libraries | ||||
38 | # | ||||
39 | # Usage of this module as follows: | ||||
40 | # | ||||
41 | # find_package(libpcap) | ||||
42 | # | ||||
43 | # Variables used by this module, they can change the default behaviour and need | ||||
44 | # to be set before calling find_package: | ||||
45 | # | ||||
46 | # PCAP_ROOT_DIR Set this variable to the root installation of | ||||
47 | # libpcap if the module has problems finding the | ||||
48 | # proper installation path. | ||||
49 | # | ||||
50 | # Variables defined by this module: | ||||
51 | # | ||||
52 | # PCAP_FOUND System has libpcap, include and library dirs found | ||||
53 | # PCAP_INCLUDE_DIR The libpcap include directories. | ||||
54 | # PCAP_LIBRARY The libpcap library (possibly includes a thread | ||||
55 | # library e.g. required by pf_ring's libpcap) | ||||
56 | # HAVE_PF_RING If a found version of libpcap supports PF_RING | ||||
57 | | ||||
58 | find_path(PCAP_ROOT_DIR | ||||
59 | NAMES include/pcap.h | ||||
60 | ) | ||||
61 | | ||||
62 | find_path(PCAP_INCLUDE_DIR | ||||
63 | NAMES pcap.h | ||||
64 | HINTS ${PCAP_ROOT_DIR}/include | ||||
65 | ) | ||||
66 | | ||||
67 | find_library(PCAP_LIBRARY | ||||
68 | NAMES pcap | ||||
69 | HINTS ${PCAP_ROOT_DIR}/lib | ||||
70 | ) | ||||
71 | | ||||
72 | include(FindPackageHandleStandardArgs) | ||||
73 | find_package_handle_standard_args(libpcap DEFAULT_MSG | ||||
74 | PCAP_LIBRARY | ||||
75 | PCAP_INCLUDE_DIR | ||||
76 | ) | ||||
77 | | ||||
78 | include(CheckCSourceCompiles) | ||||
79 | set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY}) | ||||
80 | check_c_source_compiles("int main() { return 0; }" PCAP_LINKS_SOLO) | ||||
81 | set(CMAKE_REQUIRED_LIBRARIES) | ||||
82 | | ||||
83 | # check if linking against libpcap also needs to link against a thread library | ||||
84 | if (NOT PCAP_LINKS_SOLO) | ||||
85 | find_package(Threads) | ||||
86 | if (THREADS_FOUND) | ||||
87 | set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT}) | ||||
88 | check_c_source_compiles("int main() { return 0; }" PCAP_NEEDS_THREADS) | ||||
89 | set(CMAKE_REQUIRED_LIBRARIES) | ||||
90 | endif () | ||||
91 | if (THREADS_FOUND AND PCAP_NEEDS_THREADS) | ||||
92 | set(_tmp ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT}) | ||||
93 | list(REMOVE_DUPLICATES _tmp) | ||||
94 | set(PCAP_LIBRARY ${_tmp} | ||||
95 | CACHE STRING "Libraries needed to link against libpcap" FORCE) | ||||
96 | else () | ||||
97 | message(FATAL_ERROR "Couldn't determine how to link against libpcap") | ||||
98 | endif () | ||||
99 | endif () | ||||
100 | | ||||
101 | include(CheckFunctionExists) | ||||
102 | set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY}) | ||||
103 | check_function_exists(pcap_get_pfring_id HAVE_PF_RING) | ||||
104 | set(CMAKE_REQUIRED_LIBRARIES) | ||||
105 | | ||||
106 | mark_as_advanced( | ||||
107 | PCAP_ROOT_DIR | ||||
108 | PCAP_INCLUDE_DIR | ||||
109 | PCAP_LIBRARY | ||||
110 | ) |