]> The Tcpdump Group git mirrors - libpcap/blob - CMakeLists.txt
Fix typpo.
[libpcap] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8.6)
2
3 #
4 # Apple doesn't build with an install_name starting with @rpath, and
5 # neither do we with autotools; don't do so with CMake, either, and
6 # suppress warnings about that.
7 #
8 if(POLICY CMP0042)
9 cmake_policy(SET CMP0042 OLD)
10 endif()
11
12 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
13
14 project(pcap)
15
16 ###################################################################
17 # Parameters
18 ###################################################################
19
20 if(WIN32)
21 #
22 # On Windows, allow the library name to be overridden, for the
23 # benefit of projects that combine libpcap with their own
24 # kernel-mode code to support capturing.
25 #
26 set(LIBRARY_NAME pcap CACHE STRING "Library name")
27 else()
28 #
29 # On UN*X, it's always been libpcap.
30 #
31 set(LIBRARY_NAME pcap)
32 endif()
33
34 option(INET6 "Enable IPv6" ON)
35 if(WIN32)
36 option(USE_STATIC_RT "Use static Runtime" ON)
37 endif(WIN32)
38 option(BUILD_SHARED_LIBS "Build shared libraries" ON)
39 if(WIN32)
40 set(PACKET_DLL_DIR "" CACHE PATH "Path to directory with include and lib subdirectories for packet.dll")
41 endif(WIN32)
42
43 # To pacify those who hate the protochain instruction
44 option(NO_PROTOCHAIN "Disable protochain instruction" OFF)
45
46 #
47 # Start out with the capture mechanism type unspecified; the user
48 # can explicitly specify it and, if they don't, we'll pick an
49 # appropriate one.
50 #
51 set(PCAP_TYPE "" CACHE STRING "Packet capture type")
52
53 #
54 # Default to having remote capture support on Windows and, for now, to
55 # not having it on UN*X.
56 #
57 if(WIN32)
58 option(ENABLE_REMOTE "Enable remote capture" ON)
59 else()
60 option(ENABLE_REMOTE "Enable remote capture" OFF)
61 endif(WIN32)
62
63 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
64 option(PCAP_SUPPORT_PACKET_RING "Enable Linux packet ring support" ON)
65 option(BUILD_WITH_LIBNL "Build with libnl" ON)
66 endif()
67
68 #
69 # By default, build universal with the appropriate set of architectures
70 # for the OS on which we're doing the build.
71 #
72 if(APPLE AND "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "")
73 #
74 # Get the major version of Darwin.
75 #
76 string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MAJOR "${CMAKE_SYSTEM_VERSION}")
77
78 if(SYSTEM_VERSION_MAJOR LESS 8)
79 #
80 # Pre-Tiger. Build only for 32-bit PowerPC.
81 #
82 set(CMAKE_OSX_ARCHITECTURES "ppc")
83 elseif(SYSTEM_VERSION_MAJOR EQUAL 8)
84 #
85 # Tiger. Is this prior to, or with, Intel support?
86 #
87 # Get the minor version of Darwin.
88 #
89 string(REPLACE "${SYSTEM_VERSION_MAJOR}." "" SYSTEM_MINOR_AND_PATCH_VERSION ${CMAKE_SYSTEM_VERSION})
90 string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MINOR "${SYSTEM_MINOR_AND_PATCH_VERSION}")
91 if(SYSTEM_VERSION_MINOR LESS 4)
92 #
93 # Prior to Intel support. Build for 32-bit
94 # PowerPC and 64-bit PowerPC, with 32-bit PowerPC
95 # first. (I'm guessing that's what Apple does.)
96 #
97 set(CMAKE_OSX_ARCHITECTURES "ppc;ppc64")
98 elseif(SYSTEM_VERSION_MINOR LESS 7)
99 #
100 # With Intel support but prior to x86-64 support.
101 # Build for 32-bit PowerPC, 64-bit PowerPC, and x86,
102 # with 32-bit PowerPC first.
103 # (I'm guessing that's what Apple does.)
104 #
105 set(CMAKE_OSX_ARCHITECTURES "ppc;ppc64;i386")
106 else()
107 #
108 # With Intel support including x86-64 support.
109 # Build for 32-bit PowerPC, 64-bit PowerPC, x86,
110 # and x86-64, with 32-bit PowerPC first.
111 # (I'm guessing that's what Apple does.)
112 #
113 set(CMAKE_OSX_ARCHITECTURES "ppc;ppc64;i386;x86_64")
114 endif()
115 elseif(SYSTEM_VERSION_MAJOR EQUAL 9)
116 #
117 # Leopard. Build for 32-bit PowerPC, 64-bit
118 # PowerPC, x86, and x86-64, with 32-bit PowerPC
119 # first. (That's what Apple does.)
120 #
121 set(CMAKE_OSX_ARCHITECTURES "ppc;ppc64;i386;x86_64")
122 elseif(SYSTEM_VERSION_MAJOR EQUAL 10)
123 #
124 # Snow Leopard. Build for x86-64, x86, and
125 # 32-bit PowerPC, with x86-64 first. (That's
126 # what Apple does, even though Snow Leopard
127 # doesn't run on PPC, so PPC libpcap runs under
128 # Rosetta, and Rosetta doesn't support BPF
129 # ioctls, so PPC programs can't do live
130 # captures.)
131 #
132 set(CMAKE_OSX_ARCHITECTURES "x86_64;i386;ppc")
133 else()
134 #
135 # Post-Snow Leopard. Build for x86-64 and
136 # x86, with x86-64 first. (That's probably what
137 # Apple does, given that Rosetta is gone.)
138 # XXX - update if and when Apple drops support
139 # for 32-bit x86 code.
140 #
141 set(CMAKE_OSX_ARCHITECTURES "x86_64;i386")
142 endif()
143 endif()
144
145 #
146 # Additional capture modules.
147 #
148 option(DISABLE_USB "Disable USB sniffing support" OFF)
149 option(DISABLE_BLUETOOTH "Disable Bluetooth sniffing support" OFF)
150 option(DISABLE_NETMAP "Disable netmap support" OFF)
151 #
152 # We don't support D-Bus sniffing on macOS; see
153 #
154 # https://bugs.freedesktop.org/show_bug.cgi?id=74029
155 #
156 if(APPLE)
157 option(DISABLE_DBUS "Disable D-Bus sniffing support" ON)
158 else(APPLE)
159 option(DISABLE_DBUS "Disable D-Bus sniffing support" OFF)
160 endif(APPLE)
161 option(DISABLE_RDMA "Disable RDMA sniffing support" OFF)
162
163 option(DISABLE_DAG "Disable Endace DAG card support" OFF)
164
165 option(DISABLE_SEPTEL "Disable Septel card support" OFF)
166 set(SEPTEL_ROOT "${CMAKE_SOURCE_DIR}/../septel" CACHE PATH "Path to directory with include and lib subdirectories for Septel API")
167
168 option(DISABLE_SNF "Disable Myricom SNF support" OFF)
169
170 option(DISABLE_TC "Disable Riverbed TurboCap support" OFF)
171
172 #
173 # Debugging options.
174 #
175 option(BDEBUG "Build optimizer debugging code" OFF)
176 option(YYDEBUG "Build parser debugging code" OFF)
177
178 ###################################################################
179 # Versioning
180 ###################################################################
181
182 # Get, parse, format and set pcap's version string from [pcap_root]/VERSION
183 # for later use.
184
185 # Get MAJOR, MINOR, PATCH & SUFFIX
186 file(STRINGS ${pcap_SOURCE_DIR}/VERSION
187 PACKAGE_VERSION
188 LIMIT_COUNT 1 # Read only the first line
189 )
190
191 # Get "just" MAJOR
192 string(REGEX MATCH "^([0-9]+)" PACKAGE_VERSION_MAJOR "${PACKAGE_VERSION}")
193
194 # Get MAJOR, MINOR & PATCH
195 string(REGEX MATCH "^([0-9]+.)?([0-9]+.)?([0-9]+)" PACKAGE_VERSION_NOSUFFIX "${PACKAGE_VERSION}")
196
197 if(WIN32)
198 # Convert PCAP_VERSION_NOSUFFIX to Windows preferred version format
199 string(REPLACE "." "," PACKAGE_VERSION_PREDLL ${PACKAGE_VERSION_NOSUFFIX})
200
201 # Append NANO (used for Windows internal versioning) to PCAP_VERSION_PREDLL
202 # 0 means unused.
203 set(PACKAGE_VERSION_DLL ${PACKAGE_VERSION_PREDLL},0)
204 endif(WIN32)
205
206 set(PACKAGE_NAME "${LIBRARY_NAME}")
207 set(PACKAGE_STRING "${LIBRARY_NAME} ${PACKAGE_VERSION}")
208
209 ######################################
210 # Project settings
211 ######################################
212
213 add_definitions(-DHAVE_CONFIG_H)
214
215 include_directories(
216 ${CMAKE_CURRENT_BINARY_DIR}
217 ${pcap_SOURCE_DIR}
218 )
219
220 include(CheckFunctionExists)
221 include(CMakePushCheckState)
222
223 if(WIN32)
224
225 if(IS_DIRECTORY ${CMAKE_HOME_DIRECTORY}/../../Common)
226 include_directories(${CMAKE_HOME_DIRECTORY}/../../Common)
227 endif(IS_DIRECTORY ${CMAKE_HOME_DIRECTORY}/../../Common)
228
229 find_package(Packet)
230 if(PACKET_FOUND)
231 set(HAVE_PACKET32 TRUE)
232 include_directories(${PACKET_INCLUDE_DIR})
233 #
234 # Check whether we have the NPcap PacketIsLoopbackAdapter()
235 # function.
236 #
237 cmake_push_check_state()
238 set(CMAKE_REQUIRED_LIBRARIES ${PACKET_LIBRARY})
239 check_function_exists(PacketIsLoopbackAdapter HAVE_PACKET_IS_LOOPBACK_ADAPTER)
240 cmake_pop_check_state()
241 endif(PACKET_FOUND)
242
243 endif(WIN32)
244
245 add_definitions(-DBUILDING_PCAP)
246
247 if(MSVC)
248 add_definitions(-D__STDC__)
249 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
250 endif(MSVC)
251
252 if(USE_STATIC_RT)
253 message(STATUS "Use STATIC runtime")
254 if(MSVC)
255 foreach(RT_FLAG
256 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
257 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
258 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
259 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
260 string(REGEX REPLACE "/MD" "/MT" ${RT_FLAG} "${${RT_FLAG}}")
261 endforeach(RT_FLAG)
262 elseif(MINGW)
263 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc")
264 endif()
265 else (USE_STATIC_RT)
266 message(STATUS "Use DYNAMIC runtime")
267 endif(USE_STATIC_RT)
268
269 ###################################################################
270 # Detect available platform features
271 ###################################################################
272
273 include(CheckIncludeFile)
274 include(CheckIncludeFiles)
275 include(CheckStructHasMember)
276 include(CheckTypeSize)
277
278 #
279 # Header files.
280 #
281 check_include_file(inttypes.h HAVE_INTTYPES_H)
282 check_include_file(stdint.h HAVE_STDINT_H)
283 check_include_file(unistd.h HAVE_UNISTD_H)
284 if(NOT HAVE_UNISTD_H)
285 add_definitions(-DYY_NO_UNISTD_H)
286 endif(NOT HAVE_UNISTD_H)
287 check_include_file(bitypes.h HAVE_SYS_BITYPES_H)
288 check_include_file(sys/ioccom.h HAVE_SYS_IOCCOM_H)
289 check_include_file(sys/sockio.h HAVE_SYS_SOCKIO_H)
290 check_include_file(sys/select.h HAVE_SYS_SELECT_H)
291 check_include_file(limits.h HAVE_LIMITS_H)
292 check_include_file(netpacket/packet.h HAVE_NETPACKET_PACKET_H)
293 check_include_file(net/pfvar.h HAVE_NET_PFVAR_H)
294 if(HAVE_NET_PFVAR_H)
295 #
296 # Check for various PF actions.
297 #
298 check_c_source_compiles(
299 "#include <sys/types.h>
300 #include <sys/socket.h>
301 #include <net/if.h>
302 #include <net/pfvar.h>
303
304 int
305 main(void)
306 {
307 return PF_NAT+PF_NONAT+PF_BINAT+PF_NOBINAT+PF_RDR+PF_NORDR;
308 }
309 "
310 HAVE_PF_NAT_THROUGH_PF_NORDR)
311 endif()
312 check_include_file(netinet/if_ether.h HAVE_NETINET_IF_ETHER_H)
313 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
314 check_include_file(linux/sockios.h HAVE_LINUX_SOCKIOS_H)
315 #
316 # linux/if_bonding.h requires sys/socket.h.
317 #
318 check_include_files("sys/socket.h;linux/if_bonding.h" HAVE_LINUX_IF_BONDING_H)
319 endif()
320
321 #
322 # Functions.
323 #
324 check_function_exists(strerror HAVE_STRERROR)
325 check_function_exists(strerror_r HAVE_STRERROR_R)
326 check_function_exists(strerror_s HAVE_STRERROR_S)
327 check_function_exists(strlcpy HAVE_STRLCPY)
328 check_function_exists(strlcat HAVE_STRLCAT)
329 check_function_exists(snprintf HAVE_SNPRINTF)
330 check_function_exists(vsnprintf HAVE_VSNPRINTF)
331 check_function_exists(strtok_r HAVE_STRTOK_R)
332
333 #
334 # Find library needed for gethostbyname.
335 # NOTE: if you hand check_library_exists as its last argument a variable
336 # that's been set, it skips the test, so we need different variables.
337 #
338 set(PCAP_LINK_LIBRARIES "")
339 include(CheckLibraryExists)
340 check_function_exists(gethostbyname STDLIBS_HAVE_GETHOSTBYNAME)
341 if(NOT STDLIBS_HAVE_GETHOSTBYNAME)
342 check_library_exists(nsl gethostbyname "" LIBNSL_HAS_GETHOSTBYNAME)
343 if(LIBNSL_HAS_GETHOSTBYNAME)
344 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} nsl)
345 endif()
346 endif()
347
348 #
349 # Data types.
350 #
351 # XXX - there's no check_struct() macro that's like check_struct_has_member()
352 # except that it only checks for the existence of the structure type,
353 # so we use check_struct_has_member() and look for ss_family.
354 #
355 check_struct_has_member("struct sockaddr_storage" ss_family sys/socket.h HAVE_SOCKADDR_STORAGE)
356 set(CMAKE_EXTRA_INCLUDE_FILES unistd.h sys/socket.h)
357 check_type_size("socklen_t" SOCKLEN_T)
358 set(CMAKE_EXTRA_INCLUDE_FILES unistd.h)
359
360 #
361 # Structure fields.
362 #
363 check_struct_has_member("struct sockaddr" sa_len sys/socket.h HAVE_SOCKADDR_SA_LEN)
364
365 #
366 # Do we have ffs(), and is it declared in <strings.h>?
367 #
368 include(CheckSymbolExists)
369 check_function_exists(ether_hostton HAVE_FFS)
370 if(HAVE_FFS)
371 #
372 # OK, we have ffs(). Is it declared in <strings.h>?
373 #
374 # This test fails if we don't have <strings.h> or if we do
375 # but it doesn't declare ffs().
376 #
377 check_symbol_exists(ffs strings.h STRINGS_H_DECLARES_FFS)
378 endif()
379
380 #
381 # You are in a twisty little maze of UN*Xes, all different.
382 # Some might not have ether_hostton().
383 # Some might have it and declare it in <net/ethernet.h>.
384 # Some might have it and declare it in <netinet/ether.h>
385 # Some might have it and declare it in <sys/ethernet.h>.
386 # Some might have it and declare it in <arpa/inet.h>.
387 # Some might have it and declare it in <netinet/if_ether.h>.
388 # Some might have it and not declare it in any header file.
389 #
390 # Before you is a C compiler.
391 #
392 check_function_exists(ether_hostton HAVE_ETHER_HOSTTON)
393 if(HAVE_ETHER_HOSTTON)
394 #
395 # OK, we have ether_hostton(). Is it declared in <net/ethernet.h>?
396 #
397 # This test fails if we don't have <net/ethernet.h> or if we do
398 # but it doesn't declare ether_hostton().
399 #
400 check_symbol_exists(ether_hostton net/ethernet.h NET_ETHERNET_H_DECLARES_ETHER_HOSTTON)
401 if(NET_ETHERNET_H_DECLARES_ETHER_HOSTTON)
402 #
403 # Yes - we have it declared.
404 #
405 set(HAVE_DECL_ETHER_HOSTTON TRUE)
406 endif()
407 #
408 # Did that succeed?
409 #
410 if(NOT HAVE_DECL_ETHER_HOSTTON)
411 #
412 # No - how about <netinet/ether.h>, as on Linux?
413 #
414 # This test fails if we don't have <netinet/ether.h>
415 # or if we do but it doesn't declare ether_hostton().
416 #
417 check_symbol_exists(ether_hostton netinet/ether.h NETINET_ETHER_H_DECLARES_ETHER_HOSTTON)
418 if(NETINET_ETHER_H_DECLARES_ETHER_HOSTTON)
419 #
420 # Yes - we have it declared.
421 #
422 set(HAVE_DECL_ETHER_HOSTTON TRUE)
423 endif()
424 endif()
425 #
426 # Did that succeed?
427 #
428 if(NOT HAVE_DECL_ETHER_HOSTTON)
429 #
430 # No - how about <sys/ethernet.h>, as on Solaris 10 and later?
431 #
432 # This test fails if we don't have <sys/ethernet.h>
433 # or if we do but it doesn't declare ether_hostton().
434 #
435 check_symbol_exists(ether_hostton sys/ethernet.h SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON)
436 if(SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON)
437 #
438 # Yes - we have it declared.
439 #
440 set(HAVE_DECL_ETHER_HOSTTON TRUE)
441 endif()
442 endif()
443 #
444 # Did that succeed?
445 #
446 if(NOT HAVE_DECL_ETHER_HOSTTON)
447 #
448 # No, how about <arpa/inet.h>, as on AIX?
449 #
450 # This test fails if we don't have <arpa/inet.h>
451 # or if we do but it doesn't declare ether_hostton().
452 #
453 check_symbol_exists(ether_hostton arpa/inet.h ARPA_INET_H_DECLARES_ETHER_HOSTTON)
454 if(ARPA_INET_H_DECLARES_ETHER_HOSTTON)
455 #
456 # Yes - we have it declared.
457 #
458 set(HAVE_DECL_ETHER_HOSTTON TRUE)
459 endif()
460 endif()
461 #
462 # Did that succeed?
463 #
464 if(NOT HAVE_DECL_ETHER_HOSTTON)
465 #
466 # No, how about <netinet/if_ether.h>?
467 # On some platforms, it requires <net/if.h> and
468 # <netinet/in.h>, and we always include it with
469 # both of them, so test it with both of them.
470 #
471 # This test fails if we don't have <netinet/if_ether.h>
472 # and the headers we include before it, or if we do but
473 # <netinet/if_ether.h> doesn't declare ether_hostton().
474 #
475 check_symbol_exists(ether_hostton "sys/types.h;sys/socket.h;net/if.h;netinet/in.h;netinet/if_ether.h" NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON)
476 if(NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON)
477 #
478 # Yes - we have it declared.
479 #
480 set(HAVE_DECL_ETHER_HOSTTON TRUE)
481 endif()
482 endif()
483 #
484 # After all that, is ether_hostton() declared?
485 #
486 if(NOT HAVE_DECL_ETHER_HOSTTON)
487 #
488 # No, we'll have to declare it ourselves.
489 # Do we have "struct ether_addr" if we include<netinet/if_ether.h>?
490 #
491 check_struct_has_member("struct ether_addr" octet "sys/types.h;sys/socket.h;net/if.h;netinet/in.h;netinet/if_ether.h" HAVE_STRUCT_ETHER_ADDR)
492 endif()
493 endif()
494
495 #
496 # Large file support on UN*X, a/k/a LFS.
497 #
498 if(NOT WIN32)
499 include(FindLFS)
500 if(LFS_FOUND)
501 #
502 # Add the required #defines.
503 #
504 add_definitions(${LFS_DEFINITIONS})
505 endif()
506
507 #
508 # Check for fseeko as well.
509 #
510 include(FindFseeko)
511 if(FSEEKO_FOUND)
512 set(HAVE_FSEEKO ON)
513
514 #
515 # Add the required #defines.
516 #
517 add_definitions(${FSEEKO_DEFINITIONS})
518 endif()
519 endif()
520
521 if(INET6)
522 message(STATUS "Support IPv6")
523 endif(INET6)
524
525 #
526 # Pthreads.
527 # We might need them, because some libraries we use might use them,
528 # but we don't necessarily need them.
529 # That's only on UN*X; on Windows, if they use threads, we assume
530 # they're native Windows threads.
531 #
532 if(NOT WIN32)
533 set(CMAKE_THREAD_PREFER_PTHREAD ON)
534 find_package(Threads)
535 if(NOT CMAKE_USE_PTHREADS_INIT)
536 #
537 # If it's not pthreads, we won't use it; we use it for libraries
538 # that require it.
539 #
540 set(CMAKE_THREAD_LIBS_INIT "")
541 endif(NOT CMAKE_USE_PTHREADS_INIT)
542 endif(NOT WIN32)
543
544 ######################################
545 # Input files
546 ######################################
547
548 set(PROJECT_SOURCE_LIST_C
549 bpf_dump.c
550 bpf_image.c
551 etherent.c
552 fmtutils.c
553 fopen.c
554 gencode.c
555 nametoaddr.c
556 optimize.c
557 pcap-common.c
558 pcap.c
559 savefile.c
560 sf-pcap-ng.c
561 sf-pcap.c
562 bpf/net/bpf_filter.c
563 )
564
565 if(WIN32)
566 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/win_snprintf.c)
567 else()
568 if(NOT HAVE_SNPRINTF)
569 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/snprintf.c)
570 endif(NOT HAVE_SNPRINTF)
571 if(NOT HAVE_STRTOK_R)
572 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/strtok_r.c)
573 endif(NOT HAVE_STRTOK_R)
574 endif(WIN32)
575
576 #
577 # Determine the main pcap-XXX.c file to use, and the libraries with
578 # which we need to link libpcap, if any.
579 #
580 if(WIN32)
581 #
582 # Windows; we need to link with WinSock2.
583 #
584 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ws2_32)
585
586 #
587 # Has the user explicitly specified a capture type?
588 #
589 if(PCAP_TYPE STREQUAL "")
590 #
591 # The user didn't explicitly specify a capture mechanism.
592 # Check whether we have packet.dll.
593 #
594 if(HAVE_PACKET32)
595 #
596 # We have packet.dll.
597 # Set the capture type to NPF.
598 #
599 set(PCAP_TYPE npf)
600 else()
601 #
602 # We don't have any capture type we know about, so just use
603 # the null capture type, and only support reading (and writing)
604 # capture files.
605 #
606 set(PCAP_TYPE null)
607 endif()
608 endif()
609 else()
610 #
611 # UN*X.
612 #
613 # Figure out what type of packet capture mechanism we have, and
614 # what libraries we'd need to link libpcap with, if any.
615 #
616
617 #
618 # Has the user explicitly specified a capture type?
619 #
620 if(PCAP_TYPE STREQUAL "")
621 #
622 # Check for a bunch of headers for various packet capture mechanisms.
623 #
624 check_include_files("sys/types.h;net/bpf.h" HAVE_NET_BPF_H)
625 if(HAVE_NET_BPF_H)
626 #
627 # Does it define BIOCSETIF?
628 # I.e., is it a header for an LBL/BSD-style capture
629 # mechanism, or is it just a header for a BPF filter
630 # engine? Some versions of Arch Linux, for example,
631 # have a net/bpf.h that doesn't define BIOCSETIF;
632 # as it's a Linux, it should use packet sockets,
633 # instead.
634 #
635 #
636 # We need:
637 #
638 # sys/types.h, because FreeBSD 10's net/bpf.h
639 # requires that various BSD-style integer types
640 # be defined;
641 #
642 # sys/ioctl.h and, if we have it, sys/ioccom.h,
643 # because net/bpf.h defines ioctls;
644 #
645 # net/if.h, because it defines some structures
646 # used in ioctls defined by net/bpf.h;
647 #
648 # sys/socket.h, because OpenBSD 5.9's net/bpf.h
649 # defines some structure fields as being
650 # struct sockaddrs;
651 #
652 # and net/bpf.h doesn't necessarily include all
653 # of those headers itself.
654 #
655 if(HAVE_SYS_IOCCOM_H)
656 check_symbol_exists(BIOCSETIF "sys/types.h;sys/ioctl.h;sys/socket.h;sys/ioccom.h;net/bpf.h;net/if.h" BPF_H_DEFINES_BIOCSETIF)
657 else(HAVE_SYS_IOCCOM_H)
658 check_symbol_exists(BIOCSETIF "sys/types.h;sys/ioctl.h;sys/socket.h;net/bpf.h;net/if.h" BPF_H_DEFINES_BIOCSETIF)
659 endif(HAVE_SYS_IOCCOM_H)
660 endif(HAVE_NET_BPF_H)
661 check_include_file(net/pfilt.h HAVE_NET_PFILT_H)
662 check_include_file(net/enet.h HAVE_NET_ENET_H)
663 check_include_file(net/nit.h HAVE_NET_NIT_H)
664 check_include_file(sys/net/nit.h HAVE_SYS_NET_NIT_H)
665 check_include_file(linux/socket.h HAVE_LINUX_SOCKET_H)
666 check_include_file(net/raw.h HAVE_NET_RAW_H)
667 check_include_file(sys/dlpi.h HAVE_SYS_DLPI_H)
668
669 if(BPF_H_DEFINES_BIOCSETIF)
670 #
671 # BPF.
672 # Check this before DLPI, so that we pick BPF on
673 # Solaris 11 and later.
674 #
675 set(PCAP_TYPE bpf)
676 elseif(HAVE_LINUX_SOCKET_H)
677 #
678 # No prizes for guessing this one.
679 #
680 set(PCAP_TYPE linux)
681 elseif(HAVE_NET_PFILT_H)
682 #
683 # DEC OSF/1, Digital UNIX, Tru64 UNIX
684 #
685 set(PCAP_TYPE pf)
686 elseif(HAVE_NET_ENET_H)
687 #
688 # Stanford Enetfilter.
689 #
690 set(PCAP_TYPE enet)
691 elseif(HAVE_NET_NIT_H)
692 #
693 # SunOS 4.x STREAMS NIT.
694 #
695 set(PCAP_TYPE snit)
696 elseif(HAVE_SYS_NET_NIT_H)
697 #
698 # Pre-SunOS 4.x non-STREAMS NIT.
699 #
700 set(PCAP_TYPE nit)
701 elseif(HAVE_NET_RAW_H)
702 #
703 # IRIX snoop.
704 #
705 set(PCAP_TYPE snoop)
706 elseif(HAVE_SYS_DLPI_H)
707 #
708 # DLPI on pre-Solaris 11 SunOS 5, HP-UX, possibly others.
709 #
710 set(PCAP_TYPE dlpi)
711 else()
712 #
713 # Nothing we support.
714 #
715 set(PCAP_TYPE null)
716 endif()
717 endif()
718 endif(WIN32)
719 message(STATUS "Packet capture mechanism type: ${PCAP_TYPE}")
720
721 #
722 # Do capture-mechanism-dependent tests.
723 #
724 if(WIN32)
725 if(PCAP_TYPE STREQUAL "npf")
726 #
727 # Link with packet.dll before WinSock2.
728 #
729 set(PCAP_LINK_LIBRARIES ${PACKET_LIBRARY} ${PCAP_LINK_LIBRARIES})
730 elseif(PCAP_TYPE STREQUAL "null")
731 else()
732 message(ERROR "${PCAP_TYPE} is not a valid pcap type")
733 endif()
734 else(WIN32)
735 if(PCAP_TYPE STREQUAL "dlpi")
736 #
737 # Needed for common functions used by pcap-[dlpi,libdlpi].c
738 #
739 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} dlpisubs.c)
740
741 #
742 # Checks for some header files.
743 #
744 check_include_file(sys/bufmod.h HAVE_SYS_BUFMOD_H)
745 check_include_file(sys/dlpi_ext.h HAVE_SYS_DLPI_EXT_H)
746
747 #
748 # Checks to see if Solaris has the public libdlpi(3LIB) library.
749 # Note: The existence of /usr/include/libdlpi.h does not mean it is the
750 # public libdlpi(3LIB) version. Before libdlpi was made public, a
751 # private version also existed, which did not have the same APIs.
752 # Due to a gcc bug, the default search path for 32-bit libraries does
753 # not include /lib, we add it explicitly here.
754 # [http://bugs.opensolaris.org/view_bug.do?bug_id=6619485].
755 # Also, due to the bug above applications that link to libpcap with
756 # libdlpi will have to add "-L/lib" option to "configure".
757 #
758 cmake_push_check_state()
759 set(CMAKE_REQUIRED_FLAGS "-L/lib")
760 set(CMAKE_REQUIRED_LIBRARIES dlpi)
761 check_function_exists(dlpi_walk HAVE_LIBDLPI)
762 cmake_pop_check_state()
763 if(HAVE_LIBDLPI)
764 #
765 # XXX - add -L/lib
766 #
767 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} dlpi)
768 set(PCAP_TYPE libdlpi)
769 endif()
770
771 #
772 # This check is for Solaris with DLPI support for passive modes.
773 # See dlpi(7P) for more details.
774 #
775 # XXX - there's no check_struct() macro that's like
776 # check_struct_has_member() except that it only checks for the
777 # existence of the structure type, so we use
778 # check_struct_has_member() and look for dl_primitive.
779 #
780 check_struct_has_member("dl_passive_req_t" dl_primitive "sys/types.h;sys/dlpi.h" HAVE_DLPI_PASSIVE)
781 elseif(PCAP_TYPE STREQUAL "linux")
782 #
783 # Do we have the wireless extensions?
784 # linux/wireless.h requires sys/socket.h.
785 #
786 check_include_files("sys/socket.h;linux/wireless.h" HAVE_LINUX_WIRELESS_H)
787
788 #
789 # Do we have libnl?
790 #
791 if(BUILD_WITH_LIBNL)
792 #
793 # Try libnl 3.x first.
794 #
795 cmake_push_check_state()
796 set(CMAKE_REQUIRED_LIBRARIES nl-3)
797 check_function_exists(nl_socket_alloc HAVE_LIBNL)
798 cmake_pop_check_state()
799 if(HAVE_LIBNL)
800 #
801 # Yes, we have libnl 3.x.
802 #
803 set(PCAP_LINK_LIBRARIES nl-genl-3 nl-3 ${PCAP_LINK_LIBRARIES})
804 set(HAVE_LIBNL_3_x ON)
805 set(HAVE_LIBNL_NLE ON)
806 set(HAVE_LIBNL_SOCKETS ON)
807 include_directories("/usr/include/libnl3")
808 else()
809 #
810 # Try libnl 2.x.
811 #
812 cmake_push_check_state()
813 set(CMAKE_REQUIRED_LIBRARIES nl)
814 check_function_exists(nl_socket_alloc HAVE_LIBNL)
815 cmake_pop_check_state()
816 if(HAVE_LIBNL)
817 #
818 # Yes, we have libnl 2.x.
819 #
820 set(PCAP_LINK_LIBRARIES nl-genl nl ${PCAP_LINK_LIBRARIES})
821 set(HAVE_LIBNL_2_x ON)
822 set(HAVE_LIBNL_NLE ON)
823 set(HAVE_LIBNL_SOCKETS ON)
824 else()
825 #
826 # No, we don't; do we have libnl 1.x?
827 #
828 cmake_push_check_state()
829 set(CMAKE_REQUIRED_LIBRARIES nl)
830 check_function_exists(nl_handle_alloc HAVE_LIBNL)
831 cmake_pop_check_state()
832 if(HAVE_LIBNL)
833 set(PCAP_LINK_LIBRARIES nl ${PCAP_LINK_LIBRARIES})
834 endif()
835 endif()
836 endif()
837 endif()
838
839 check_include_file(linux/ethtool.h HAVE_LINUX_ETHTOOL_H)
840
841 #
842 # Checks to see if tpacket_stats is defined in linux/if_packet.h
843 # If so then pcap-linux.c can use this to report proper statistics.
844 #
845 check_struct_has_member("struct tpacket_stats" tp_packets linux/if_packet.h HAVE_TPACKET_STATS)
846
847 check_struct_has_member("struct tpacket_auxdata" tp_vlan_tci linux/if_packet.h HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI)
848 if(HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI)
849 set(HAVE_LINUX_TPACKET_AUXDATA tp_vlan_tci)
850 endif()
851 elseif(PCAP_TYPE STREQUAL "bpf")
852 #
853 # Check whether we have the *BSD-style ioctls.
854 #
855 check_include_files("sys/types.h;net/if_media.h" HAVE_NET_IF_MEDIA_H)
856
857 #
858 # Check whether we have struct BPF_TIMEVAL.
859 #
860 if(HAVE_SYS_IOCCOM_H)
861 check_struct_has_member("struct BPF_TIMEVAL" tv_sec "sys/types.h;sys/ioccom.h;net/bpf.h" HAVE_STRUCT_BPF_TIMEVAL)
862 else()
863 check_struct_has_member("struct BPF_TIMEVAL" tv_sec "sys/types.h;net/bpf.h" HAVE_STRUCT_BPF_TIMEVAL)
864 endif()
865 elseif(PCAP_TYPE STREQUAL "null")
866 else()
867 message(FATAL_ERROR "${PCAP_TYPE} is not a valid pcap type")
868 endif()
869 endif(WIN32)
870
871 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-${PCAP_TYPE}.c)
872
873 #
874 # Now figure out how we get a list of interfaces and addresses,
875 # if we support capturing. Don't bother if we don't support
876 # capturing.
877 #
878 if(NOT WIN32)
879 #
880 # UN*X - figure out what type of interface list mechanism we
881 # have.
882 #
883 # If the capture type is null, that means we can't capture,
884 # so we can't open any capture devices, so we won't return
885 # any interfaces.
886 #
887 if(NOT PCAP_TYPE STREQUAL "null")
888 check_function_exists(getifaddrs HAVE_GETIFADDRS)
889 if(NOT HAVE_GETIFADDRS)
890 #
891 # It's in libsocket on Solaris and possibly other OSes;
892 # check there.
893 #
894 # NOTE: if you hand check_library_exists as its last
895 # argument a variable that's been set, it skips the test,
896 # so we need different variables.
897 #
898 check_library_exists(socket getifaddrs "" SOCKET_HAS_GETIFADDRS)
899 if(SOCKET_HAS_GETIFADDRS)
900 set(PCAP_LINK_LIBRARIES socket ${PCAP_LINK_LIBRARIES})
901 set(HAVE_GETIFADDRS TRUE)
902 endif()
903 endif()
904 if(HAVE_GETIFADDRS)
905 #
906 # We have "getifaddrs()"; make sure we have <ifaddrs.h>
907 # as well, just in case some platform is really weird.
908 # It may require that sys/types.h be included first,
909 # so include it first.
910 #
911 check_include_files("sys/types.h;ifaddrs.h" HAVE_IFADDRS_H)
912 if(HAVE_IFADDRS_H)
913 #
914 # We have the header, so we use "getifaddrs()" to
915 # get the list of interfaces.
916 #
917 set(FINDALLDEVS_TYPE getad)
918 else()
919 #
920 # We don't have the header - give up.
921 # XXX - we could also fall back on some other
922 # mechanism, but, for now, this'll catch this
923 # problem so that we can at least try to figure
924 # out something to do on systems with "getifaddrs()"
925 # but without "ifaddrs.h", if there is something
926 # we can do on those systems.
927 #
928 message(FATAL_ERROR "Your system has getifaddrs() but doesn't have a usable <ifaddrs.h>.")
929 endif()
930 else()
931 #
932 # Well, we don't have "getifaddrs()", so we have to use
933 # some other mechanism; determine what that mechanism is.
934 #
935 # The first thing we use is the type of capture mechanism,
936 # which is somewhat of a proxy for the OS we're using.
937 #
938 if(PCAP_TYPE STREQUAL "dlpi" OR PCAP_TYPE STREQUAL "libdlpi")
939 #
940 # This might be Solaris 8 or later, with
941 # SIOCGLIFCONF, or it might be some other OS
942 # or some older version of Solaris, with
943 # just SIOCGIFCONF.
944 #
945 try_compile(HAVE_SIOCGLIFCONF ${CMAKE_CURRENT_BINARY_DIR} "${pcap_SOURCE_DIR}/cmake/have_siocglifconf.c" )
946 if(HAVE_SIOCGLIFCONF)
947 set(FINDALLDEVS_TYPE glifc)
948 else()
949 set(FINDALLDEVS_TYPE gifc)
950 endif()
951 else()
952 #
953 # Assume we just have SIOCGIFCONF.
954 # (XXX - on at least later Linux kernels, there's
955 # another mechanism, and we should be using that
956 # instead.)
957 #
958 set(FINDALLDEVS_TYPE gifc)
959 endif()
960 endif()
961 message(STATUS "Find-interfaces mechanism type: ${FINDALLDEVS_TYPE}")
962 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} fad-${FINDALLDEVS_TYPE}.c)
963 endif()
964 endif()
965
966 # Check for hardware timestamp support.
967 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
968 check_include_file(linux/net_tstamp.h HAVE_LINUX_NET_TSTAMP_H)
969 endif()
970
971 #
972 # Check for additional native sniffing capabilities.
973 #
974
975 # Check for USB sniffing support on Linux.
976 # On FreeBSD, it uses BPF, so we don't need to do anything special here.
977 if(NOT DISABLE_USB)
978 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
979 set(PCAP_SUPPORT_USB TRUE)
980 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-usb-linux.c)
981 set(LINUX_USB_MON_DEV /dev/usbmon)
982 #
983 # Do we have a version of <linux/compiler.h> available?
984 # If so, we might need it for <linux/usbdevice_fs.h>.
985 #
986 check_include_files("linux/compiler.h" HAVE_LINUX_COMPILER_H)
987 if(HAVE_LINUX_COMPILER_H)
988 #
989 # Yes - include it when testing for <linux/usbdevice_fs.h>.
990 #
991 check_include_files("linux/compiler.h;linux/usbdevice_fs.h" HAVE_LINUX_USBDEVICE_FS_H)
992 else(HAVE_LINUX_COMPILER_H)
993 check_include_files("linux/usbdevice_fs.h" HAVE_LINUX_USBDEVICE_FS_H)
994 endif(HAVE_LINUX_COMPILER_H)
995 if(HAVE_LINUX_USBDEVICE_FS_H)
996 #
997 # OK, does it define bRequestType? Older versions of the kernel
998 # define fields with names like "requesttype, "request", and
999 # "value", rather than "bRequestType", "bRequest", and
1000 # "wValue".
1001 #
1002 if(HAVE_LINUX_COMPILER_H)
1003 check_struct_has_member("struct usbdevfs_ctrltransfer" bRequestType "linux/compiler.h;linux/usbdevice_fs.h" HAVE_USBDEVFS_CTRLTRANSFER_BREQUESTTYPE)
1004 else(HAVE_LINUX_COMPILER_H)
1005 check_struct_has_member("struct usbdevfs_ctrltransfer" bRequestType "linux/usbdevice_fs.h" HAVE_USBDEVFS_CTRLTRANSFER_BREQUESTTYPE)
1006 endif(HAVE_LINUX_COMPILER_H)
1007 endif()
1008 endif()
1009 endif()
1010
1011 # Check for netfilter sniffing support.
1012 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
1013 #
1014 # Life's too short to deal with trying to get this to compile
1015 # if you don't get the right types defined with
1016 # __KERNEL_STRICT_NAMES getting defined by some other include.
1017 #
1018 # Check whether the includes Just Work. If not, don't turn on
1019 # netfilter support.
1020 #
1021 check_c_source_compiles(
1022 "#include <sys/socket.h>
1023 #include <netinet/in.h>
1024 #include <linux/types.h>
1025
1026 #include <linux/netlink.h>
1027 #include <linux/netfilter.h>
1028 #include <linux/netfilter/nfnetlink.h>
1029 #include <linux/netfilter/nfnetlink_log.h>
1030 #include <linux/netfilter/nfnetlink_queue.h>
1031
1032 int
1033 main(void)
1034 {
1035 return 0;
1036 }
1037 "
1038 PCAP_SUPPORT_NETFILTER)
1039 if(PCAP_SUPPORT_NETFILTER)
1040 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-netfilter-linux.c)
1041 endif(PCAP_SUPPORT_NETFILTER)
1042 endif()
1043
1044 # Check for netmap sniffing support.
1045 if(NOT DISABLE_NETMAP)
1046 #
1047 # Check whether net/netmap_user.h is usable if NETMAP_WITH_LIBS is
1048 # defined; it's not usable on DragonFly BSD 4.6 if NETMAP_WITH_LIBS
1049 # is defined, for example, as it includes a non-existent malloc.h
1050 # header.
1051 #
1052 check_c_source_compiles(
1053 "#define NETMAP_WITH_LIBS
1054 #include <net/netmap_user.h>
1055 "
1056 PCAP_SUPPORT_NETMAP)
1057 if(PCAP_SUPPORT_NETMAP)
1058 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-netmap.c)
1059 endif(PCAP_SUPPORT_NETMAP)
1060 endif()
1061
1062 # Check for Bluetooth sniffing support
1063 if(NOT DISABLE_BLUETOOTH)
1064 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
1065 check_include_file(bluetooth/bluetooth.h HAVE_BLUETOOTH_BLUETOOTH_H)
1066 if(HAVE_BLUETOOTH_BLUETOOTH_H)
1067 set(PCAP_SUPPORT_BT TRUE)
1068 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-bt-linux.c)
1069 #
1070 # OK, does struct sockaddr_hci have an hci_channel
1071 # member?
1072 #
1073 check_struct_has_member("struct sockaddr_hci" hci_channel "bluetooth/bluetooth.h;bluetooth/hci.h" SOCKADDR_HCI_HAS_HCI_CHANNEL)
1074 if(SOCKADDR_HCI_HAS_HCI_CHANNEL)
1075 #
1076 # OK, is HCI_CHANNEL_MONITOR defined?
1077 #
1078 check_c_source_compiles(
1079 "#include <bluetooth/bluetooth.h>
1080 #include <bluetooth/hci.h>
1081
1082 int
1083 main(void)
1084 {
1085 u_int i = HCI_CHANNEL_MONITOR;
1086 return 0;
1087 }
1088 "
1089 PCAP_SUPPORT_BT_MONITOR)
1090 if(PCAP_SUPPORT_BT_MONITOR)
1091 #
1092 # Yes, so we can also support Bluetooth monitor
1093 # sniffing.
1094 #
1095 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-bt-monitor-linux.c)
1096 endif(PCAP_SUPPORT_BT_MONITOR)
1097 endif(SOCKADDR_HCI_HAS_HCI_CHANNEL)
1098 endif(HAVE_BLUETOOTH_BLUETOOTH_H)
1099 endif()
1100 endif()
1101
1102 # Check for Bluetooth sniffing support
1103 if(NOT DISABLE_DBUS)
1104 #
1105 # We don't support D-Bus sniffing on macOS; see
1106 #
1107 # https://bugs.freedesktop.org/show_bug.cgi?id=74029
1108 #
1109 if(APPLE)
1110 message(FATAL_ERROR "Due to freedesktop.org bug 74029, D-Bus capture support is not available on macOS")
1111 endif(APPLE)
1112 include(FindPkgConfig)
1113 pkg_check_modules(DBUS dbus-1)
1114 if(DBUS_FOUND)
1115 set(PCAP_SUPPORT_DBUS TRUE)
1116 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-dbus.c)
1117 include_directories(${DBUS_INCLUDE_DIRS})
1118 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${DBUS_LIBRARIES})
1119 endif(DBUS_FOUND)
1120 endif(NOT DISABLE_DBUS)
1121
1122 # Check for RDMA sniffing support
1123 if(NOT DISABLE_RDMA)
1124 check_library_exists(ibverbs ibv_get_device_list "" LIBIBVERBS_HAS_IBV_GET_DEVICE_LIST)
1125 if(LIBIBVERBS_HAS_IBV_GET_DEVICE_LIST)
1126 check_include_file(infiniband/verbs.h HAVE_INFINIBAND_VERBS_H)
1127 if(HAVE_INFINIBAND_VERBS_H)
1128 check_symbol_exists(ibv_create_flow infiniband/verbs.h PCAP_SUPPORT_RDMASNIFF)
1129 if(PCAP_SUPPORT_RDMASNIFF)
1130 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-rdmasniff.c)
1131 set(PCAP_LINK_LIBRARIES ibverbs ${PCAP_LINK_LIBRARIES})
1132 endif(PCAP_SUPPORT_RDMASNIFF)
1133 endif(HAVE_INFINIBAND_VERBS_H)
1134 endif(LIBIBVERBS_HAS_IBV_GET_DEVICE_LIST)
1135 endif(NOT DISABLE_RDMA)
1136
1137 #
1138 # Check for sniffing capabilities using third-party APIs.
1139 #
1140
1141 # Check for Endace DAG card support.
1142 if(NOT DISABLE_DAG)
1143 #
1144 # Try to find the DAG header file and library.
1145 #
1146 find_package(DAG)
1147
1148 #
1149 # Did we succeed?
1150 #
1151 if(DAG_FOUND)
1152 #
1153 # Yes.
1154 # Check for various DAG API functions.
1155 #
1156 cmake_push_check_state()
1157 set(CMAKE_REQUIRED_INCLUDES ${DAG_INCLUDE_DIR})
1158 set(CMAKE_REQUIRED_LIBRARIES ${DAG_LIBRARY})
1159 check_function_exists(dag_attach_stream HAVE_DAG_STREAMS_API)
1160 if(NOT HAVE_DAG_STREAMS_API)
1161 message(FATAL_ERROR "DAG library lacks streams support")
1162 endif()
1163 check_function_exists(dag_attach_stream64 HAVE_DAG_LARGE_STREAMS_API)
1164 check_function_exists(dag_get_erf_types HAVE_DAG_GET_ERF_TYPES)
1165 check_function_exists(dag_get_stream_erf_types HAVE_DAG_GET_STREAM_ERF_TYPES)
1166 cmake_pop_check_state()
1167
1168 include_directories(AFTER ${DAG_INCLUDE_DIR})
1169 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-dag.c)
1170 set(HAVE_DAG_API TRUE)
1171 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${DAG_LIBRARY})
1172
1173 if(HAVE_DAG_LARGE_STREAMS_API)
1174 get_filename_component(DAG_LIBRARY_DIR ${DAG_LIBRARY} PATH)
1175 check_library_exists(vdag vdag_set_device_info ${DAG_LIBRARY_DIR} HAVE_DAG_VDAG)
1176 if(HAVE_DAG_VDAG)
1177 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
1178 endif()
1179 endif()
1180 endif()
1181 endif()
1182
1183 # Check for Septel card support.
1184 set(PROJECT_EXTERNAL_OBJECT_LIST "")
1185 if(NOT DISABLE_SEPTEL)
1186 #
1187 # Do we have the msg.h header?
1188 #
1189 set(SEPTEL_INCLUDE_DIR "${SEPTEL_ROOT}/INC")
1190 cmake_push_check_state()
1191 set(CMAKE_REQUIRED_INCLUDES ${SEPTEL_INCLUDE_DIR})
1192 check_include_file(msg.h HAVE_INC_MSG_H)
1193 cmake_pop_check_state()
1194 if(HAVE_INC_MSG_H)
1195 #
1196 # Yes.
1197 #
1198 include_directories(AFTER ${SEPTEL_INCLUDE_DIR})
1199 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-septel.c)
1200 set(PROJECT_EXTERNAL_OBJECT_LIST ${PROJECT_EXTERNAL_OBJECT_LIST} "${SEPTEL_ROOT}/asciibin.o ${SEPTEL_ROOT}/bit2byte.o ${SEPTEL_ROOT}/confirm.o ${SEPTEL_ROOT}/fmtmsg.o ${SEPTEL_ROOT}/gct_unix.o ${SEPTEL_ROOT}/hqueue.o ${SEPTEL_ROOT}/ident.o ${SEPTEL_ROOT}/mem.o ${SEPTEL_ROOT}/pack.o ${SEPTEL_ROOT}/parse.o ${SEPTEL_ROOT}/pool.o ${SEPTEL_ROOT}/sdlsig.o ${SEPTEL_ROOT}/strtonum.o ${SEPTEL_ROOT}/timer.o ${SEPTEL_ROOT}/trace.o")
1201 set(HAVE_SEPTEL_API TRUE)
1202 endif()
1203 endif()
1204
1205 # Check for Myricom SNF support.
1206 if(NOT DISABLE_SNF)
1207 #
1208 # Try to find the SNF header file and library.
1209 #
1210 find_package(SNF)
1211
1212 #
1213 # Did we succeed?
1214 #
1215 if(SNF_FOUND)
1216 #
1217 # Yes.
1218 #
1219 include_directories(AFTER ${SNF_INCLUDE_DIR})
1220 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-snf.c)
1221 set(HAVE_SNF_API TRUE)
1222 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${SNF_LIBRARY})
1223 endif()
1224 endif()
1225
1226 # Check for Riverbed TurboCap support.
1227 if(NOT DISABLE_TC)
1228 #
1229 # Try to find the TurboCap header file and library.
1230 #
1231 find_package(TC)
1232
1233 #
1234 # Did we succeed?
1235 #
1236 if(TC_FOUND)
1237 #
1238 # Yes.
1239 #
1240 include_directories(AFTER ${TC_INCLUDE_DIR})
1241 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-tc.c)
1242 set(HAVE_TC_API TRUE)
1243 set(PCAP_LINK_LIBRARIES "${PCAP_LINK_LIBRARIES} ${TC_LIBRARY} ${CMAKE_USE_PTHREADS_INIT} stdc++")
1244 endif()
1245 endif()
1246
1247 #
1248 # Remote capture support.
1249 #
1250
1251 if(ENABLE_REMOTE)
1252 #
1253 # Check for various members of struct msghdr.
1254 #
1255 check_struct_has_member("struct msghdr" msg_control "sys/socket.h" STRUCT_MSGHDR_HAS_MSG_CONTROL)
1256 check_struct_has_member("struct msghdr" msg_flags "sys/socket.h" STRUCT_MSGHDR_HAS_MSG_FLAGS)
1257 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C}
1258 pcap-new.c pcap-rpcap.c rpcap-protocol.c sockutils.c)
1259 endif(ENABLE_REMOTE)
1260
1261 file(GLOB PROJECT_SOURCE_LIST_H
1262 *.h
1263 pcap/*.h
1264 )
1265
1266 #
1267 # Check and add warning options if we have a .devel file.
1268 #
1269 include(CheckCCompilerFlag)
1270 macro(check_and_add_compiler_option _option)
1271 message(STATUS "Checking C compiler flag ${_option}")
1272 string(REPLACE "=" "-" _temp_option_variable ${_option})
1273 string(REGEX REPLACE "^-" "" _option_variable ${_temp_option_variable})
1274 check_c_compiler_flag("${_option}" ${_option_variable})
1275 if(${${_option_variable}})
1276 set(C_ADDITIONAL_FLAGS ${C_ADDITIONAL_FLAGS} "${_option}")
1277 endif()
1278 endmacro()
1279
1280 set(C_ADDITIONAL_FLAGS "")
1281 if(EXISTS ${CMAKE_SOURCE_DIR}/.devel)
1282 #
1283 # -W options, used by GCC and compilers that try to behave like it.
1284 #
1285 check_and_add_compiler_option(-Wall)
1286 check_and_add_compiler_option(-Wsign-compare)
1287 check_and_add_compiler_option(-Wmissing-prototypes)
1288 check_and_add_compiler_option(-Wstrict-prototypes)
1289 check_and_add_compiler_option(-Wshadow)
1290 check_and_add_compiler_option(-Wdeclaration-after-statement)
1291 check_and_add_compiler_option(-Wused-but-marked-unused)
1292 endif()
1293
1294 #
1295 # Add subdirectories after we've set C_ADDITIONAL_FLAGS, so they
1296 # pick up those flags.
1297 #
1298 if(ENABLE_REMOTE)
1299 add_subdirectory(rpcapd)
1300 endif(ENABLE_REMOTE)
1301
1302 #
1303 # Try to have the compiler default to hiding symbols, so that only
1304 # symbols explicitly exported with PCAP_API will be visible outside
1305 # (shared) libraries.
1306 #
1307 # Not necessary with MSVC, as that's the default.
1308 #
1309 if(NOT MSVC)
1310 if(CMAKE_C_COMPILER_ID MATCHES "SunPro")
1311 #
1312 # Sun C/Oracle Studio.
1313 #
1314 check_and_add_compiler_option(-xldscope=hidden)
1315 else()
1316 #
1317 # Try this for all other compilers; it's what GCC uses,
1318 # and a number of other compilers, such as Clang and Intel C,
1319 # use it as well.
1320 #
1321 check_and_add_compiler_option(-fvisibility=hidden)
1322 endif()
1323 endif(NOT MSVC)
1324
1325 #
1326 # {Flex} and YACC/Berkeley YACC/Bison.
1327 # From a mail message to the CMake mailing list by Andy Cedilnik of
1328 # Kitware.
1329 #
1330
1331 #
1332 # Try to find Flex, a Windows version of Flex, or Lex.
1333 #
1334 find_program(LEX_EXECUTABLE NAMES flex win_flex lex)
1335 if(LEX_EXECUTABLE STREQUAL "LEX_EXECUTABLE-NOTFOUND")
1336 message(FATAL_ERROR "Neither flex nor win_flex nor lex was found.")
1337 endif()
1338 message(STATUS "Lexical analyzer generator: ${LEX_EXECUTABLE}")
1339
1340 add_custom_command(
1341 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/scanner.c ${CMAKE_CURRENT_BINARY_DIR}/scanner.h
1342 SOURCE ${pcap_SOURCE_DIR}/scanner.l
1343 COMMAND ${LEX_EXECUTABLE} -P pcap_ --header-file=scanner.h --nounput -o${CMAKE_CURRENT_BINARY_DIR}/scanner.c ${pcap_SOURCE_DIR}/scanner.l
1344 DEPENDS ${pcap_SOURCE_DIR}/scanner.l
1345 )
1346
1347 #
1348 # Since scanner.c does not exist yet when cmake is run, mark
1349 # it as generated.
1350 #
1351 # Since scanner.c includes grammar.h, mark that as a dependency.
1352 #
1353 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/scanner.c PROPERTIES
1354 GENERATED TRUE
1355 OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/scanner.h
1356 )
1357
1358 #
1359 # Add scanner.c to the list of sources.
1360 #
1361 #set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${CMAKE_CURRENT_BINARY_DIR}/scanner.c)
1362
1363 #
1364 # Try to find YACC or Bison.
1365 #
1366 find_program(YACC_EXECUTABLE NAMES bison win_bison byacc yacc)
1367 if(YACC_EXECUTABLE STREQUAL "YACC_EXECUTABLE-NOTFOUND")
1368 message(FATAL_ERROR "Neither bison nor win_bison nor byacc nor yacc was found.")
1369 endif()
1370 message(STATUS "Parser generator: ${YACC_EXECUTABLE}")
1371
1372 #
1373 # Create custom command for the scanner.
1374 # Find out whether it's Bison or notby looking at the last component
1375 # of the path (without a .exe extension, if this is Windows).
1376 #
1377 get_filename_component(YACC_NAME ${YACC_EXECUTABLE} NAME_WE)
1378 if("${YACC_NAME}" STREQUAL "bison" OR "${YACC_NAME}" STREQUAL "win_bison")
1379 set(YACC_COMPATIBILITY_FLAG "-y")
1380 endif()
1381 add_custom_command(
1382 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/grammar.c ${CMAKE_CURRENT_BINARY_DIR}/grammar.h
1383 SOURCE ${pcap_SOURCE_DIR}/grammar.y
1384 COMMAND ${YACC_EXECUTABLE} ${YACC_COMPATIBILITY_FLAG} -p pcap_ -o ${CMAKE_CURRENT_BINARY_DIR}/grammar.c -d ${pcap_SOURCE_DIR}/grammar.y
1385 DEPENDS ${pcap_SOURCE_DIR}/grammar.y
1386 )
1387
1388 #
1389 # Since grammar.c does not exists yet when cmake is run, mark
1390 # it as generated.
1391 #
1392 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/grammar.c PROPERTIES
1393 GENERATED TRUE
1394 )
1395
1396 #
1397 # Add grammar.c to the list of sources.
1398 #
1399 #set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${CMAKE_CURRENT_BINARY_DIR}/grammar.c)
1400
1401 #
1402 # Assume, by default, V7/BSD convention for man pages (file formats in
1403 # section 5, miscellaneous info in section 7).
1404 # Individual cases can override this.
1405 #
1406 set(MAN_FILE_FORMATS 5)
1407 set(MAN_MISC_INFO 7)
1408 set(MAN_USERMOD_SECTION 8)
1409 if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
1410 # Workaround to enable certain features
1411 set(_SUN TRUE)
1412 if(PCAP_TYPE STREQUAL "bpf")
1413 #
1414 # If we're using BPF, we need libodm and libcfg, as
1415 # we use them to load the BPF module.
1416 #
1417 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} odm cfg)
1418 endif()
1419 elseif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
1420 if(CMAKE_SYSTEM_VERSION MATCHES "[A-Z.]*9\.[0-9]*")
1421 #
1422 # HP-UX 9.x.
1423 #
1424 set(HAVE_HPUX9 TRUE)
1425 elseif(CMAKE_SYSTEM_VERSION MATCHES "[A-Z.]*10\.0")
1426 #
1427 # HP-UX 10.0.
1428 #
1429 elseif(CMAKE_SYSTEM_VERSION MATCHES "[A-Z.]*10\.1")
1430 #
1431 # HP-UX 10.1.
1432 #
1433 else()
1434 #
1435 # HP-UX 10.20 and later.
1436 #
1437 set(HAVE_HPUX10_20_OR_LATER TRUE)
1438 endif()
1439
1440 #
1441 # Use System V conventions for man pages.
1442 #
1443 set(MAN_FILE_FORMATS 4)
1444 set(MAN_MISC_INFO 5)
1445 elseif(CMAKE_SYSTEM_NAME STREQUAL "IRIX" OR CMAKE_SYSTEM_NAME STREQUAL "IRIX64")
1446 #
1447 # Use System V conventions for man pages.
1448 #
1449 set(MAN_FILE_FORMATS 4)
1450 set(MAN_MISC_INFO 5)
1451 elseif(CMAKE_SYSTEM_NAME STREQUAL "OSF1")
1452 #
1453 # DEC OSF/1, a/k/a Digial UNIX, a/k/a Tru64 UNIX.
1454 # Use System V conventions for man pages.
1455 #
1456 set(MAN_FILE_FORMATS 4)
1457 set(MAN_MISC_INFO 5)
1458 elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_VERSION MATCHES "5[.][0-9.]*")
1459 #
1460 # SunOS 5.x.
1461 #
1462 set(HAVE_SOLARIS TRUE)
1463 #
1464 # Make sure errno is thread-safe, in case we're called in
1465 # a multithreaded program. We don't guarantee that two
1466 # threads can use the *same* pcap_t safely, but the
1467 # current version does guarantee that you can use different
1468 # pcap_t's in different threads, and even that pcap_compile()
1469 # is thread-safe (it wasn't thread-safe in some older versions).
1470 #
1471 add_definitions(-D_TS_ERRNO)
1472
1473 if(CMAKE_SYSTEM_VERSION STREQUAL "5.12")
1474 else()
1475 #
1476 # Use System V conventions for man pages.
1477 #
1478 set(MAN_USERMOD_SECTION 1m)
1479 set(MAN_FILE_FORMATS 4)
1480 set(MAN_MISC_INFO 5)
1481 endif()
1482 endif()
1483
1484 source_group("Source Files" FILES ${PROJECT_SOURCE_LIST_C})
1485 source_group("Header Files" FILES ${PROJECT_SOURCE_LIST_H})
1486
1487 if(WIN32)
1488 #
1489 # Add pcap-dll.rc to the list of sources.
1490 #
1491 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${pcap_SOURCE_DIR}/pcap-dll.rc)
1492 endif(WIN32)
1493
1494 add_subdirectory(tests)
1495
1496 ######################################
1497 # Register targets
1498 ######################################
1499
1500 #
1501 # Special target to serialize the building of the generated source.
1502 #
1503 # See
1504 #
1505 # http://public.kitware.com/pipermail/cmake/2013-August/055510.html
1506 #
1507 add_custom_target(SerializeTarget
1508 DEPENDS
1509 ${CMAKE_CURRENT_BINARY_DIR}/grammar.c
1510 ${CMAKE_CURRENT_BINARY_DIR}/scanner.c
1511 )
1512
1513 set_source_files_properties(${PROJECT_EXTERNAL_OBJECT_LIST} PROPERTIES
1514 EXTERNAL_OBJECT TRUE)
1515
1516 if(BUILD_SHARED_LIBS)
1517 add_library(${LIBRARY_NAME} SHARED
1518 ${PROJECT_SOURCE_LIST_C}
1519 ${CMAKE_CURRENT_BINARY_DIR}/grammar.c
1520 ${CMAKE_CURRENT_BINARY_DIR}/scanner.c
1521 ${PROJECT_EXTERNAL_OBJECT_LIST}
1522 )
1523 add_dependencies(${LIBRARY_NAME} SerializeTarget)
1524 endif(BUILD_SHARED_LIBS)
1525
1526 add_library(${LIBRARY_NAME}_static STATIC
1527 ${PROJECT_SOURCE_LIST_C}
1528 ${CMAKE_CURRENT_BINARY_DIR}/grammar.c
1529 ${CMAKE_CURRENT_BINARY_DIR}/scanner.c
1530 ${PROJECT_EXTERNAL_OBJECT_LIST}
1531 )
1532 add_dependencies(${LIBRARY_NAME}_static SerializeTarget)
1533
1534 if(WIN32)
1535 if(BUILD_SHARED_LIBS)
1536 set_target_properties(${LIBRARY_NAME} PROPERTIES
1537 VERSION ${PACKAGE_VERSION_NOSUFFIX} # only MAJOR and MINOR are needed
1538 )
1539 endif(BUILD_SHARED_LIBS)
1540 if(MSVC)
1541 # XXX For DLLs, the TARGET_PDB_FILE generator expression can be used to locate
1542 # its PDB file's output directory for installation.
1543 # cmake doesn't offer a generator expression for PDB files generated by the
1544 # compiler (static libraries).
1545 # So instead of considering any possible output there is (there are many),
1546 # this will search for the PDB file in the compiler's initial output directory,
1547 # which is always ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles\wpcap_static.dir
1548 # regardless of architecture, build generator etc.
1549 # Quite hackish indeed.
1550 set(CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY $<TARGET_FILE_DIR:${LIBRARY_NAME}_static>)
1551 set_target_properties(${LIBRARY_NAME}_static PROPERTIES
1552 COMPILE_PDB_NAME ${LIBRARY_NAME}_static
1553 OUTPUT_NAME "${LIBRARY_NAME}_static"
1554 )
1555 elseif(MINGW)
1556 #
1557 # For compatibility, build the shared library without the "lib" prefix on
1558 # MinGW as well.
1559 #
1560 set_target_properties(${LIBRARY_NAME} PROPERTIES
1561 PREFIX ""
1562 OUTPUT_NAME "${LIBRARY_NAME}"
1563 )
1564 set_target_properties(${LIBRARY_NAME}_static PROPERTIES
1565 OUTPUT_NAME "${LIBRARY_NAME}"
1566 )
1567 endif()
1568 else(WIN32) # UN*X
1569 if(BUILD_SHARED_LIBS)
1570 if(APPLE)
1571 set_target_properties(${LIBRARY_NAME} PROPERTIES
1572 VERSION ${PACKAGE_VERSION}
1573 SOVERSION A
1574 )
1575 else(APPLE)
1576 set_target_properties(${LIBRARY_NAME} PROPERTIES
1577 VERSION ${PACKAGE_VERSION}
1578 SOVERSION ${PACKAGE_VERSION_MAJOR}
1579 )
1580 endif(APPLE)
1581 endif(BUILD_SHARED_LIBS)
1582 set_target_properties(${LIBRARY_NAME}_static PROPERTIES
1583 OUTPUT_NAME "${LIBRARY_NAME}"
1584 )
1585 endif(WIN32)
1586
1587 if(BUILD_SHARED_LIBS)
1588 set_target_properties(${LIBRARY_NAME} PROPERTIES COMPILE_OPTIONS "${C_ADDITIONAL_FLAGS}")
1589 endif(BUILD_SHARED_LIBS)
1590 set_target_properties(${LIBRARY_NAME}_static PROPERTIES COMPILE_OPTIONS "${C_ADDITIONAL_FLAGS}")
1591
1592 if(BUILD_SHARED_LIBS)
1593 target_link_libraries(${LIBRARY_NAME} ${PCAP_LINK_LIBRARIES})
1594 endif(BUILD_SHARED_LIBS)
1595
1596 ######################################
1597 # Write out the config.h file
1598 ######################################
1599
1600 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
1601
1602 ######################################
1603 # Install pcap library, include files, and man pages
1604 ######################################
1605
1606 #
1607 # "Define GNU standard installation directories", which actually
1608 # are also defined, to some degree, by autotools, and at least
1609 # some of which are general UN*X conventions.
1610 #
1611 include(GNUInstallDirs)
1612
1613 set(LIBRARY_NAME_STATIC ${LIBRARY_NAME}_static)
1614
1615 function(install_manpage_symlink SOURCE TARGET MANDIR)
1616 if(MINGW)
1617 find_program(LINK_EXECUTABLE ln)
1618 if(LINK_EXECUTABLE)
1619 set(LINK_COMMAND "\"${LINK_EXECUTABLE}\" \"-s\" \"${SOURCE}\" \"${TARGET}\"")
1620 else(LINK_EXECUTABLE)
1621 message(FATAL_ERROR "ln (http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ln.html) not find.")
1622 endif(LINK_EXECUTABLE)
1623 else(MINGW)
1624 set(LINK_COMMAND "\"${CMAKE_COMMAND}\" \"-E\" \"create_symlink\" \"${SOURCE}\" \"${TARGET}\"")
1625 endif(MINGW)
1626
1627 install(CODE
1628 "message(STATUS \"Symlinking: ${CMAKE_INSTALL_PREFIX}/${MANDIR}/${SOURCE} to ${TARGET}\")
1629 execute_process(
1630 COMMAND \"${CMAKE_COMMAND}\" \"-E\" \"remove\" \"${TARGET}\"
1631 WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${MANDIR}
1632 )
1633 execute_process(
1634 COMMAND ${LINK_COMMAND}
1635 WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${MANDIR}
1636 RESULT_VARIABLE EXIT_STATUS
1637 )
1638 if(NOT EXIT_STATUS EQUAL 0)
1639 message(FATAL_ERROR \"Could not create symbolic link from ${CMAKE_INSTALL_PREFIX}/${MANDIR}/${SOURCE} to ${TARGET}\")
1640 endif()
1641 set(CMAKE_INSTALL_MANIFEST_FILES \${CMAKE_INSTALL_MANIFEST_FILES} ${CMAKE_INSTALL_PREFIX}/${MANDIR}/${TARGET})")
1642 endfunction(install_manpage_symlink)
1643
1644 set(MAN1_NOEXPAND pcap-config.1)
1645 set(MAN3PCAP_EXPAND
1646 pcap.3pcap.in
1647 pcap_compile.3pcap.in
1648 pcap_datalink.3pcap.in
1649 pcap_dump_open.3pcap.in
1650 pcap_get_tstamp_precision.3pcap.in
1651 pcap_list_datalinks.3pcap.in
1652 pcap_list_tstamp_types.3pcap.in
1653 pcap_open_dead.3pcap.in
1654 pcap_open_offline.3pcap.in
1655 pcap_set_tstamp_precision.3pcap.in
1656 pcap_set_tstamp_type.3pcap.in
1657 )
1658 set(MAN3PCAP_NOEXPAND
1659 pcap_activate.3pcap
1660 pcap_breakloop.3pcap
1661 pcap_can_set_rfmon.3pcap
1662 pcap_close.3pcap
1663 pcap_create.3pcap
1664 pcap_datalink_name_to_val.3pcap
1665 pcap_datalink_val_to_name.3pcap
1666 pcap_dump.3pcap
1667 pcap_dump_close.3pcap
1668 pcap_dump_file.3pcap
1669 pcap_dump_flush.3pcap
1670 pcap_dump_ftell.3pcap
1671 pcap_file.3pcap
1672 pcap_fileno.3pcap
1673 pcap_findalldevs.3pcap
1674 pcap_freecode.3pcap
1675 pcap_get_selectable_fd.3pcap
1676 pcap_geterr.3pcap
1677 pcap_inject.3pcap
1678 pcap_is_swapped.3pcap
1679 pcap_lib_version.3pcap
1680 pcap_lookupdev.3pcap
1681 pcap_lookupnet.3pcap
1682 pcap_loop.3pcap
1683 pcap_major_version.3pcap
1684 pcap_next_ex.3pcap
1685 pcap_offline_filter.3pcap
1686 pcap_open_live.3pcap
1687 pcap_set_buffer_size.3pcap
1688 pcap_set_datalink.3pcap
1689 pcap_set_immediate_mode.3pcap
1690 pcap_set_promisc.3pcap
1691 pcap_set_protocol.3pcap
1692 pcap_set_rfmon.3pcap
1693 pcap_set_snaplen.3pcap
1694 pcap_set_timeout.3pcap
1695 pcap_setdirection.3pcap
1696 pcap_setfilter.3pcap
1697 pcap_setnonblock.3pcap
1698 pcap_snapshot.3pcap
1699 pcap_stats.3pcap
1700 pcap_statustostr.3pcap
1701 pcap_strerror.3pcap
1702 pcap_tstamp_type_name_to_val.3pcap
1703 pcap_tstamp_type_val_to_name.3pcap
1704 )
1705 set(MANFILE_EXPAND pcap-savefile.manfile.in)
1706 set(MANMISC_EXPAND
1707 pcap-filter.manmisc.in
1708 pcap-linktype.manmisc.in
1709 pcap-tstamp.manmisc.in
1710 )
1711
1712 if(NOT BUILD_SHARED_LIBS)
1713 unset(LIBRARY_NAME)
1714 endif(NOT BUILD_SHARED_LIBS)
1715
1716 if(WIN32)
1717 if(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8)
1718 #
1719 # Install 64-bit code built with MSVC in the amd64 subdirectories,
1720 # as that's where it expects it to be.
1721 #
1722 install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC}
1723 RUNTIME DESTINATION bin/amd64
1724 LIBRARY DESTINATION lib/amd64
1725 ARCHIVE DESTINATION lib/amd64)
1726 if(NOT MINGW)
1727 install(FILES $<TARGET_FILE_DIR:${LIBRARY_NAME_STATIC}>/${LIBRARY_NAME_STATIC}.pdb
1728 DESTINATION bin/amd64 OPTIONAL)
1729 if(BUILD_SHARED_LIBS)
1730 install(FILES $<TARGET_PDB_FILE:${LIBRARY_NAME}>
1731 DESTINATION bin/amd64 OPTIONAL)
1732 endif(BUILD_SHARED_LIBS)
1733 endif(NOT MINGW)
1734 else(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8)
1735 #
1736 # Install 32-bit code, and 64-bit code not built with MSVC
1737 # in the top-level directories, as those are where they
1738 # expect it to be.
1739 #
1740 install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC}
1741 RUNTIME DESTINATION bin
1742 LIBRARY DESTINATION lib
1743 ARCHIVE DESTINATION lib)
1744 if(NOT MINGW)
1745 install(FILES $<TARGET_FILE_DIR:${LIBRARY_NAME_STATIC}>/${LIBRARY_NAME_STATIC}.pdb
1746 DESTINATION bin OPTIONAL)
1747 if(BUILD_SHARED_LIBS)
1748 install(FILES $<TARGET_PDB_FILE:${LIBRARY_NAME}>
1749 DESTINATION bin OPTIONAL)
1750 endif(BUILD_SHARED_LIBS)
1751 endif(NOT MINGW)
1752 endif(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8)
1753 else(WIN32)
1754 install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC} DESTINATION lib)
1755 endif(WIN32)
1756
1757 install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/pcap/ DESTINATION include/pcap)
1758 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pcap.h DESTINATION include)
1759
1760 # On UN*X, and on Windows when not using MSVC, generate pcap-config and process
1761 # man pages and arrange that they be installed.
1762 if(NOT MSVC)
1763 set(PACKAGE_NAME ${LIBRARY_NAME})
1764 set(prefix ${CMAKE_INSTALL_PREFIX})
1765 set(exec_prefix "\${prefix}")
1766 set(includedir "\${prefix}/include")
1767 set(libdir "\${exec_prefix}/lib")
1768 if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR
1769 CMAKE_SYSTEM_NAME STREQUAL "NetBSD" OR
1770 CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR
1771 CMAKE_SYSTEM_NAME STREQUAL "DragonFly BSD" OR
1772 CMAKE_SYSTEM_NAME STREQUAL "Linux" OR
1773 CMAKE_SYSTEM_NAME STREQUAL "OSF1")
1774 #
1775 # Platforms where the linker is the GNU linker
1776 # or accepts command-line arguments like
1777 # those the GNU linker accepts.
1778 #
1779 set(V_RPATH_OPT "-Wl,-rpath,")
1780 elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_VERSION MATCHES "5[.][0-9.]*")
1781 #
1782 # SunOS 5.x.
1783 #
1784 # XXX - this assumes GCC is using the Sun linker,
1785 # rather than the GNU linker.
1786 #
1787 set(V_RPATH_OPT "-Wl,-R,")
1788 else()
1789 #
1790 # No option needed to set the RPATH.
1791 #
1792 set(V_RPATH_OPT "")
1793 endif()
1794 set(LIBS "")
1795 foreach(LIB ${PCAP_LINK_LIBRARIES})
1796 set(LIBS "${LIBS} -l${LIB}")
1797 endforeach(LIB)
1798 configure_file(${CMAKE_SOURCE_DIR}/pcap-config.in ${CMAKE_CURRENT_BINARY_DIR}/pcap-config @ONLY)
1799 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/pcap-config DESTINATION bin)
1800
1801 #
1802 # Man pages.
1803 #
1804 # For each section of the manual for which we have man pages
1805 # that require macro expansion, do the expansion.
1806 #
1807 set(MAN1 "")
1808 foreach(MANPAGE ${MAN1_NOEXPAND})
1809 set(MAN1 ${MAN1} ${CMAKE_SOURCE_DIR}/${MANPAGE})
1810 endforeach(MANPAGE)
1811 install(FILES ${MAN1} DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
1812
1813 set(MAN3PCAP "")
1814 foreach(MANPAGE ${MAN3PCAP_NOEXPAND})
1815 set(MAN3PCAP ${MAN3PCAP} ${CMAKE_SOURCE_DIR}/${MANPAGE})
1816 endforeach(MANPAGE)
1817 foreach(TEMPLATE_MANPAGE ${MAN3PCAP_EXPAND})
1818 string(REPLACE ".in" "" MANPAGE ${TEMPLATE_MANPAGE})
1819 configure_file(${CMAKE_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY)
1820 set(MAN3PCAP ${MAN3PCAP} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE})
1821 endforeach(TEMPLATE_MANPAGE)
1822 install(FILES ${MAN3PCAP} DESTINATION ${CMAKE_INSTALL_MANDIR}/man3)
1823 install_manpage_symlink(pcap_datalink_val_to_name.3pcap pcap_datalink_val_to_description.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
1824 install_manpage_symlink(pcap_dump_open.3pcap pcap_dump_fopen.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
1825 install_manpage_symlink(pcap_findalldevs.3pcap pcap_freealldevs.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
1826 install_manpage_symlink(pcap_geterr.3pcap pcap_perror.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
1827 install_manpage_symlink(pcap_inject.3pcap pcap_sendpacket.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
1828 install_manpage_symlink(pcap_list_datalinks.3pcap pcap_free_datalinks.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
1829 install_manpage_symlink(pcap_list_tstamp_types.3pcap pcap_free_tstamp_types.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
1830 install_manpage_symlink(pcap_loop.3pcap pcap_dispatch.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
1831 install_manpage_symlink(pcap_major_version.3pcap pcap_minor_version.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
1832 install_manpage_symlink(pcap_next_ex.3pcap pcap_next.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
1833 install_manpage_symlink(pcap_open_dead.3pcap pcap_open_dead_with_tstamp_precision.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
1834 install_manpage_symlink(pcap_open_offline.3pcap pcap_open_offline_with_tstamp_precision.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
1835 install_manpage_symlink(pcap_open_offline.3pcap pcap_fopen_offline.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
1836 install_manpage_symlink(pcap_open_offline.3pcap pcap_fopen_offline_with_tstamp_precision.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
1837 install_manpage_symlink(pcap_tstamp_type_val_to_name.3pcap pcap_tstamp_type_val_to_description.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
1838 install_manpage_symlink(pcap_setnonblock.3pcap pcap_getnonblock.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
1839
1840 set(MANFILE "")
1841 foreach(TEMPLATE_MANPAGE ${MANFILE_EXPAND})
1842 string(REPLACE ".manfile.in" ".${MAN_FILE_FORMATS}" MANPAGE ${TEMPLATE_MANPAGE})
1843 configure_file(${CMAKE_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY)
1844 set(MANFILE ${MANFILE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE})
1845 endforeach(TEMPLATE_MANPAGE)
1846 install(FILES ${MANFILE} DESTINATION ${CMAKE_INSTALL_MANDIR}/man${MAN_FILE_FORMATS})
1847
1848 set(MANMISC "")
1849 foreach(TEMPLATE_MANPAGE ${MANMISC_EXPAND})
1850 string(REPLACE ".manmisc.in" ".${MAN_MISC_INFO}" MANPAGE ${TEMPLATE_MANPAGE})
1851 configure_file(${CMAKE_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY)
1852 set(MANMISC ${MANMISC} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE})
1853 endforeach(TEMPLATE_MANPAGE)
1854 install(FILES ${MANMISC} DESTINATION ${CMAKE_INSTALL_MANDIR}/man${MAN_MISC_INFO})
1855 endif(NOT MSVC)
1856
1857 # uninstall target
1858 configure_file(
1859 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
1860 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
1861 IMMEDIATE @ONLY)
1862
1863 add_custom_target(uninstall
1864 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)