1 cmake_minimum_required(VERSION 2.8.6)
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.
9 cmake_policy(SET CMP0042 OLD)
12 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
16 ###################################################################
18 ###################################################################
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.
26 set(LIBRARY_NAME pcap CACHE STRING "Library name")
29 # On UN*X, it's always been libpcap.
31 set(LIBRARY_NAME pcap)
34 option(INET6 "Enable IPv6" ON)
36 option(USE_STATIC_RT "Use static Runtime" ON)
38 option(BUILD_SHARED_LIBS "Build shared libraries" ON)
40 set(PACKET_DLL_DIR "" CACHE PATH "Path to directory with include and lib subdirectories for packet.dll")
43 # To pacify those who hate the protochain instruction
44 option(NO_PROTOCHAIN "Disable protochain instruction" OFF)
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
51 set(PCAP_TYPE "" CACHE STRING "Packet capture type")
54 # Default to having remote capture support on Windows and, for now, to
55 # not having it on UN*X.
58 option(ENABLE_REMOTE "Enable remote capture" ON)
60 option(ENABLE_REMOTE "Enable remote capture" OFF)
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)
69 # By default, build universal with the appropriate set of architectures
70 # for the OS on which we're doing the build.
72 if(APPLE AND "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "")
74 # Get the major version of Darwin.
76 string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MAJOR "${CMAKE_SYSTEM_VERSION}")
78 if(SYSTEM_VERSION_MAJOR LESS 8)
80 # Pre-Tiger. Build only for 32-bit PowerPC.
82 set(CMAKE_OSX_ARCHITECTURES "ppc")
83 elseif(SYSTEM_VERSION_MAJOR EQUAL 8)
85 # Tiger. Is this prior to, or with, Intel support?
87 # Get the minor version of Darwin.
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)
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.)
97 set(CMAKE_OSX_ARCHITECTURES "ppc;ppc64")
98 elseif(SYSTEM_VERSION_MINOR LESS 7)
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.)
105 set(CMAKE_OSX_ARCHITECTURES "ppc;ppc64;i386")
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.)
113 set(CMAKE_OSX_ARCHITECTURES "ppc;ppc64;i386;x86_64")
115 elseif(SYSTEM_VERSION_MAJOR EQUAL 9)
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.)
121 set(CMAKE_OSX_ARCHITECTURES "ppc;ppc64;i386;x86_64")
122 elseif(SYSTEM_VERSION_MAJOR EQUAL 10)
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
132 set(CMAKE_OSX_ARCHITECTURES "x86_64;i386;ppc")
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.
141 set(CMAKE_OSX_ARCHITECTURES "x86_64;i386")
146 # Additional capture modules.
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)
152 # We don't support D-Bus sniffing on macOS; see
154 # https://bugs.freedesktop.org/show_bug.cgi?id=74029
157 option(DISABLE_DBUS "Disable D-Bus sniffing support" ON)
159 option(DISABLE_DBUS "Disable D-Bus sniffing support" OFF)
161 option(DISABLE_RDMA "Disable RDMA sniffing support" OFF)
163 option(DISABLE_DAG "Disable Endace DAG card support" OFF)
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")
168 option(DISABLE_SNF "Disable Myricom SNF support" OFF)
170 option(DISABLE_TC "Disable Riverbed TurboCap support" OFF)
175 option(BDEBUG "Build optimizer debugging code" OFF)
176 option(YYDEBUG "Build parser debugging code" OFF)
178 ###################################################################
180 ###################################################################
182 # Get, parse, format and set pcap's version string from [pcap_root]/VERSION
185 # Get MAJOR, MINOR, PATCH & SUFFIX
186 file(STRINGS ${pcap_SOURCE_DIR}/VERSION
188 LIMIT_COUNT 1 # Read only the first line
192 string(REGEX MATCH "^([0-9]+)" PACKAGE_VERSION_MAJOR "${PACKAGE_VERSION}")
194 # Get MAJOR, MINOR & PATCH
195 string(REGEX MATCH "^([0-9]+.)?([0-9]+.)?([0-9]+)" PACKAGE_VERSION_NOSUFFIX "${PACKAGE_VERSION}")
198 # Convert PCAP_VERSION_NOSUFFIX to Windows preferred version format
199 string(REPLACE "." "," PACKAGE_VERSION_PREDLL ${PACKAGE_VERSION_NOSUFFIX})
201 # Append NANO (used for Windows internal versioning) to PCAP_VERSION_PREDLL
203 set(PACKAGE_VERSION_DLL ${PACKAGE_VERSION_PREDLL},0)
206 set(PACKAGE_NAME "${LIBRARY_NAME}")
207 set(PACKAGE_STRING "${LIBRARY_NAME} ${PACKAGE_VERSION}")
209 ######################################
211 ######################################
213 add_definitions(-DHAVE_CONFIG_H)
216 ${CMAKE_CURRENT_BINARY_DIR}
220 include(CheckFunctionExists)
221 include(CMakePushCheckState)
225 if(IS_DIRECTORY ${CMAKE_HOME_DIRECTORY}/../../Common)
226 include_directories(${CMAKE_HOME_DIRECTORY}/../../Common)
227 endif(IS_DIRECTORY ${CMAKE_HOME_DIRECTORY}/../../Common)
231 set(HAVE_PACKET32 TRUE)
232 include_directories(${PACKET_INCLUDE_DIR})
234 # Check whether we have the NPcap PacketIsLoopbackAdapter()
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()
245 add_definitions(-DBUILDING_PCAP)
248 add_definitions(-D__STDC__)
249 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
253 message(STATUS "Use STATIC runtime")
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}}")
263 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc")
266 message(STATUS "Use DYNAMIC runtime")
269 ###################################################################
270 # Detect available platform features
271 ###################################################################
273 include(CheckIncludeFile)
274 include(CheckIncludeFiles)
275 include(CheckStructHasMember)
276 include(CheckTypeSize)
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)
296 # Check for various PF actions.
298 check_c_source_compiles(
299 "#include <sys/types.h>
300 #include <sys/socket.h>
302 #include <net/pfvar.h>
307 return PF_NAT+PF_NONAT+PF_BINAT+PF_NOBINAT+PF_RDR+PF_NORDR;
310 HAVE_PF_NAT_THROUGH_PF_NORDR)
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)
316 # linux/if_bonding.h requires sys/socket.h.
318 check_include_files("sys/socket.h;linux/if_bonding.h" HAVE_LINUX_IF_BONDING_H)
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)
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.
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)
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.
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)
363 check_struct_has_member("struct sockaddr" sa_len sys/socket.h HAVE_SOCKADDR_SA_LEN)
366 # Do we have ffs(), and is it declared in <strings.h>?
368 include(CheckSymbolExists)
369 check_function_exists(ether_hostton HAVE_FFS)
372 # OK, we have ffs(). Is it declared in <strings.h>?
374 # This test fails if we don't have <strings.h> or if we do
375 # but it doesn't declare ffs().
377 check_symbol_exists(ffs strings.h STRINGS_H_DECLARES_FFS)
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.
390 # Before you is a C compiler.
392 check_function_exists(ether_hostton HAVE_ETHER_HOSTTON)
393 if(HAVE_ETHER_HOSTTON)
395 # OK, we have ether_hostton(). Is it declared in <net/ethernet.h>?
397 # This test fails if we don't have <net/ethernet.h> or if we do
398 # but it doesn't declare ether_hostton().
400 check_symbol_exists(ether_hostton net/ethernet.h NET_ETHERNET_H_DECLARES_ETHER_HOSTTON)
401 if(NET_ETHERNET_H_DECLARES_ETHER_HOSTTON)
403 # Yes - we have it declared.
405 set(HAVE_DECL_ETHER_HOSTTON TRUE)
410 if(NOT HAVE_DECL_ETHER_HOSTTON)
412 # No - how about <netinet/ether.h>, as on Linux?
414 # This test fails if we don't have <netinet/ether.h>
415 # or if we do but it doesn't declare ether_hostton().
417 check_symbol_exists(ether_hostton netinet/ether.h NETINET_ETHER_H_DECLARES_ETHER_HOSTTON)
418 if(NETINET_ETHER_H_DECLARES_ETHER_HOSTTON)
420 # Yes - we have it declared.
422 set(HAVE_DECL_ETHER_HOSTTON TRUE)
428 if(NOT HAVE_DECL_ETHER_HOSTTON)
430 # No - how about <sys/ethernet.h>, as on Solaris 10 and later?
432 # This test fails if we don't have <sys/ethernet.h>
433 # or if we do but it doesn't declare ether_hostton().
435 check_symbol_exists(ether_hostton sys/ethernet.h SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON)
436 if(SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON)
438 # Yes - we have it declared.
440 set(HAVE_DECL_ETHER_HOSTTON TRUE)
446 if(NOT HAVE_DECL_ETHER_HOSTTON)
448 # No, how about <arpa/inet.h>, as on AIX?
450 # This test fails if we don't have <arpa/inet.h>
451 # or if we do but it doesn't declare ether_hostton().
453 check_symbol_exists(ether_hostton arpa/inet.h ARPA_INET_H_DECLARES_ETHER_HOSTTON)
454 if(ARPA_INET_H_DECLARES_ETHER_HOSTTON)
456 # Yes - we have it declared.
458 set(HAVE_DECL_ETHER_HOSTTON TRUE)
464 if(NOT HAVE_DECL_ETHER_HOSTTON)
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.
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().
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)
478 # Yes - we have it declared.
480 set(HAVE_DECL_ETHER_HOSTTON TRUE)
484 # After all that, is ether_hostton() declared?
486 if(NOT HAVE_DECL_ETHER_HOSTTON)
488 # No, we'll have to declare it ourselves.
489 # Do we have "struct ether_addr" if we include<netinet/if_ether.h>?
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)
496 # Large file support on UN*X, a/k/a LFS.
502 # Add the required #defines.
504 add_definitions(${LFS_DEFINITIONS})
508 # Check for fseeko as well.
515 # Add the required #defines.
517 add_definitions(${FSEEKO_DEFINITIONS})
522 message(STATUS "Support IPv6")
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.
533 set(CMAKE_THREAD_PREFER_PTHREAD ON)
534 find_package(Threads)
535 if(NOT CMAKE_USE_PTHREADS_INIT)
537 # If it's not pthreads, we won't use it; we use it for libraries
540 set(CMAKE_THREAD_LIBS_INIT "")
541 endif(NOT CMAKE_USE_PTHREADS_INIT)
544 ######################################
546 ######################################
548 set(PROJECT_SOURCE_LIST_C
566 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/win_snprintf.c)
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)
577 # Determine the main pcap-XXX.c file to use, and the libraries with
578 # which we need to link libpcap, if any.
582 # Windows; we need to link with WinSock2.
584 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ws2_32)
587 # Has the user explicitly specified a capture type?
589 if(PCAP_TYPE STREQUAL "")
591 # The user didn't explicitly specify a capture mechanism.
592 # Check whether we have packet.dll.
596 # We have packet.dll.
597 # Set the capture type to NPF.
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)
613 # Figure out what type of packet capture mechanism we have, and
614 # what libraries we'd need to link libpcap with, if any.
618 # Has the user explicitly specified a capture type?
620 if(PCAP_TYPE STREQUAL "")
622 # Check for a bunch of headers for various packet capture mechanisms.
624 check_include_files("sys/types.h;net/bpf.h" HAVE_NET_BPF_H)
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,
638 # sys/types.h, because FreeBSD 10's net/bpf.h
639 # requires that various BSD-style integer types
642 # sys/ioctl.h and, if we have it, sys/ioccom.h,
643 # because net/bpf.h defines ioctls;
645 # net/if.h, because it defines some structures
646 # used in ioctls defined by net/bpf.h;
648 # sys/socket.h, because OpenBSD 5.9's net/bpf.h
649 # defines some structure fields as being
652 # and net/bpf.h doesn't necessarily include all
653 # of those headers itself.
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)
669 if(BPF_H_DEFINES_BIOCSETIF)
672 # Check this before DLPI, so that we pick BPF on
673 # Solaris 11 and later.
676 elseif(HAVE_LINUX_SOCKET_H)
678 # No prizes for guessing this one.
681 elseif(HAVE_NET_PFILT_H)
683 # DEC OSF/1, Digital UNIX, Tru64 UNIX
686 elseif(HAVE_NET_ENET_H)
688 # Stanford Enetfilter.
691 elseif(HAVE_NET_NIT_H)
693 # SunOS 4.x STREAMS NIT.
696 elseif(HAVE_SYS_NET_NIT_H)
698 # Pre-SunOS 4.x non-STREAMS NIT.
701 elseif(HAVE_NET_RAW_H)
706 elseif(HAVE_SYS_DLPI_H)
708 # DLPI on pre-Solaris 11 SunOS 5, HP-UX, possibly others.
713 # Nothing we support.
719 message(STATUS "Packet capture mechanism type: ${PCAP_TYPE}")
722 # Do capture-mechanism-dependent tests.
725 if(PCAP_TYPE STREQUAL "npf")
727 # Link with packet.dll before WinSock2.
729 set(PCAP_LINK_LIBRARIES ${PACKET_LIBRARY} ${PCAP_LINK_LIBRARIES})
730 elseif(PCAP_TYPE STREQUAL "null")
732 message(ERROR "${PCAP_TYPE} is not a valid pcap type")
735 if(PCAP_TYPE STREQUAL "dlpi")
737 # Needed for common functions used by pcap-[dlpi,libdlpi].c
739 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} dlpisubs.c)
742 # Checks for some header files.
744 check_include_file(sys/bufmod.h HAVE_SYS_BUFMOD_H)
745 check_include_file(sys/dlpi_ext.h HAVE_SYS_DLPI_EXT_H)
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".
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()
767 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} dlpi)
768 set(PCAP_TYPE libdlpi)
772 # This check is for Solaris with DLPI support for passive modes.
773 # See dlpi(7P) for more details.
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.
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")
783 # Do we have the wireless extensions?
784 # linux/wireless.h requires sys/socket.h.
786 check_include_files("sys/socket.h;linux/wireless.h" HAVE_LINUX_WIRELESS_H)
793 # Try libnl 3.x first.
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()
801 # Yes, we have libnl 3.x.
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")
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()
818 # Yes, we have libnl 2.x.
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)
826 # No, we don't; do we have libnl 1.x?
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()
833 set(PCAP_LINK_LIBRARIES nl ${PCAP_LINK_LIBRARIES})
839 check_include_file(linux/ethtool.h HAVE_LINUX_ETHTOOL_H)
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.
845 check_struct_has_member("struct tpacket_stats" tp_packets linux/if_packet.h HAVE_TPACKET_STATS)
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)
851 elseif(PCAP_TYPE STREQUAL "bpf")
853 # Check whether we have the *BSD-style ioctls.
855 check_include_files("sys/types.h;net/if_media.h" HAVE_NET_IF_MEDIA_H)
858 # Check whether we have struct BPF_TIMEVAL.
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)
863 check_struct_has_member("struct BPF_TIMEVAL" tv_sec "sys/types.h;net/bpf.h" HAVE_STRUCT_BPF_TIMEVAL)
865 elseif(PCAP_TYPE STREQUAL "null")
867 message(FATAL_ERROR "${PCAP_TYPE} is not a valid pcap type")
871 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-${PCAP_TYPE}.c)
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
880 # UN*X - figure out what type of interface list mechanism we
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
887 if(NOT PCAP_TYPE STREQUAL "null")
888 check_function_exists(getifaddrs HAVE_GETIFADDRS)
889 if(NOT HAVE_GETIFADDRS)
891 # It's in libsocket on Solaris and possibly other OSes;
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.
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)
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.
911 check_include_files("sys/types.h;ifaddrs.h" HAVE_IFADDRS_H)
914 # We have the header, so we use "getifaddrs()" to
915 # get the list of interfaces.
917 set(FINDALLDEVS_TYPE getad)
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.
928 message(FATAL_ERROR "Your system has getifaddrs() but doesn't have a usable <ifaddrs.h>.")
932 # Well, we don't have "getifaddrs()", so we have to use
933 # some other mechanism; determine what that mechanism is.
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.
938 if(PCAP_TYPE STREQUAL "dlpi" OR PCAP_TYPE STREQUAL "libdlpi")
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
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)
949 set(FINDALLDEVS_TYPE gifc)
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
958 set(FINDALLDEVS_TYPE gifc)
961 message(STATUS "Find-interfaces mechanism type: ${FINDALLDEVS_TYPE}")
962 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} fad-${FINDALLDEVS_TYPE}.c)
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)
972 # Check for additional native sniffing capabilities.
975 # Check for USB sniffing support on Linux.
976 # On FreeBSD, it uses BPF, so we don't need to do anything special here.
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)
983 # Do we have a version of <linux/compiler.h> available?
984 # If so, we might need it for <linux/usbdevice_fs.h>.
986 check_include_files("linux/compiler.h" HAVE_LINUX_COMPILER_H)
987 if(HAVE_LINUX_COMPILER_H)
989 # Yes - include it when testing for <linux/usbdevice_fs.h>.
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)
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
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)
1011 # Check for netfilter sniffing support.
1012 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
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.
1018 # Check whether the includes Just Work. If not, don't turn on
1019 # netfilter support.
1021 check_c_source_compiles(
1022 "#include <sys/socket.h>
1023 #include <netinet/in.h>
1024 #include <linux/types.h>
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>
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)
1044 # Check for netmap sniffing support.
1045 if(NOT DISABLE_NETMAP)
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
1052 check_c_source_compiles(
1053 "#define NETMAP_WITH_LIBS
1054 #include <net/netmap_user.h>
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)
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)
1070 # OK, does struct sockaddr_hci have an hci_channel
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)
1076 # OK, is HCI_CHANNEL_MONITOR defined?
1078 check_c_source_compiles(
1079 "#include <bluetooth/bluetooth.h>
1080 #include <bluetooth/hci.h>
1085 u_int i = HCI_CHANNEL_MONITOR;
1089 PCAP_SUPPORT_BT_MONITOR)
1090 if(PCAP_SUPPORT_BT_MONITOR)
1092 # Yes, so we can also support Bluetooth monitor
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)
1102 # Check for Bluetooth sniffing support
1103 if(NOT DISABLE_DBUS)
1105 # We don't support D-Bus sniffing on macOS; see
1107 # https://bugs.freedesktop.org/show_bug.cgi?id=74029
1110 message(FATAL_ERROR "Due to freedesktop.org bug 74029, D-Bus capture support is not available on macOS")
1112 include(FindPkgConfig)
1113 pkg_check_modules(DBUS dbus-1)
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})
1120 endif(NOT DISABLE_DBUS)
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)
1138 # Check for sniffing capabilities using third-party APIs.
1141 # Check for Endace DAG card support.
1144 # Try to find the DAG header file and library.
1154 # Check for various DAG API functions.
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")
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()
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})
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)
1177 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
1183 # Check for Septel card support.
1184 set(PROJECT_EXTERNAL_OBJECT_LIST "")
1185 if(NOT DISABLE_SEPTEL)
1187 # Do we have the msg.h header?
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()
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)
1205 # Check for Myricom SNF support.
1208 # Try to find the SNF header file and library.
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})
1226 # Check for Riverbed TurboCap support.
1229 # Try to find the TurboCap header file and library.
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++")
1248 # Remote capture support.
1253 # Check for various members of struct msghdr.
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)
1261 file(GLOB PROJECT_SOURCE_LIST_H
1267 # Check and add warning options if we have a .devel file.
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}")
1280 set(C_ADDITIONAL_FLAGS "")
1281 if(EXISTS ${CMAKE_SOURCE_DIR}/.devel)
1283 # -W options, used by GCC and compilers that try to behave like it.
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)
1295 # Add subdirectories after we've set C_ADDITIONAL_FLAGS, so they
1296 # pick up those flags.
1299 add_subdirectory(rpcapd)
1300 endif(ENABLE_REMOTE)
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.
1307 # Not necessary with MSVC, as that's the default.
1310 if(CMAKE_C_COMPILER_ID MATCHES "SunPro")
1312 # Sun C/Oracle Studio.
1314 check_and_add_compiler_option(-xldscope=hidden)
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,
1321 check_and_add_compiler_option(-fvisibility=hidden)
1326 # {Flex} and YACC/Berkeley YACC/Bison.
1327 # From a mail message to the CMake mailing list by Andy Cedilnik of
1332 # Try to find Flex, a Windows version of Flex, or Lex.
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.")
1338 message(STATUS "Lexical analyzer generator: ${LEX_EXECUTABLE}")
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
1348 # Since scanner.c does not exist yet when cmake is run, mark
1351 # Since scanner.c includes grammar.h, mark that as a dependency.
1353 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/scanner.c PROPERTIES
1355 OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/scanner.h
1359 # Add scanner.c to the list of sources.
1361 #set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${CMAKE_CURRENT_BINARY_DIR}/scanner.c)
1364 # Try to find YACC or Bison.
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.")
1370 message(STATUS "Parser generator: ${YACC_EXECUTABLE}")
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).
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")
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
1389 # Since grammar.c does not exists yet when cmake is run, mark
1392 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/grammar.c PROPERTIES
1397 # Add grammar.c to the list of sources.
1399 #set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${CMAKE_CURRENT_BINARY_DIR}/grammar.c)
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.
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
1412 if(PCAP_TYPE STREQUAL "bpf")
1414 # If we're using BPF, we need libodm and libcfg, as
1415 # we use them to load the BPF module.
1417 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} odm cfg)
1419 elseif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
1420 if(CMAKE_SYSTEM_VERSION MATCHES "[A-Z.]*9\.[0-9]*")
1424 set(HAVE_HPUX9 TRUE)
1425 elseif(CMAKE_SYSTEM_VERSION MATCHES "[A-Z.]*10\.0")
1429 elseif(CMAKE_SYSTEM_VERSION MATCHES "[A-Z.]*10\.1")
1435 # HP-UX 10.20 and later.
1437 set(HAVE_HPUX10_20_OR_LATER TRUE)
1441 # Use System V conventions for man pages.
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")
1447 # Use System V conventions for man pages.
1449 set(MAN_FILE_FORMATS 4)
1450 set(MAN_MISC_INFO 5)
1451 elseif(CMAKE_SYSTEM_NAME STREQUAL "OSF1")
1453 # DEC OSF/1, a/k/a Digial UNIX, a/k/a Tru64 UNIX.
1454 # Use System V conventions for man pages.
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.]*")
1462 set(HAVE_SOLARIS TRUE)
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).
1471 add_definitions(-D_TS_ERRNO)
1473 if(CMAKE_SYSTEM_VERSION STREQUAL "5.12")
1476 # Use System V conventions for man pages.
1478 set(MAN_USERMOD_SECTION 1m)
1479 set(MAN_FILE_FORMATS 4)
1480 set(MAN_MISC_INFO 5)
1484 source_group("Source Files" FILES ${PROJECT_SOURCE_LIST_C})
1485 source_group("Header Files" FILES ${PROJECT_SOURCE_LIST_H})
1489 # Add pcap-dll.rc to the list of sources.
1491 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${pcap_SOURCE_DIR}/pcap-dll.rc)
1494 add_subdirectory(tests)
1496 ######################################
1498 ######################################
1501 # Special target to serialize the building of the generated source.
1505 # http://public.kitware.com/pipermail/cmake/2013-August/055510.html
1507 add_custom_target(SerializeTarget
1509 ${CMAKE_CURRENT_BINARY_DIR}/grammar.c
1510 ${CMAKE_CURRENT_BINARY_DIR}/scanner.c
1513 set_source_files_properties(${PROJECT_EXTERNAL_OBJECT_LIST} PROPERTIES
1514 EXTERNAL_OBJECT TRUE)
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}
1523 add_dependencies(${LIBRARY_NAME} SerializeTarget)
1524 endif(BUILD_SHARED_LIBS)
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}
1532 add_dependencies(${LIBRARY_NAME}_static SerializeTarget)
1535 if(BUILD_SHARED_LIBS)
1536 set_target_properties(${LIBRARY_NAME} PROPERTIES
1537 VERSION ${PACKAGE_VERSION_NOSUFFIX} # only MAJOR and MINOR are needed
1539 endif(BUILD_SHARED_LIBS)
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"
1557 # For compatibility, build the shared library without the "lib" prefix on
1560 set_target_properties(${LIBRARY_NAME} PROPERTIES
1562 OUTPUT_NAME "${LIBRARY_NAME}"
1564 set_target_properties(${LIBRARY_NAME}_static PROPERTIES
1565 OUTPUT_NAME "${LIBRARY_NAME}"
1569 if(BUILD_SHARED_LIBS)
1571 set_target_properties(${LIBRARY_NAME} PROPERTIES
1572 VERSION ${PACKAGE_VERSION}
1576 set_target_properties(${LIBRARY_NAME} PROPERTIES
1577 VERSION ${PACKAGE_VERSION}
1578 SOVERSION ${PACKAGE_VERSION_MAJOR}
1581 endif(BUILD_SHARED_LIBS)
1582 set_target_properties(${LIBRARY_NAME}_static PROPERTIES
1583 OUTPUT_NAME "${LIBRARY_NAME}"
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}")
1592 if(BUILD_SHARED_LIBS)
1593 target_link_libraries(${LIBRARY_NAME} ${PCAP_LINK_LIBRARIES})
1594 endif(BUILD_SHARED_LIBS)
1596 ######################################
1597 # Write out the config.h file
1598 ######################################
1600 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
1602 ######################################
1603 # Install pcap library, include files, and man pages
1604 ######################################
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.
1611 include(GNUInstallDirs)
1613 set(LIBRARY_NAME_STATIC ${LIBRARY_NAME}_static)
1615 function(install_manpage_symlink SOURCE TARGET MANDIR)
1617 find_program(LINK_EXECUTABLE ln)
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)
1624 set(LINK_COMMAND "\"${CMAKE_COMMAND}\" \"-E\" \"create_symlink\" \"${SOURCE}\" \"${TARGET}\"")
1628 "message(STATUS \"Symlinking: ${CMAKE_INSTALL_PREFIX}/${MANDIR}/${SOURCE} to ${TARGET}\")
1630 COMMAND \"${CMAKE_COMMAND}\" \"-E\" \"remove\" \"${TARGET}\"
1631 WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${MANDIR}
1634 COMMAND ${LINK_COMMAND}
1635 WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${MANDIR}
1636 RESULT_VARIABLE EXIT_STATUS
1638 if(NOT EXIT_STATUS EQUAL 0)
1639 message(FATAL_ERROR \"Could not create symbolic link from ${CMAKE_INSTALL_PREFIX}/${MANDIR}/${SOURCE} to ${TARGET}\")
1641 set(CMAKE_INSTALL_MANIFEST_FILES \${CMAKE_INSTALL_MANIFEST_FILES} ${CMAKE_INSTALL_PREFIX}/${MANDIR}/${TARGET})")
1642 endfunction(install_manpage_symlink)
1644 set(MAN1_NOEXPAND pcap-config.1)
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
1658 set(MAN3PCAP_NOEXPAND
1660 pcap_breakloop.3pcap
1661 pcap_can_set_rfmon.3pcap
1664 pcap_datalink_name_to_val.3pcap
1665 pcap_datalink_val_to_name.3pcap
1667 pcap_dump_close.3pcap
1668 pcap_dump_file.3pcap
1669 pcap_dump_flush.3pcap
1670 pcap_dump_ftell.3pcap
1673 pcap_findalldevs.3pcap
1675 pcap_get_selectable_fd.3pcap
1678 pcap_is_swapped.3pcap
1679 pcap_lib_version.3pcap
1680 pcap_lookupdev.3pcap
1681 pcap_lookupnet.3pcap
1683 pcap_major_version.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
1700 pcap_statustostr.3pcap
1702 pcap_tstamp_type_name_to_val.3pcap
1703 pcap_tstamp_type_val_to_name.3pcap
1705 set(MANFILE_EXPAND pcap-savefile.manfile.in)
1707 pcap-filter.manmisc.in
1708 pcap-linktype.manmisc.in
1709 pcap-tstamp.manmisc.in
1712 if(NOT BUILD_SHARED_LIBS)
1714 endif(NOT BUILD_SHARED_LIBS)
1717 if(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8)
1719 # Install 64-bit code built with MSVC in the amd64 subdirectories,
1720 # as that's where it expects it to be.
1722 install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC}
1723 RUNTIME DESTINATION bin/amd64
1724 LIBRARY DESTINATION lib/amd64
1725 ARCHIVE DESTINATION lib/amd64)
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)
1734 else(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8)
1736 # Install 32-bit code, and 64-bit code not built with MSVC
1737 # in the top-level directories, as those are where they
1740 install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC}
1741 RUNTIME DESTINATION bin
1742 LIBRARY DESTINATION lib
1743 ARCHIVE DESTINATION lib)
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)
1752 endif(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8)
1754 install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC} DESTINATION lib)
1757 install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/pcap/ DESTINATION include/pcap)
1758 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pcap.h DESTINATION include)
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.
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")
1775 # Platforms where the linker is the GNU linker
1776 # or accepts command-line arguments like
1777 # those the GNU linker accepts.
1779 set(V_RPATH_OPT "-Wl,-rpath,")
1780 elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_VERSION MATCHES "5[.][0-9.]*")
1784 # XXX - this assumes GCC is using the Sun linker,
1785 # rather than the GNU linker.
1787 set(V_RPATH_OPT "-Wl,-R,")
1790 # No option needed to set the RPATH.
1795 foreach(LIB ${PCAP_LINK_LIBRARIES})
1796 set(LIBS "${LIBS} -l${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)
1804 # For each section of the manual for which we have man pages
1805 # that require macro expansion, do the expansion.
1808 foreach(MANPAGE ${MAN1_NOEXPAND})
1809 set(MAN1 ${MAN1} ${CMAKE_SOURCE_DIR}/${MANPAGE})
1811 install(FILES ${MAN1} DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
1814 foreach(MANPAGE ${MAN3PCAP_NOEXPAND})
1815 set(MAN3PCAP ${MAN3PCAP} ${CMAKE_SOURCE_DIR}/${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)
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})
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})
1859 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
1860 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
1863 add_custom_target(uninstall
1864 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)