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)
13 # Squelch noise about quoted strings in if() statements.
14 # WE KNOW WHAT WE'RE DOING, WE'RE DOING EVERYTHING THE WAY THAT NEWER
15 # VERSIONS OF CMAKE EXPECT BY DEFAULT, DON'T WASTE OUR TIME WITH NOISE.
17 cmake_policy(SET CMP0054 NEW)
19 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)
23 include(CheckCCompilerFlag)
26 # For checking if a compiler flag works and adding it if it does.
28 macro(check_and_add_compiler_option _option)
29 message(STATUS "Checking C compiler flag ${_option}")
30 string(REPLACE "=" "-" _temp_option_variable ${_option})
31 string(REGEX REPLACE "^-" "" _option_variable ${_temp_option_variable})
32 check_c_compiler_flag("${_option}" ${_option_variable})
33 if(${${_option_variable}})
34 set(C_ADDITIONAL_FLAGS "${C_ADDITIONAL_FLAGS} ${_option}")
39 # If we're building with Visual Studio, we require Visual Studio 2015,
40 # in order to get sufficient C99 compatibility. Check for that.
42 # If not, try the appropriate flag for the compiler to enable C99
45 set(C_ADDITIONAL_FLAGS "")
47 if(MSVC_VERSION LESS 1900)
48 message(FATAL_ERROR "Visual Studio 2015 or later is required")
52 # Treat source files as being in UTF-8 with MSVC if it's not using
53 # the Clang front end.
54 # We assume that UTF-8 source is OK with other compilers and with
55 # MSVC if it's using the Clang front end.
57 if(NOT ${CMAKE_C_COMPILER} MATCHES "clang*")
58 set(C_ADDITIONAL_FLAGS "${C_ADDITIONAL_FLAGS} /utf-8")
59 endif(NOT ${CMAKE_C_COMPILER} MATCHES "clang*")
62 # For checking if a compiler flag works, failing if it doesn't,
63 # and adding it otherwise.
65 macro(require_and_add_compiler_option _option)
66 message(STATUS "Checking C compiler flag ${_option}")
67 string(REPLACE "=" "-" _temp_option_variable ${_option})
68 string(REGEX REPLACE "^-" "" _option_variable ${_temp_option_variable})
69 check_c_compiler_flag("${_option}" ${_option_variable})
70 if(${${_option_variable}})
71 set(C_ADDITIONAL_FLAGS "${C_ADDITIONAL_FLAGS} ${_option}")
73 message(FATAL_ERROR "C99 support is required, but the compiler doesn't support a compiler flag to enable it")
78 # Try to enable as many C99 features as we can.
79 # At minimum, we want C++/C99-style // comments.
81 # Newer versions of compilers might default to supporting C99, but
82 # older versions may require a special flag.
84 # Prior to CMake 3.1, setting CMAKE_C_STANDARD will not have any effect,
85 # so, unless and until we require CMake 3.1 or later, we have to do it
86 # ourselves on pre-3.1 CMake, so we just do it ourselves on all versions
89 # Note: with CMake 3.1 through 3.5, the only compilers for which CMake
90 # handles CMAKE_C_STANDARD are GCC and Clang. 3.6 adds support only
91 # for Intel C; 3.9 adds support for PGI C, Sun C, and IBM XL C, and
92 # 3.10 adds support for Cray C and IAR C, but no version of CMake has
93 # support for HP C. Therefore, even if we use CMAKE_C_STANDARD with
94 # compilers for which CMake supports it, we may still have to do it
95 # ourselves on other compilers.
97 # See the CMake documentation for the CMAKE_<LANG>_COMPILER_ID variables
98 # for a list of compiler IDs.
100 # XXX - this just tests whether the option works, fails if it doesn't,
101 # and adds it if it does. We don't test whether it's necessary in order
102 # to get the C99 features that we use, or whether, if it's used, it
103 # enables all the features that we require.
105 if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR
106 CMAKE_C_COMPILER_ID MATCHES "Clang")
107 require_and_add_compiler_option("-std=gnu99")
108 elseif(CMAKE_C_COMPILER_ID MATCHES "XL")
110 # We want support for extensions picked up for GNU C compatibility,
111 # so we use -qlanglvl=extc99.
113 require_and_add_compiler_option("-qlanglvl=extc99")
114 elseif(CMAKE_C_COMPILER_ID MATCHES "HP")
115 require_and_add_compiler_option("-AC99")
116 elseif(CMAKE_C_COMPILER_ID MATCHES "Sun")
117 require_and_add_compiler_option("-xc99")
118 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
119 require_and_add_compiler_option("-c99")
124 # Build all runtimes in the top-level binary directory; that way,
125 # on Windows, the executables will be in the same directory as
126 # the DLLs, so the system will find pcap.dll when any of the
127 # executables are run.
129 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run)
131 ###################################################################
133 ###################################################################
137 # On Windows, allow the library name to be overridden, for the
138 # benefit of projects that combine libpcap with their own
139 # kernel-mode code to support capturing.
141 set(LIBRARY_NAME pcap CACHE STRING "Library name")
144 # On UN*X, it's always been libpcap.
146 set(LIBRARY_NAME pcap)
149 option(INET6 "Enable IPv6" ON)
151 option(USE_STATIC_RT "Use static Runtime" ON)
153 option(BUILD_SHARED_LIBS "Build shared libraries" ON)
155 set(PACKET_DLL_DIR "" CACHE PATH "Path to directory with include and lib subdirectories for packet.dll")
158 # To pacify those who hate the protochain instruction
159 option(NO_PROTOCHAIN "Disable protochain instruction" OFF)
162 # Start out with the capture mechanism type unspecified; the user
163 # can explicitly specify it and, if they don't, we'll pick an
166 set(PCAP_TYPE "" CACHE STRING "Packet capture type")
169 # Default to having remote capture support on Windows and, for now, to
170 # not having it on UN*X.
173 option(ENABLE_REMOTE "Enable remote capture" ON)
175 option(ENABLE_REMOTE "Enable remote capture" OFF)
178 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
179 option(PCAP_SUPPORT_PACKET_RING "Enable Linux packet ring support" ON)
180 option(BUILD_WITH_LIBNL "Build with libnl" ON)
184 # Additional capture modules.
186 option(DISABLE_USB "Disable USB sniffing support" OFF)
187 option(DISABLE_BLUETOOTH "Disable Bluetooth sniffing support" OFF)
188 option(DISABLE_NETMAP "Disable netmap support" OFF)
189 option(DISABLE_DPDK "Disable DPDK support" OFF)
192 # We don't support D-Bus sniffing on macOS; see
194 # https://bugs.freedesktop.org/show_bug.cgi?id=74029
197 option(DISABLE_DBUS "Disable D-Bus sniffing support" ON)
199 option(DISABLE_DBUS "Disable D-Bus sniffing support" OFF)
201 option(DISABLE_RDMA "Disable RDMA sniffing support" OFF)
203 option(DISABLE_DAG "Disable Endace DAG card support" OFF)
205 option(DISABLE_SEPTEL "Disable Septel card support" OFF)
206 set(SEPTEL_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../septel" CACHE PATH "Path to directory with include and lib subdirectories for Septel API")
208 option(DISABLE_SNF "Disable Myricom SNF support" OFF)
210 option(DISABLE_TC "Disable Riverbed TurboCap support" OFF)
215 option(BDEBUG "Build optimizer debugging code" OFF)
216 option(YYDEBUG "Build parser debugging code" OFF)
218 ###################################################################
220 ###################################################################
222 # Get, parse, format and set pcap's version string from [pcap_root]/VERSION
225 # Get MAJOR, MINOR, PATCH & SUFFIX
226 file(STRINGS ${pcap_SOURCE_DIR}/VERSION
228 LIMIT_COUNT 1 # Read only the first line
232 string(REGEX MATCH "^([0-9]+)" PACKAGE_VERSION_MAJOR "${PACKAGE_VERSION}")
234 # Get MAJOR, MINOR & PATCH
235 string(REGEX MATCH "^([0-9]+.)?([0-9]+.)?([0-9]+)" PACKAGE_VERSION_NOSUFFIX "${PACKAGE_VERSION}")
238 # Convert PCAP_VERSION_NOSUFFIX to Windows preferred version format
239 string(REPLACE "." "," PACKAGE_VERSION_PREDLL ${PACKAGE_VERSION_NOSUFFIX})
241 # Append NANO (used for Windows internal versioning) to PCAP_VERSION_PREDLL
243 set(PACKAGE_VERSION_DLL ${PACKAGE_VERSION_PREDLL},0)
246 set(PACKAGE_NAME "${LIBRARY_NAME}")
247 set(PACKAGE_STRING "${LIBRARY_NAME} ${PACKAGE_VERSION}")
249 ######################################
251 ######################################
253 add_definitions(-DHAVE_CONFIG_H)
256 ${CMAKE_CURRENT_BINARY_DIR}
260 include(CheckFunctionExists)
261 include(CMakePushCheckState)
262 include(CheckSymbolExists)
266 if(IS_DIRECTORY ${CMAKE_HOME_DIRECTORY}/../../Common)
267 include_directories(${CMAKE_HOME_DIRECTORY}/../../Common)
268 endif(IS_DIRECTORY ${CMAKE_HOME_DIRECTORY}/../../Common)
272 set(HAVE_PACKET32 TRUE)
273 include_directories(${PACKET_INCLUDE_DIRS})
275 # Check whether we have the NPcap PacketIsLoopbackAdapter()
278 cmake_push_check_state()
279 set(CMAKE_REQUIRED_LIBRARIES ${PACKET_LIBRARIES})
280 check_function_exists(PacketIsLoopbackAdapter HAVE_PACKET_IS_LOOPBACK_ADAPTER)
281 cmake_pop_check_state()
284 message(STATUS "checking for Npcap's version.h")
285 check_symbol_exists(WINPCAP_PRODUCT_NAME "../../version.h" HAVE_VERSION_H)
287 message(STATUS "HAVE version.h")
289 message(STATUS "MISSING version.h")
290 endif(HAVE_VERSION_H)
295 add_definitions(-D__STDC__)
296 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
300 message(STATUS "Use STATIC runtime")
303 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
304 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
305 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
306 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
307 string(REGEX REPLACE "/MD" "/MT" ${RT_FLAG} "${${RT_FLAG}}")
310 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc")
313 message(STATUS "Use DYNAMIC runtime")
316 ###################################################################
317 # Detect available platform features
318 ###################################################################
320 include(CheckIncludeFile)
321 include(CheckIncludeFiles)
322 include(CheckStructHasMember)
323 include(CheckTypeSize)
326 # Tests are a bit expensive with Visual Studio on Windows, so, on
327 # Windows, we skip tests for UN*X-only headers and functions.
333 check_include_file(inttypes.h HAVE_INTTYPES_H)
334 check_include_file(stdint.h HAVE_STDINT_H)
335 check_include_file(unistd.h HAVE_UNISTD_H)
336 if(NOT HAVE_UNISTD_H)
337 add_definitions(-DYY_NO_UNISTD_H)
338 endif(NOT HAVE_UNISTD_H)
339 check_include_file(bitypes.h HAVE_SYS_BITYPES_H)
341 check_include_file(sys/ioccom.h HAVE_SYS_IOCCOM_H)
342 check_include_file(sys/sockio.h HAVE_SYS_SOCKIO_H)
343 check_include_file(sys/select.h HAVE_SYS_SELECT_H)
345 check_include_file(netpacket/packet.h HAVE_NETPACKET_PACKET_H)
346 check_include_files("sys/types.h;sys/socket.h;net/if.h;net/pfvar.h" HAVE_NET_PFVAR_H)
349 # Check for various PF actions.
351 check_c_source_compiles(
352 "#include <sys/types.h>
353 #include <sys/socket.h>
355 #include <net/pfvar.h>
360 return PF_NAT+PF_NONAT+PF_BINAT+PF_NOBINAT+PF_RDR+PF_NORDR;
363 HAVE_PF_NAT_THROUGH_PF_NORDR)
364 endif(HAVE_NET_PFVAR_H)
365 check_include_file(netinet/if_ether.h HAVE_NETINET_IF_ETHER_H)
366 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
367 check_include_file(linux/sockios.h HAVE_LINUX_SOCKIOS_H)
369 # linux/if_bonding.h requires sys/socket.h.
371 check_include_files("sys/socket.h;linux/if_bonding.h" HAVE_LINUX_IF_BONDING_H)
374 # Check for the eventfd header.
376 check_include_files("sys/eventfd.h" HAVE_SYS_EVENTFD_H)
383 check_function_exists(strerror HAVE_STRERROR)
384 check_function_exists(strerror_r HAVE_STRERROR_R)
387 # We have strerror_r; if we define _GNU_SOURCE, is it a
388 # POSIX-compliant strerror_r() or a GNU strerror_r()?
390 check_c_source_compiles(
394 /* Define it GNU-style; that will cause an error if it's not GNU-style */
395 extern char *strerror_r(int, char *, size_t);
404 if(NOT HAVE_GNU_STRERROR_R)
405 set(HAVE_POSIX_STRERROR_R YES)
406 endif(NOT HAVE_GNU_STRERROR_R)
407 else(HAVE_STRERROR_R)
409 # We don't have strerror_r; do we have strerror_s?
411 check_function_exists(strerror_s HAVE_STRERROR_S)
412 endif(HAVE_STRERROR_R)
415 # Make sure we have vsnprintf() and snprintf(); we require them.
416 # We use check_symbol_exists(), as they aren't necessarily external
417 # functions - in Visual Studio, for example, they're inline functions
418 # calling a common external function.
420 check_symbol_exists(vsnprintf "stdio.h" HAVE_VSNPRINTF)
421 if(NOT HAVE_VSNPRINTF)
422 message(FATAL_ERROR "vsnprintf() is required but wasn't found")
423 endif(NOT HAVE_VSNPRINTF)
424 check_symbol_exists(snprintf "stdio.h" HAVE_SNPRINTF)
425 if(NOT HAVE_SNPRINTF)
426 message(FATAL_ERROR "snprintf() is required but wasn't found")
429 check_function_exists(strlcpy HAVE_STRLCPY)
430 check_function_exists(strlcat HAVE_STRLCAT)
431 check_function_exists(asprintf HAVE_ASPRINTF)
432 check_function_exists(vasprintf HAVE_VASPRINTF)
433 check_function_exists(strtok_r HAVE_STRTOK_R)
435 check_function_exists(vsyslog HAVE_VSYSLOG)
439 # These tests are for network applications that need socket functions
440 # and getaddrinfo()/getnameinfo()-ish functions. We now require
441 # getaddrinfo() and getnameinfo(). On UN*X systems, we also prefer
442 # versions of recvmsg() that conform to the Single UNIX Specification,
443 # so that we can check whether a datagram received with recvmsg() was
444 # truncated when received due to the buffer being too small.
446 # On Windows, getaddrinfo() is in the ws2_32 library.
448 # On most UN*X systems, they're available in the system library.
450 # Under Solaris, we need to link with libsocket and libnsl to get
451 # getaddrinfo() and getnameinfo() and, if we have libxnet, we need to
452 # link with libxnet before libsocket to get a version of recvmsg()
453 # that conforms to the Single UNIX Specification.
455 # We use getaddrinfo() because we want a portable thread-safe way
456 # of getting information for a host name or port; there exist _r
457 # versions of gethostbyname() and getservbyname() on some platforms,
458 # but not on all platforms.
460 # NOTE: if you hand check_library_exists as its last argument a variable
461 # that's been set, it skips the test, so we need different variables.
463 set(PCAP_LINK_LIBRARIES "")
464 include(CheckLibraryExists)
467 # We need winsock2.h and ws2tcpip.h.
469 cmake_push_check_state()
470 set(CMAKE_REQUIRED_LIBRARIES ws2_32)
471 check_symbol_exists(getaddrinfo "winsock2.h;ws2tcpip.h" LIBWS2_32_HAS_GETADDRINFO)
472 cmake_pop_check_state()
473 if(LIBWS2_32_HAS_GETADDRINFO)
474 set(PCAP_LINK_LIBRARIES ws2_32 ${PCAP_LINK_LIBRARIES})
475 else(LIBWS2_32_HAS_GETADDRINFO)
476 message(FATAL_ERROR "getaddrinfo is required, but wasn't found")
477 endif(LIBWS2_32_HAS_GETADDRINFO)
480 # UN*X. First try the system libraries, then try the libraries
481 # for Solaris and possibly other systems that picked up the
482 # System V library split.
484 check_function_exists(getaddrinfo STDLIBS_HAVE_GETADDRINFO)
485 if(NOT STDLIBS_HAVE_GETADDRINFO)
487 # Not found in the standard system libraries.
488 # Try libsocket, which requires libnsl.
490 cmake_push_check_state()
491 set(CMAKE_REQUIRED_LIBRARIES nsl)
492 check_library_exists(socket getaddrinfo "" LIBSOCKET_HAS_GETADDRINFO)
493 cmake_pop_check_state()
494 if(LIBSOCKET_HAS_GETADDRINFO)
496 # OK, we found it in libsocket.
498 set(PCAP_LINK_LIBRARIES socket nsl ${PCAP_LINK_LIBRARIES})
499 else(LIBSOCKET_HAS_GETADDRINFO)
500 check_library_exists(network getaddrinfo "" LIBNETWORK_HAS_GETADDRINFO)
501 if(LIBNETWORK_HAS_GETADDRINFO)
503 # OK, we found it in libnetwork (Haiku).
505 set(PCAP_LINK_LIBRARIES network ${PCAP_LINK_LIBRARIES})
506 else(LIBNETWORK_HAS_GETADDRINFO)
510 message(FATAL_ERROR "getaddrinfo is required, but wasn't found")
511 endif(LIBNETWORK_HAS_GETADDRINFO)
512 endif(LIBSOCKET_HAS_GETADDRINFO)
515 # OK, do we have recvmsg() in libxnet?
516 # We also link with libsocket and libnsl.
518 cmake_push_check_state()
519 set(CMAKE_REQUIRED_LIBRARIES socket nsl)
520 check_library_exists(xnet recvmsg "" LIBXNET_HAS_RECVMSG)
521 cmake_pop_check_state()
522 if(LIBXNET_HAS_RECVMSG)
524 # Yes - link with it as well.
526 set(PCAP_LINK_LIBRARIES xnet ${PCAP_LINK_LIBRARIES})
527 endif(LIBXNET_HAS_RECVMSG)
528 endif(NOT STDLIBS_HAVE_GETADDRINFO)
530 # DLPI needs putmsg under HPUX so test for -lstr while we're at it
531 check_function_exists(putmsg STDLIBS_HAVE_PUTMSG)
532 if(NOT STDLIBS_HAVE_PUTMSG)
533 check_library_exists(str putmsg "" LIBSTR_HAS_PUTMSG)
534 if(LIBSTR_HAS_PUTMSG)
535 set(PCAP_LINK_LIBRARIES str ${PCAP_LINK_LIBRARIES})
536 endif(LIBSTR_HAS_PUTMSG)
537 endif(NOT STDLIBS_HAVE_PUTMSG)
541 # Check for reentrant versions of getnetbyname_r(), as provided by
542 # Linux (glibc), Solaris/IRIX, and AIX (with three different APIs!).
543 # If we don't find one, we just use getnetbyname(), which uses
544 # thread-specific data on many platforms, but doesn't use it on
545 # NetBSD or OpenBSD, and may not use it on older versions of other
548 # Only do the check if we have a declaration of getnetbyname_r();
549 # without it, we can't check which API it has. (We assume that
550 # if there's a declaration, it has a prototype, so that the API
553 cmake_push_check_state()
554 set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LINK_LIBRARIES})
555 check_symbol_exists(getnetbyname_r netdb.h NETDB_H_DECLARES_GETNETBYNAME_R)
556 if(NETDB_H_DECLARES_GETNETBYNAME_R)
557 check_c_source_compiles(
563 struct netent netent_buf;
565 struct netent *resultp;
568 return getnetbyname_r((const char *)0, &netent_buf, buf, sizeof buf, &resultp, &h_errnoval);
571 HAVE_LINUX_GETNETBYNAME_R)
572 if(NOT HAVE_LINUX_GETNETBYNAME_R)
573 check_c_source_compiles(
579 struct netent netent_buf;
582 return getnetbyname_r((const char *)0, &netent_buf, buf, (int)sizeof buf) != NULL;
585 HAVE_SOLARIS_IRIX_GETNETBYNAME_R)
586 if(NOT HAVE_SOLARIS_IRIX_GETNETBYNAME_R)
587 check_c_source_compiles(
593 struct netent netent_buf;
594 struct netent_data net_data;
596 return getnetbyname_r((const char *)0, &netent_buf, &net_data);
599 HAVE_AIX_GETNETBYNAME_R)
600 endif(NOT HAVE_SOLARIS_IRIX_GETNETBYNAME_R)
601 endif(NOT HAVE_LINUX_GETNETBYNAME_R)
602 endif(NETDB_H_DECLARES_GETNETBYNAME_R)
603 cmake_pop_check_state()
606 # Check for reentrant versions of getprotobyname_r(), as provided by
607 # Linux (glibc), Solaris/IRIX, and AIX (with three different APIs!).
608 # If we don't find one, we just use getprotobyname(), which uses
609 # thread-specific data on many platforms, but doesn't use it on
610 # NetBSD or OpenBSD, and may not use it on older versions of other
613 # Only do the check if we have a declaration of getprotobyname_r();
614 # without it, we can't check which API it has. (We assume that
615 # if there's a declaration, it has a prototype, so that the API
618 cmake_push_check_state()
619 set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LINK_LIBRARIES})
620 check_symbol_exists(getprotobyname_r netdb.h NETDB_H_DECLARES_GETPROTOBYNAME_R)
621 if(NETDB_H_DECLARES_GETPROTOBYNAME_R)
622 check_c_source_compiles(
628 struct protoent protoent_buf;
630 struct protoent *resultp;
632 return getprotobyname_r((const char *)0, &protoent_buf, buf, sizeof buf, &resultp);
635 HAVE_LINUX_GETPROTOBYNAME_R)
636 if(NOT HAVE_LINUX_GETPROTOBYNAME_R)
637 check_c_source_compiles(
643 struct protoent protoent_buf;
646 return getprotobyname_r((const char *)0, &protoent_buf, buf, (int)sizeof buf) != NULL;
649 HAVE_SOLARIS_IRIX_GETPROTOBYNAME_R)
650 if(NOT HAVE_SOLARIS_IRIX_GETPROTOBYNAME_R)
651 check_c_source_compiles(
657 struct protoent protoent_buf;
658 struct protoent_data proto_data;
660 return getprotobyname_r((const char *)0, &protoent_buf, &proto_data);
663 HAVE_AIX_GETPROTOBYNAME_R)
664 endif(NOT HAVE_SOLARIS_IRIX_GETPROTOBYNAME_R)
665 endif(NOT HAVE_LINUX_GETPROTOBYNAME_R)
666 endif(NETDB_H_DECLARES_GETPROTOBYNAME_R)
667 cmake_pop_check_state()
672 # XXX - there's no check_type() macro that's like check_type_size()
673 # except that it only checks for the existence of the structure type,
674 # so we use check_type_size() and ignore the size.
676 cmake_push_check_state()
678 set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h)
680 set(CMAKE_EXTRA_INCLUDE_FILES unistd.h sys/socket.h)
682 check_type_size("struct sockaddr_storage" STRUCT_SOCKADDR_STORAGE)
683 check_type_size("socklen_t" SOCKLEN_T)
684 cmake_pop_check_state()
690 check_struct_has_member("struct sockaddr" sa_len winsock2.h HAVE_STRUCT_SOCKADDR_SA_LEN)
692 check_struct_has_member("struct sockaddr" sa_len sys/socket.h HAVE_STRUCT_SOCKADDR_SA_LEN)
696 # Do we have ffs(), and is it declared in <strings.h>?
698 check_function_exists(ffs HAVE_FFS)
701 # OK, we have ffs(). Is it declared in <strings.h>?
703 # This test fails if we don't have <strings.h> or if we do
704 # but it doesn't declare ffs().
706 check_symbol_exists(ffs strings.h STRINGS_H_DECLARES_FFS)
710 # This requires the libraries that we require, as ether_hostton might be
711 # in one of those libraries. That means we have to do this after
712 # we check for those libraries.
714 # You are in a twisty little maze of UN*Xes, all different.
715 # Some might not have ether_hostton().
716 # Some might have it and declare it in <net/ethernet.h>.
717 # Some might have it and declare it in <netinet/ether.h>
718 # Some might have it and declare it in <sys/ethernet.h>.
719 # Some might have it and declare it in <arpa/inet.h>.
720 # Some might have it and declare it in <netinet/if_ether.h>.
721 # Some might have it and not declare it in any header file.
723 # Before you is a C compiler.
725 cmake_push_check_state()
726 set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LINK_LIBRARIES})
727 check_function_exists(ether_hostton HAVE_ETHER_HOSTTON)
728 if(HAVE_ETHER_HOSTTON)
730 # OK, we have ether_hostton(). Is it declared in <net/ethernet.h>?
732 # This test fails if we don't have <net/ethernet.h> or if we do
733 # but it doesn't declare ether_hostton().
735 check_symbol_exists(ether_hostton net/ethernet.h NET_ETHERNET_H_DECLARES_ETHER_HOSTTON)
736 if(NET_ETHERNET_H_DECLARES_ETHER_HOSTTON)
738 # Yes - we have it declared.
740 set(HAVE_DECL_ETHER_HOSTTON TRUE)
745 if(NOT HAVE_DECL_ETHER_HOSTTON)
747 # No - how about <netinet/ether.h>, as on Linux?
749 # This test fails if we don't have <netinet/ether.h>
750 # or if we do but it doesn't declare ether_hostton().
752 check_symbol_exists(ether_hostton netinet/ether.h NETINET_ETHER_H_DECLARES_ETHER_HOSTTON)
753 if(NETINET_ETHER_H_DECLARES_ETHER_HOSTTON)
755 # Yes - we have it declared.
757 set(HAVE_DECL_ETHER_HOSTTON TRUE)
763 if(NOT HAVE_DECL_ETHER_HOSTTON)
765 # No - how about <sys/ethernet.h>, as on Solaris 10 and later?
767 # This test fails if we don't have <sys/ethernet.h>
768 # or if we do but it doesn't declare ether_hostton().
770 check_symbol_exists(ether_hostton sys/ethernet.h SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON)
771 if(SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON)
773 # Yes - we have it declared.
775 set(HAVE_DECL_ETHER_HOSTTON TRUE)
781 if(NOT HAVE_DECL_ETHER_HOSTTON)
783 # No, how about <arpa/inet.h>, as on AIX?
785 # This test fails if we don't have <arpa/inet.h>
786 # or if we do but it doesn't declare ether_hostton().
788 check_symbol_exists(ether_hostton arpa/inet.h ARPA_INET_H_DECLARES_ETHER_HOSTTON)
789 if(ARPA_INET_H_DECLARES_ETHER_HOSTTON)
791 # Yes - we have it declared.
793 set(HAVE_DECL_ETHER_HOSTTON TRUE)
799 if(NOT HAVE_DECL_ETHER_HOSTTON)
801 # No, how about <netinet/if_ether.h>?
802 # On some platforms, it requires <net/if.h> and
803 # <netinet/in.h>, and we always include it with
804 # both of them, so test it with both of them.
806 # This test fails if we don't have <netinet/if_ether.h>
807 # and the headers we include before it, or if we do but
808 # <netinet/if_ether.h> doesn't declare ether_hostton().
810 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)
811 if(NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON)
813 # Yes - we have it declared.
815 set(HAVE_DECL_ETHER_HOSTTON TRUE)
819 # After all that, is ether_hostton() declared?
821 if(NOT HAVE_DECL_ETHER_HOSTTON)
823 # No, we'll have to declare it ourselves.
824 # Do we have "struct ether_addr" if we include <netinet/if_ether.h>?
826 # XXX - there's no check_type() macro that's like check_type_size()
827 # except that it only checks for the existence of the structure type,
828 # so we use check_type_size() and ignore the size.
830 cmake_push_check_state()
831 set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h sys/socket.h net/if.h netinet/in.h netinet/if_ether.h)
832 check_type_size("struct ether_addr" STRUCT_ETHER_ADDR)
833 cmake_pop_check_state()
836 cmake_pop_check_state()
839 # Large file support on UN*X, a/k/a LFS.
845 # Add the required #defines.
847 add_definitions(${LFS_DEFINITIONS})
851 # Check for fseeko as well.
858 # Add the required #defines.
860 add_definitions(${FSEEKO_DEFINITIONS})
865 message(STATUS "Support IPv6")
870 # We might need them, because some libraries we use might use them,
871 # but we don't necessarily need them.
872 # That's only on UN*X; on Windows, if they use threads, we assume
873 # they're native Windows threads.
876 set(CMAKE_THREAD_PREFER_PTHREAD ON)
877 find_package(Threads)
878 if(NOT CMAKE_USE_PTHREADS_INIT)
880 # If it's not pthreads, we won't use it; we use it for libraries
883 set(CMAKE_THREAD_LIBS_INIT "")
884 endif(NOT CMAKE_USE_PTHREADS_INIT)
890 # https://github.com/commonmark/cmark/blob/master/FindAsan.cmake
892 # The MIT License (MIT)
894 # Copyright (c) 2013 Matthew Arsenault
896 # Permission is hereby granted, free of charge, to any person obtaining a copy
897 # of this software and associated documentation files (the "Software"), to deal
898 # in the Software without restriction, including without limitation the rights
899 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
900 # copies of the Software, and to permit persons to whom the Software is
901 # furnished to do so, subject to the following conditions:
903 # The above copyright notice and this permission notice shall be included in
904 # all copies or substantial portions of the Software.
906 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
907 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
908 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
909 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
910 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
911 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
914 # Test if the each of the sanitizers in the ENABLE_SANITIZERS list are
915 # supported by the compiler, and, if so, adds the appropriate flags to
916 # CMAKE_C_FLAGS, CMAKE_CXX_FLAGS, and SANITIZER_FLAGS. If not, it fails.
918 # Do this last, in the hope that it will prevent configuration on Linux
919 # from somehow deciding it doesn't need -lpthread when building rpcapd
920 # (it does require it, but somehow, in some mysterious fashion that no
921 # obvious CMake debugging flag reveals, it doesn't realize that if we
922 # turn sanitizer stuff on).
924 set(SANITIZER_FLAGS "")
925 foreach(sanitizer IN LISTS ENABLE_SANITIZERS)
926 # Set -Werror to catch "argument unused during compilation" warnings
928 message(STATUS "Checking sanitizer ${sanitizer}")
929 set(sanitizer_variable "sanitize_${sanitizer}")
930 set(CMAKE_REQUIRED_FLAGS "-Werror -fsanitize=${sanitizer}")
931 check_c_compiler_flag("-fsanitize=${sanitizer}" ${sanitizer_variable})
932 if(${${sanitizer_variable}})
933 set(SANITIZER_FLAGS "${SANITIZER_FLAGS} -fsanitize=${sanitizer}")
934 message(STATUS "${sanitizer} sanitizer supported using -fsanitizer=${sanitizer}")
937 # Try the versions supported prior to Clang 3.2.
938 # If the sanitizer is "address", try -fsanitize-address.
939 # If it's "undefined", try -fcatch-undefined-behavior.
940 # Otherwise, give up.
942 set(sanitizer_variable "OLD_${sanitizer_variable}")
943 if ("${sanitizer}" STREQUAL "address")
944 set(CMAKE_REQUIRED_FLAGS "-Werror -fsanitize-address")
945 check_c_compiler_flag("-fsanitize-address" ${sanitizer_variable})
946 if(${${sanitizer_variable}})
947 set(SANITIZER_FLAGS "${SANITIZER_FLAGS} -fsanitize-address")
948 message(STATUS "${sanitizer} sanitizer supported using -fsanitize-address")
950 message(FATAL_ERROR "${sanitizer} isn't a supported sanitizer")
952 elseif("${sanitizer}" STREQUAL "undefined")
953 set(CMAKE_REQUIRED_FLAGS "-Werror -fcatch-undefined-behavior")
954 check_c_compiler_flag("-fcatch-undefined-behavior" ${sanitizer_variable})
955 if(${${sanitizer_variable}})
956 set(SANITIZER_FLAGS "${SANITIZER_FLAGS} -fcatch-undefined-behavior")
957 message(STATUS "${sanitizer} sanitizer supported using catch-undefined-behavior")
959 message(FATAL_ERROR "${sanitizer} isn't a supported sanitizer")
962 message(FATAL_ERROR "${sanitizer} isn't a supported sanitizer")
966 unset(CMAKE_REQUIRED_FLAGS)
969 if(NOT "${SANITIZER_FLAGS}" STREQUAL "")
970 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O1 -g ${SANITIZER_FLAGS} -fno-omit-frame-pointer -fno-optimize-sibling-calls")
971 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1 -g ${SANITIZER_FLAGS} -fno-omit-frame-pointer -fno-optimize-sibling-calls")
977 find_package(OpenSSL)
982 include_directories(SYSTEM ${OPENSSL_INCLUDE_DIR})
983 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${OPENSSL_LIBRARIES})
984 set(HAVE_OPENSSL YES)
987 ######################################
989 ######################################
991 set(PROJECT_SOURCE_LIST_C
1009 # We assume we don't have asprintf(), and provide an implementation
1010 # that uses _vscprintf() to determine how big the string needs to be.
1012 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C}
1013 missing/win_asprintf.c)
1015 if(NOT HAVE_ASPRINTF)
1016 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/asprintf.c)
1018 if(NOT HAVE_STRLCAT)
1019 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/strlcat.c)
1020 endif(NOT HAVE_STRLCAT)
1021 if(NOT HAVE_STRLCPY)
1022 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/strlcpy.c)
1023 endif(NOT HAVE_STRLCPY)
1024 if(NOT HAVE_STRTOK_R)
1025 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/strtok_r.c)
1026 endif(NOT HAVE_STRTOK_R)
1030 # Determine the main pcap-XXX.c file to use, and the libraries with
1031 # which we need to link libpcap, if any.
1037 # Has the user explicitly specified a capture type?
1039 if(PCAP_TYPE STREQUAL "")
1041 # The user didn't explicitly specify a capture mechanism.
1042 # Check whether we have packet.dll.
1046 # We have packet.dll.
1047 # Set the capture type to NPF.
1052 # We don't have any capture type we know about, so just use
1053 # the null capture type, and only support reading (and writing)
1063 # Figure out what type of packet capture mechanism we have, and
1064 # what libraries we'd need to link libpcap with, if any.
1068 # Has the user explicitly specified a capture type?
1070 if(PCAP_TYPE STREQUAL "")
1072 # Check for a bunch of headers for various packet capture mechanisms.
1074 check_include_files("sys/types.h;net/bpf.h" HAVE_NET_BPF_H)
1077 # Does it define BIOCSETIF?
1078 # I.e., is it a header for an LBL/BSD-style capture
1079 # mechanism, or is it just a header for a BPF filter
1080 # engine? Some versions of Arch Linux, for example,
1081 # have a net/bpf.h that doesn't define BIOCSETIF;
1082 # as it's a Linux, it should use packet sockets,
1087 # sys/types.h, because FreeBSD 10's net/bpf.h
1088 # requires that various BSD-style integer types
1091 # sys/time.h, because AIX 5.2 and 5.3's net/bpf.h
1092 # doesn't include it but does use struct timeval
1093 # in ioctl definitions;
1095 # sys/ioctl.h and, if we have it, sys/ioccom.h,
1096 # because net/bpf.h defines ioctls;
1098 # net/if.h, because it defines some structures
1099 # used in ioctls defined by net/bpf.h;
1101 # sys/socket.h, because OpenBSD 5.9's net/bpf.h
1102 # defines some structure fields as being
1105 # and net/bpf.h doesn't necessarily include all
1106 # of those headers itself.
1108 if(HAVE_SYS_IOCCOM_H)
1109 check_symbol_exists(BIOCSETIF "sys/types.h;sys/time.h;sys/ioctl.h;sys/socket.h;sys/ioccom.h;net/bpf.h;net/if.h" BPF_H_DEFINES_BIOCSETIF)
1110 else(HAVE_SYS_IOCCOM_H)
1111 check_symbol_exists(BIOCSETIF "sys/types.h;sys/time.h;sys/ioctl.h;sys/socket.h;net/bpf.h;net/if.h" BPF_H_DEFINES_BIOCSETIF)
1112 endif(HAVE_SYS_IOCCOM_H)
1113 endif(HAVE_NET_BPF_H)
1114 check_include_file(net/pfilt.h HAVE_NET_PFILT_H)
1115 check_include_file(net/enet.h HAVE_NET_ENET_H)
1116 check_include_file(net/nit.h HAVE_NET_NIT_H)
1117 check_include_file(sys/net/nit.h HAVE_SYS_NET_NIT_H)
1118 check_include_file(linux/socket.h HAVE_LINUX_SOCKET_H)
1119 check_include_file(net/raw.h HAVE_NET_RAW_H)
1120 check_include_file(sys/dlpi.h HAVE_SYS_DLPI_H)
1121 check_include_file(config/HaikuConfig.h HAVE_CONFIG_HAIKUCONFIG_H)
1123 if(BPF_H_DEFINES_BIOCSETIF)
1126 # Check this before DLPI, so that we pick BPF on
1127 # Solaris 11 and later.
1130 elseif(HAVE_LINUX_SOCKET_H)
1132 # No prizes for guessing this one.
1134 set(PCAP_TYPE linux)
1135 elseif(HAVE_NET_PFILT_H)
1137 # DEC OSF/1, Digital UNIX, Tru64 UNIX
1140 elseif(HAVE_NET_ENET_H)
1142 # Stanford Enetfilter.
1145 elseif(HAVE_NET_NIT_H)
1147 # SunOS 4.x STREAMS NIT.
1150 elseif(HAVE_SYS_NET_NIT_H)
1152 # Pre-SunOS 4.x non-STREAMS NIT.
1155 elseif(HAVE_NET_RAW_H)
1159 set(PCAP_TYPE snoop)
1160 elseif(HAVE_SYS_DLPI_H)
1162 # DLPI on pre-Solaris 11 SunOS 5, HP-UX, possibly others.
1165 elseif(HAVE_CONFIG_HAIKUCONFIG_H)
1169 set(PCAP_TYPE haiku)
1172 # Nothing we support.
1178 message(STATUS "Packet capture mechanism type: ${PCAP_TYPE}")
1181 # Do capture-mechanism-dependent tests.
1184 if(PCAP_TYPE STREQUAL "npf")
1186 # Link with packet.dll before WinSock2.
1188 set(PCAP_LINK_LIBRARIES ${PACKET_LIBRARIES} ${PCAP_LINK_LIBRARIES})
1189 elseif(PCAP_TYPE STREQUAL "null")
1191 message(FATAL_ERROR "${PCAP_TYPE} is not a valid pcap type")
1194 if(PCAP_TYPE STREQUAL "dlpi")
1196 # Needed for common functions used by pcap-[dlpi,libdlpi].c
1198 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} dlpisubs.c)
1201 # Checks for some header files.
1203 check_include_file(sys/bufmod.h HAVE_SYS_BUFMOD_H)
1204 check_include_file(sys/dlpi_ext.h HAVE_SYS_DLPI_EXT_H)
1207 # Checks to see if Solaris has the public libdlpi(3LIB) library.
1208 # Note: The existence of /usr/include/libdlpi.h does not mean it is the
1209 # public libdlpi(3LIB) version. Before libdlpi was made public, a
1210 # private version also existed, which did not have the same APIs.
1211 # Due to a gcc bug, the default search path for 32-bit libraries does
1212 # not include /lib, we add it explicitly here.
1213 # [http://bugs.opensolaris.org/view_bug.do?bug_id=6619485].
1214 # Also, due to the bug above applications that link to libpcap with
1215 # libdlpi will have to add "-L/lib" option to "configure".
1217 cmake_push_check_state()
1218 set(CMAKE_REQUIRED_FLAGS "-L/lib")
1219 set(CMAKE_REQUIRED_LIBRARIES dlpi)
1220 check_function_exists(dlpi_walk HAVE_LIBDLPI)
1221 cmake_pop_check_state()
1226 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} dlpi)
1227 set(PCAP_TYPE libdlpi)
1231 # This check is for Solaris with DLPI support for passive modes.
1232 # See dlpi(7P) for more details.
1234 # XXX - there's no check_type() macro that's like check_type_size()
1235 # except that it only checks for the existence of the structure type,
1236 # so we use check_type_size() and ignore the size.
1238 cmake_push_check_state()
1239 set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h sys/dlpi.h)
1240 check_type_size(dl_passive_req_t DL_PASSIVE_REQ_T)
1241 cmake_pop_check_state()
1242 elseif(PCAP_TYPE STREQUAL "linux")
1244 # Do we have the wireless extensions?
1245 # linux/wireless.h requires sys/socket.h.
1247 check_include_files("sys/socket.h;linux/wireless.h" HAVE_LINUX_WIRELESS_H)
1252 if(BUILD_WITH_LIBNL)
1254 # Try libnl 3.x first.
1256 cmake_push_check_state()
1257 set(CMAKE_REQUIRED_LIBRARIES nl-3)
1258 check_function_exists(nl_socket_alloc HAVE_LIBNL)
1259 cmake_pop_check_state()
1262 # Yes, we have libnl 3.x.
1264 set(PCAP_LINK_LIBRARIES nl-genl-3 nl-3 ${PCAP_LINK_LIBRARIES})
1265 set(HAVE_LIBNL_3_x ON)
1266 set(HAVE_LIBNL_NLE ON)
1267 set(HAVE_LIBNL_SOCKETS ON)
1268 include_directories("/usr/include/libnl3")
1273 cmake_push_check_state()
1274 set(CMAKE_REQUIRED_LIBRARIES nl)
1275 check_function_exists(nl_socket_alloc HAVE_LIBNL)
1276 cmake_pop_check_state()
1279 # Yes, we have libnl 2.x.
1281 set(PCAP_LINK_LIBRARIES nl-genl nl ${PCAP_LINK_LIBRARIES})
1282 set(HAVE_LIBNL_2_x ON)
1283 set(HAVE_LIBNL_NLE ON)
1284 set(HAVE_LIBNL_SOCKETS ON)
1287 # No, we don't; do we have libnl 1.x?
1289 cmake_push_check_state()
1290 set(CMAKE_REQUIRED_LIBRARIES nl)
1291 check_function_exists(nl_handle_alloc HAVE_LIBNL)
1292 cmake_pop_check_state()
1294 set(PCAP_LINK_LIBRARIES nl ${PCAP_LINK_LIBRARIES})
1300 check_include_file(linux/ethtool.h HAVE_LINUX_ETHTOOL_H)
1303 # Checks to see if tpacket_stats is defined in linux/if_packet.h
1304 # If so then pcap-linux.c can use this to report proper statistics.
1306 # XXX - there's no check_type() macro that's like check_type_size()
1307 # except that it only checks for the existence of the structure type,
1308 # so we use check_type_size() and ignore the size.
1310 cmake_push_check_state()
1311 set(CMAKE_EXTRA_INCLUDE_FILES linux/if_packet.h)
1312 check_type_size("struct tpacket_stats" STRUCT_TPACKET_STATS)
1313 cmake_pop_check_state()
1315 check_struct_has_member("struct tpacket_auxdata" tp_vlan_tci linux/if_packet.h HAVE_STRUCT_TPACKET_AUXDATA_TP_VLAN_TCI)
1316 elseif(PCAP_TYPE STREQUAL "bpf")
1318 # Check whether we have the *BSD-style ioctls.
1320 check_include_files("sys/types.h;net/if_media.h" HAVE_NET_IF_MEDIA_H)
1323 # Check whether we have struct BPF_TIMEVAL.
1325 # XXX - there's no check_type() macro that's like check_type_size()
1326 # except that it only checks for the existence of the structure type,
1327 # so we use check_type_size() and ignore the size.
1329 cmake_push_check_state()
1330 if(HAVE_SYS_IOCCOM_H)
1331 set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h sys/ioccom.h net/bpf.h)
1332 check_type_size("struct BPF_TIMEVAL" STRUCT_BPF_TIMEVAL)
1334 set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h net/bpf.h)
1335 check_type_size("struct BPF_TIMEVAL" STRUCT_BPF_TIMEVAL)
1337 cmake_pop_check_state()
1338 elseif(PCAP_TYPE STREQUAL "haiku")
1340 # Check for some headers just in case.
1342 check_include_files("net/if.h;net/if_dl.h;net/if_types.h" HAVE_NET_IF_TYPES_H)
1343 set(PCAP_SRC pcap-${PCAP_TYPE}.cpp)
1344 elseif(PCAP_TYPE STREQUAL "null")
1346 message(FATAL_ERROR "${PCAP_TYPE} is not a valid pcap type")
1350 if(NOT DEFINED PCAP_SRC)
1351 set(PCAP_SRC pcap-${PCAP_TYPE}.c)
1354 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${PCAP_SRC})
1357 # Now figure out how we get a list of interfaces and addresses,
1358 # if we support capturing. Don't bother if we don't support
1363 # UN*X - figure out what type of interface list mechanism we
1366 # If the capture type is null, that means we can't capture,
1367 # so we can't open any capture devices, so we won't return
1370 if(NOT PCAP_TYPE STREQUAL "null")
1371 cmake_push_check_state()
1372 set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LINK_LIBRARIES})
1373 check_function_exists(getifaddrs HAVE_GETIFADDRS)
1374 cmake_pop_check_state()
1375 if(NOT HAVE_GETIFADDRS)
1377 # It's not in the libraries that, at this point, we've
1378 # found we need to link libpcap with.
1380 # It's in libsocket on Solaris and possibly other OSes;
1381 # as long as we're not linking with libxnet, check there.
1383 # NOTE: if you hand check_library_exists as its last
1384 # argument a variable that's been set, it skips the test,
1385 # so we need different variables.
1387 if(NOT LIBXNET_HAS_GETHOSTBYNAME)
1388 check_library_exists(socket getifaddrs "" SOCKET_HAS_GETIFADDRS)
1389 if(SOCKET_HAS_GETIFADDRS)
1390 set(PCAP_LINK_LIBRARIES socket ${PCAP_LINK_LIBRARIES})
1391 set(HAVE_GETIFADDRS TRUE)
1397 # We have "getifaddrs()"; make sure we have <ifaddrs.h>
1398 # as well, just in case some platform is really weird.
1399 # It may require that sys/types.h be included first,
1400 # so include it first.
1402 check_include_files("sys/types.h;ifaddrs.h" HAVE_IFADDRS_H)
1405 # We have the header, so we use "getifaddrs()" to
1406 # get the list of interfaces.
1408 set(FINDALLDEVS_TYPE getad)
1411 # We don't have the header - give up.
1412 # XXX - we could also fall back on some other
1413 # mechanism, but, for now, this'll catch this
1414 # problem so that we can at least try to figure
1415 # out something to do on systems with "getifaddrs()"
1416 # but without "ifaddrs.h", if there is something
1417 # we can do on those systems.
1419 message(FATAL_ERROR "Your system has getifaddrs() but doesn't have a usable <ifaddrs.h>.")
1423 # Well, we don't have "getifaddrs()", at least not with the
1424 # libraries with which we've decided we need to link
1425 # libpcap with, so we have to use some other mechanism.
1427 # Note that this may happen on Solaris, which has
1428 # getifaddrs(), but in -lsocket, not in -lxnet, so we
1429 # won't find it if we link with -lxnet, which we want
1430 # to do for other reasons.
1432 # For now, we use either the SIOCGIFCONF ioctl or the
1433 # SIOCGLIFCONF ioctl, preferring the latter if we have
1434 # it; the latter is a Solarisism that first appeared
1435 # in Solaris 8. (Solaris's getifaddrs() appears to
1436 # be built atop SIOCGLIFCONF; using it directly
1437 # avoids a not-all-that-useful middleman.)
1439 try_compile(HAVE_SIOCGLIFCONF ${CMAKE_CURRENT_BINARY_DIR} "${pcap_SOURCE_DIR}/cmake/have_siocglifconf.c" )
1440 if(HAVE_SIOCGLIFCONF)
1441 set(FINDALLDEVS_TYPE glifc)
1443 set(FINDALLDEVS_TYPE gifc)
1446 message(STATUS "Find-interfaces mechanism type: ${FINDALLDEVS_TYPE}")
1447 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} fad-${FINDALLDEVS_TYPE}.c)
1451 # Check for hardware timestamp support.
1452 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
1453 check_include_file(linux/net_tstamp.h HAVE_LINUX_NET_TSTAMP_H)
1457 # Check for additional native sniffing capabilities.
1460 # Check for USB sniffing support on Linux.
1461 # On FreeBSD, it uses BPF, so we don't need to do anything special here.
1463 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
1464 set(PCAP_SUPPORT_USB TRUE)
1465 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-usb-linux.c)
1466 set(LINUX_USB_MON_DEV /dev/usbmon)
1468 # Do we have a version of <linux/compiler.h> available?
1469 # If so, we might need it for <linux/usbdevice_fs.h>.
1471 check_include_files("linux/compiler.h" HAVE_LINUX_COMPILER_H)
1472 if(HAVE_LINUX_COMPILER_H)
1474 # Yes - include it when testing for <linux/usbdevice_fs.h>.
1476 check_include_files("linux/compiler.h;linux/usbdevice_fs.h" HAVE_LINUX_USBDEVICE_FS_H)
1477 else(HAVE_LINUX_COMPILER_H)
1478 check_include_files("linux/usbdevice_fs.h" HAVE_LINUX_USBDEVICE_FS_H)
1479 endif(HAVE_LINUX_COMPILER_H)
1480 if(HAVE_LINUX_USBDEVICE_FS_H)
1482 # OK, does it define bRequestType? Older versions of the kernel
1483 # define fields with names like "requesttype, "request", and
1484 # "value", rather than "bRequestType", "bRequest", and
1487 if(HAVE_LINUX_COMPILER_H)
1488 check_struct_has_member("struct usbdevfs_ctrltransfer" bRequestType "linux/compiler.h;linux/usbdevice_fs.h" HAVE_STRUCT_USBDEVFS_CTRLTRANSFER_BREQUESTTYPE)
1489 else(HAVE_LINUX_COMPILER_H)
1490 check_struct_has_member("struct usbdevfs_ctrltransfer" bRequestType "linux/usbdevice_fs.h" HAVE_STRUCT_USBDEVFS_CTRLTRANSFER_BREQUESTTYPE)
1491 endif(HAVE_LINUX_COMPILER_H)
1496 # Check for netfilter sniffing support.
1497 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
1499 # Life's too short to deal with trying to get this to compile
1500 # if you don't get the right types defined with
1501 # __KERNEL_STRICT_NAMES getting defined by some other include.
1503 # Check whether the includes Just Work. If not, don't turn on
1504 # netfilter support.
1506 check_c_source_compiles(
1507 "#include <sys/socket.h>
1508 #include <netinet/in.h>
1509 #include <linux/types.h>
1511 #include <linux/netlink.h>
1512 #include <linux/netfilter.h>
1513 #include <linux/netfilter/nfnetlink.h>
1514 #include <linux/netfilter/nfnetlink_log.h>
1515 #include <linux/netfilter/nfnetlink_queue.h>
1523 PCAP_SUPPORT_NETFILTER)
1524 if(PCAP_SUPPORT_NETFILTER)
1525 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-netfilter-linux.c)
1526 endif(PCAP_SUPPORT_NETFILTER)
1529 # Check for netmap sniffing support.
1530 if(NOT DISABLE_NETMAP)
1532 # Check whether net/netmap_user.h is usable if NETMAP_WITH_LIBS is
1533 # defined; it's not usable on DragonFly BSD 4.6 if NETMAP_WITH_LIBS
1534 # is defined, for example, as it includes a non-existent malloc.h
1537 check_c_source_compiles(
1538 "#define NETMAP_WITH_LIBS
1539 #include <net/netmap_user.h>
1547 PCAP_SUPPORT_NETMAP)
1548 if(PCAP_SUPPORT_NETMAP)
1549 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-netmap.c)
1550 endif(PCAP_SUPPORT_NETMAP)
1553 # Check for DPDK sniffing support
1554 if(NOT DISABLE_DPDK)
1558 # We include rte_bus.h, and older versions of DPDK didn't have
1559 # it, so check for it.
1561 cmake_push_check_state()
1562 set(CMAKE_REQUIRED_INCLUDES ${dpdk_INCLUDE_DIRS})
1563 check_include_file(rte_bus.h HAVE_RTE_BUS_H)
1564 cmake_pop_check_state()
1566 set(DPDK_C_FLAGS "-march=native")
1567 set(DPDK_LIB dpdk rt m numa dl)
1568 set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} ${DPDK_C_FLAGS})
1569 include_directories(AFTER ${dpdk_INCLUDE_DIRS})
1570 link_directories(AFTER ${dpdk_LIBRARIES})
1571 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${dpdk_LIBRARIES})
1572 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-dpdk.c)
1573 set(PCAP_SUPPORT_DPDK TRUE)
1578 # Check for Bluetooth sniffing support
1579 if(NOT DISABLE_BLUETOOTH)
1580 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
1581 check_include_file(bluetooth/bluetooth.h HAVE_BLUETOOTH_BLUETOOTH_H)
1582 if(HAVE_BLUETOOTH_BLUETOOTH_H)
1583 set(PCAP_SUPPORT_BT TRUE)
1584 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-bt-linux.c)
1586 # OK, does struct sockaddr_hci have an hci_channel
1589 check_struct_has_member("struct sockaddr_hci" hci_channel "bluetooth/bluetooth.h;bluetooth/hci.h" HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL)
1590 if(HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL)
1592 # OK, is HCI_CHANNEL_MONITOR defined?
1594 check_c_source_compiles(
1595 "#include <bluetooth/bluetooth.h>
1596 #include <bluetooth/hci.h>
1601 u_int i = HCI_CHANNEL_MONITOR;
1605 PCAP_SUPPORT_BT_MONITOR)
1606 if(PCAP_SUPPORT_BT_MONITOR)
1608 # Yes, so we can also support Bluetooth monitor
1611 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-bt-monitor-linux.c)
1612 endif(PCAP_SUPPORT_BT_MONITOR)
1613 endif(HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL)
1614 endif(HAVE_BLUETOOTH_BLUETOOTH_H)
1618 # Check for Bluetooth sniffing support
1619 if(NOT DISABLE_DBUS)
1621 # We don't support D-Bus sniffing on macOS; see
1623 # https://bugs.freedesktop.org/show_bug.cgi?id=74029
1626 message(FATAL_ERROR "Due to freedesktop.org bug 74029, D-Bus capture support is not available on macOS")
1628 pkg_check_modules(DBUS dbus-1)
1630 set(PCAP_SUPPORT_DBUS TRUE)
1631 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-dbus.c)
1632 include_directories(${DBUS_INCLUDE_DIRS})
1635 # This "helpfully" supplies DBUS_LIBRARIES as a bunch of
1636 # library names - not paths - and DBUS_LIBRARY_DIRS as
1637 # a bunch of directories.
1639 # CMake *really* doesn't like the notion of specifying "here are
1640 # the directories in which to look for libraries" except in
1641 # find_library() calls; it *really* prefers using full paths to
1642 # library files, rather than library names.
1644 # Find the libraries and add their full paths.
1646 set(DBUS_LIBRARY_FULLPATHS)
1647 foreach(_lib IN LISTS DBUS_LIBRARIES)
1649 # Try to find this library, so we get its full path.
1651 find_library(_libfullpath ${_lib} HINTS ${DBUS_LIBRARY_DIRS})
1652 list(APPEND DBUS_LIBRARY_FULLPATHS ${_libfullpath})
1654 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${DBUS_LIBRARY_FULLPATHS})
1656 endif(NOT DISABLE_DBUS)
1658 # Check for RDMA sniffing support
1659 if(NOT DISABLE_RDMA)
1660 check_library_exists(ibverbs ibv_get_device_list "" LIBIBVERBS_HAS_IBV_GET_DEVICE_LIST)
1661 if(LIBIBVERBS_HAS_IBV_GET_DEVICE_LIST)
1662 check_include_file(infiniband/verbs.h HAVE_INFINIBAND_VERBS_H)
1663 if(HAVE_INFINIBAND_VERBS_H)
1664 check_symbol_exists(ibv_create_flow infiniband/verbs.h PCAP_SUPPORT_RDMASNIFF)
1665 if(PCAP_SUPPORT_RDMASNIFF)
1666 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-rdmasniff.c)
1667 set(PCAP_LINK_LIBRARIES ibverbs ${PCAP_LINK_LIBRARIES})
1668 endif(PCAP_SUPPORT_RDMASNIFF)
1669 endif(HAVE_INFINIBAND_VERBS_H)
1670 endif(LIBIBVERBS_HAS_IBV_GET_DEVICE_LIST)
1671 endif(NOT DISABLE_RDMA)
1674 # Check for sniffing capabilities using third-party APIs.
1677 # Check for Endace DAG card support.
1680 # Try to find the DAG header file and library.
1690 # Check for various DAG API functions.
1692 cmake_push_check_state()
1693 set(CMAKE_REQUIRED_INCLUDES ${DAG_INCLUDE_DIRS})
1694 set(CMAKE_REQUIRED_LIBRARIES ${DAG_LIBRARIES})
1695 check_function_exists(dag_attach_stream HAVE_DAG_STREAMS_API)
1696 if(NOT HAVE_DAG_STREAMS_API)
1697 message(FATAL_ERROR "DAG library lacks streams support")
1699 check_function_exists(dag_attach_stream64 HAVE_DAG_LARGE_STREAMS_API)
1700 check_function_exists(dag_get_erf_types HAVE_DAG_GET_ERF_TYPES)
1701 check_function_exists(dag_get_stream_erf_types HAVE_DAG_GET_STREAM_ERF_TYPES)
1702 cmake_pop_check_state()
1704 include_directories(AFTER ${DAG_INCLUDE_DIRS})
1705 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-dag.c)
1706 set(HAVE_DAG_API TRUE)
1707 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${DAG_LIBRARIES})
1709 if(HAVE_DAG_LARGE_STREAMS_API)
1710 get_filename_component(DAG_LIBRARY_DIR ${DAG_LIBRARY} PATH)
1711 check_library_exists(vdag vdag_set_device_info ${DAG_LIBRARY_DIR} HAVE_DAG_VDAG)
1713 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
1719 # Check for Septel card support.
1720 set(PROJECT_EXTERNAL_OBJECT_LIST "")
1721 if(NOT DISABLE_SEPTEL)
1723 # Do we have the msg.h header?
1725 set(SEPTEL_INCLUDE_DIRS "${SEPTEL_ROOT}/INC")
1726 cmake_push_check_state()
1727 set(CMAKE_REQUIRED_INCLUDES ${SEPTEL_INCLUDE_DIRS})
1728 check_include_file(msg.h HAVE_INC_MSG_H)
1729 cmake_pop_check_state()
1734 include_directories(AFTER ${SEPTEL_INCLUDE_DIRS})
1735 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-septel.c)
1736 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")
1737 set(HAVE_SEPTEL_API TRUE)
1741 # Check for Myricom SNF support.
1744 # Try to find the SNF header file and library.
1755 include_directories(AFTER ${SNF_INCLUDE_DIRS})
1756 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-snf.c)
1757 set(HAVE_SNF_API TRUE)
1758 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${SNF_LIBRARIES})
1762 # Check for Riverbed TurboCap support.
1765 # Try to find the TurboCap header file and library.
1776 include_directories(AFTER ${TC_INCLUDE_DIRS})
1777 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-tc.c)
1778 set(HAVE_TC_API TRUE)
1779 set(PCAP_LINK_LIBRARIES "${PCAP_LINK_LIBRARIES} ${TC_LIBRARIES} ${CMAKE_USE_PTHREADS_INIT} stdc++")
1784 # Remote capture support.
1789 # Check for various members of struct msghdr.
1790 # We need to include ftmacros.h on some platforms, to make sure we
1791 # get the POSIX/Single USER Specification version of struct msghdr,
1792 # which has those members, rather than the backwards-compatible
1793 # version, which doesn't. That's not a system header file, and
1794 # at least some versions of CMake include it as <ftmacros.h>, which
1795 # won't check the current directory, so we add the top-level
1796 # source directory to the list of include directories when we do
1799 cmake_push_check_state()
1800 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR})
1801 check_struct_has_member("struct msghdr" msg_control "ftmacros.h;sys/socket.h" HAVE_STRUCT_MSGHDR_MSG_CONTROL)
1802 check_struct_has_member("struct msghdr" msg_flags "ftmacros.h;sys/socket.h" HAVE_STRUCT_MSGHDR_MSG_FLAGS)
1803 cmake_pop_check_state()
1804 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C}
1805 pcap-new.c pcap-rpcap.c rpcap-protocol.c sockutils.c sslutils.c)
1806 endif(ENABLE_REMOTE)
1808 ###################################################################
1810 ###################################################################
1813 # Check and add warning options if we have a .devel file.
1815 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.devel OR EXISTS ${CMAKE_BINARY_DIR}/.devel)
1819 if(MSVC AND NOT ${CMAKE_C_COMPILER} MATCHES "clang*")
1821 # MSVC, with Microsoft's front end and code generator.
1822 # "MSVC" is also set for Microsoft's compiler with a Clang
1823 # front end and their code generator ("Clang/C2"), so we
1824 # check for clang.exe and treat that differently.
1826 check_and_add_compiler_option(-Wall)
1828 # Disable some pointless warnings that /Wall turns on.
1830 # Unfortunately, MSVC does not appear to have an equivalent
1831 # to "__attribute__((unused))" to mark a particular function
1832 # parameter as being known to be unused, so that the compiler
1833 # won't warn about it (for example, the function might have
1834 # that parameter because a pointer to it is being used, and
1835 # the signature of that function includes that parameter).
1836 # C++ lets you give a parameter a type but no name, but C
1837 # doesn't have that.
1839 check_and_add_compiler_option(-wd4100)
1841 # In theory, we care whether somebody uses f() rather than
1842 # f(void) to declare a function with no arguments, but, in
1843 # practice, there are places in the Windows header files
1844 # that appear to do that, so we squelch that warning.
1846 check_and_add_compiler_option(-wd4255)
1848 # Windows FD_SET() generates this, so we suppress it.
1850 check_and_add_compiler_option(-wd4548)
1852 # Perhaps testing something #defined to be 0 with #ifdef is an
1853 # error, and it should be tested with #if, but perhaps it's
1854 # not, and Microsoft does that in its headers, so we squelch
1857 check_and_add_compiler_option(-wd4574)
1859 # The Windows headers also test not-defined values in #if, so
1860 # we don't want warnings about that, either.
1862 check_and_add_compiler_option(-wd4668)
1864 # We do *not* care whether some function is, or isn't, going to be
1867 check_and_add_compiler_option(-wd4710)
1868 check_and_add_compiler_option(-wd4711)
1870 # We do *not* care whether we're adding padding bytes after
1871 # structure members.
1873 check_and_add_compiler_option(-wd4820)
1875 # We do *not* care about every single place the compiler would
1876 # have inserted Spectre mitigation if only we had told it to
1877 # do so with /Qspectre. Maybe it's worth it, as that's in
1878 # Bison-generated code that we don't control.
1880 # XXX - add /Qspectre if that is really worth doing.
1882 check_and_add_compiler_option(-wd5045)
1885 # Other compilers, including MSVC with a Clang front end and
1886 # Microsoft's code generator. We currently treat them as if
1887 # they might support GCC-style -W options.
1889 check_and_add_compiler_option(-Wall)
1890 check_and_add_compiler_option(-Wcomma)
1891 # Warns about safeguards added in case the enums are extended
1892 # check_and_add_compiler_option(-Wcovered-switch-default)
1893 check_and_add_compiler_option(-Wdocumentation)
1894 check_and_add_compiler_option(-Wformat-nonliteral)
1895 check_and_add_compiler_option(-Wmissing-noreturn)
1896 check_and_add_compiler_option(-Wmissing-prototypes)
1897 check_and_add_compiler_option(-Wmissing-variable-declarations)
1898 check_and_add_compiler_option(-Wpointer-arith)
1899 check_and_add_compiler_option(-Wpointer-sign)
1900 check_and_add_compiler_option(-Wshadow)
1901 check_and_add_compiler_option(-Wsign-compare)
1902 check_and_add_compiler_option(-Wshorten-64-to-32)
1903 check_and_add_compiler_option(-Wstrict-prototypes)
1904 check_and_add_compiler_option(-Wunreachable-code)
1905 check_and_add_compiler_option(-Wunused-parameter)
1906 check_and_add_compiler_option(-Wused-but-marked-unused)
1911 # Suppress some warnings we get with MSVC even without /Wall.
1913 if(MSVC AND NOT ${CMAKE_C_COMPILER} MATCHES "clang*")
1915 # Yes, we have some functions that never return but that
1916 # have a non-void return type. That's because, on some
1917 # platforms, they *do* return values but, on other
1918 # platforms, including Windows, they just fail and
1919 # longjmp out by calling bpf_error().
1921 check_and_add_compiler_option(-wd4646)
1924 file(GLOB PROJECT_SOURCE_LIST_H
1930 # Try to have the compiler default to hiding symbols, so that only
1931 # symbols explicitly exported with PCAP_API will be visible outside
1932 # (shared) libraries.
1934 # Not necessary with MSVC, as that's the default.
1936 # XXX - we don't use ADD_COMPILER_EXPORT_FLAGS, because, as of CMake
1937 # 2.8.12.2, it doesn't know about Sun C/Oracle Studio, and, as of
1938 # CMake 2.8.6, it only sets the C++ compiler flags, rather than
1939 # allowing an arbitrary variable to be set with the "hide symbols
1940 # not explicitly exported" flag.
1943 if(CMAKE_C_COMPILER_ID MATCHES "SunPro")
1945 # Sun C/Oracle Studio.
1947 check_and_add_compiler_option(-xldscope=hidden)
1950 # Try this for all other compilers; it's what GCC uses,
1951 # and a number of other compilers, such as Clang and Intel C,
1954 check_and_add_compiler_option(-fvisibility=hidden)
1959 # Flex/Lex and YACC/Berkeley YACC/Bison.
1960 # From a mail message to the CMake mailing list by Andy Cedilnik of
1965 # Try to find Flex, a Windows version of Flex, or Lex.
1967 find_program(LEX_EXECUTABLE NAMES flex win_flex lex)
1968 if(LEX_EXECUTABLE STREQUAL "LEX_EXECUTABLE-NOTFOUND")
1969 message(FATAL_ERROR "Neither flex nor win_flex nor lex was found.")
1971 message(STATUS "Lexical analyzer generator: ${LEX_EXECUTABLE}")
1974 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/scanner.c ${CMAKE_CURRENT_BINARY_DIR}/scanner.h
1975 SOURCE ${pcap_SOURCE_DIR}/scanner.l
1976 COMMAND ${LEX_EXECUTABLE} -P pcap_ --header-file=scanner.h --nounput -o${CMAKE_CURRENT_BINARY_DIR}/scanner.c ${pcap_SOURCE_DIR}/scanner.l
1977 DEPENDS ${pcap_SOURCE_DIR}/scanner.l
1981 # Since scanner.c does not exist yet when cmake is run, mark
1984 # Since scanner.c includes grammar.h, mark that as a dependency.
1986 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/scanner.c PROPERTIES
1988 OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/grammar.h
1992 # Add scanner.c to the list of sources.
1994 #set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${CMAKE_CURRENT_BINARY_DIR}/scanner.c)
1997 # Try to find YACC or Bison.
1999 find_program(YACC_EXECUTABLE NAMES bison win_bison byacc yacc)
2000 if(YACC_EXECUTABLE STREQUAL "YACC_EXECUTABLE-NOTFOUND")
2001 message(FATAL_ERROR "Neither bison nor win_bison nor byacc nor yacc was found.")
2003 message(STATUS "Parser generator: ${YACC_EXECUTABLE}")
2006 # Create custom command for the scanner.
2007 # Find out whether it's Bison or not by looking at the last component
2008 # of the path (without a .exe extension, if this is Windows).
2010 get_filename_component(YACC_NAME ${YACC_EXECUTABLE} NAME_WE)
2011 if("${YACC_NAME}" STREQUAL "bison" OR "${YACC_NAME}" STREQUAL "win_bison")
2012 set(YACC_COMPATIBILITY_FLAG "-y")
2015 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/grammar.c ${CMAKE_CURRENT_BINARY_DIR}/grammar.h
2016 SOURCE ${pcap_SOURCE_DIR}/grammar.y
2017 COMMAND ${YACC_EXECUTABLE} ${YACC_COMPATIBILITY_FLAG} -p pcap_ -o ${CMAKE_CURRENT_BINARY_DIR}/grammar.c -d ${pcap_SOURCE_DIR}/grammar.y
2018 DEPENDS ${pcap_SOURCE_DIR}/grammar.y
2022 # Since grammar.c does not exists yet when cmake is run, mark
2025 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/grammar.c PROPERTIES
2027 OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/scanner.h
2031 # Add grammar.c to the list of sources.
2033 #set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${CMAKE_CURRENT_BINARY_DIR}/grammar.c)
2036 # Assume, by default, no support for shared libraries and V7/BSD
2037 # convention for man pages (devices in section 4, file formats in
2038 # section 5, miscellaneous info in section 7, administrative commands
2039 # and daemons in section 8). Individual cases can override this.
2040 # Individual cases can override this.
2043 set(MAN_FILE_FORMATS 5)
2044 set(MAN_MISC_INFO 7)
2045 set(MAN_ADMIN_COMMANDS 8)
2046 if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
2047 # Workaround to enable certain features
2049 if(PCAP_TYPE STREQUAL "bpf")
2051 # If we're using BPF, we need libodm and libcfg, as
2052 # we use them to load the BPF module.
2054 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} odm cfg)
2056 elseif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
2057 if(CMAKE_SYSTEM_VERSION MATCHES "[A-Z.]*9\.[0-9]*")
2061 set(HAVE_HPUX9 TRUE)
2062 elseif(CMAKE_SYSTEM_VERSION MATCHES "[A-Z.]*10\.0")
2066 elseif(CMAKE_SYSTEM_VERSION MATCHES "[A-Z.]*10\.1")
2072 # HP-UX 10.20 and later.
2074 set(HAVE_HPUX10_20_OR_LATER TRUE)
2078 # Use System V conventions for man pages.
2080 set(MAN_ADMIN_COMMANDS 1m)
2081 set(MAN_FILE_FORMATS 4)
2082 set(MAN_MISC_INFO 5)
2083 elseif(CMAKE_SYSTEM_NAME STREQUAL "IRIX" OR CMAKE_SYSTEM_NAME STREQUAL "IRIX64")
2085 # Use IRIX conventions for man pages; they're the same as the
2086 # System V conventions, except that they use section 8 for
2087 # administrative commands and daemons.
2089 set(MAN_FILE_FORMATS 4)
2090 set(MAN_MISC_INFO 5)
2091 elseif(CMAKE_SYSTEM_NAME STREQUAL "OSF1")
2093 # DEC OSF/1, a/k/a Digial UNIX, a/k/a Tru64 UNIX.
2094 # Use Tru64 UNIX conventions for man pages; they're the same as the
2095 # System V conventions except that they use section 8 for
2096 # administrative commands and daemons.
2098 set(MAN_FILE_FORMATS 4)
2099 set(MAN_MISC_INFO 5)
2101 elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_VERSION MATCHES "5[.][0-9.]*")
2105 set(HAVE_SOLARIS TRUE)
2107 # Make sure errno is thread-safe, in case we're called in
2108 # a multithreaded program. We don't guarantee that two
2109 # threads can use the *same* pcap_t safely, but the
2110 # current version does guarantee that you can use different
2111 # pcap_t's in different threads, and even that pcap_compile()
2112 # is thread-safe (it wasn't thread-safe in some older versions).
2114 add_definitions(-D_TS_ERRNO)
2116 if(CMAKE_SYSTEM_VERSION STREQUAL "5.12")
2119 # Use System V conventions for man pages.
2121 set(MAN_ADMIN_COMMANDS 1m)
2122 set(MAN_FILE_FORMATS 4)
2123 set(MAN_MISC_INFO 5)
2126 elseif(CMAKE_SYSTEM_NAME STREQUAL "Haiku")
2128 # Haiku needs _BSD_SOURCE for the _IO* macros because it doesn't use them.
2130 add_definitions(-D_BSD_SOURCE)
2133 source_group("Source Files" FILES ${PROJECT_SOURCE_LIST_C})
2134 source_group("Header Files" FILES ${PROJECT_SOURCE_LIST_H})
2138 # Add pcap-dll.rc to the list of sources.
2140 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${pcap_SOURCE_DIR}/pcap-dll.rc)
2144 # Add subdirectories after we've set various variables, so they pick up
2145 # pick up those variables.
2148 add_subdirectory(rpcapd)
2149 endif(ENABLE_REMOTE)
2150 add_subdirectory(testprogs)
2152 ######################################
2154 ######################################
2157 # Special target to serialize the building of the generated source.
2161 # http://public.kitware.com/pipermail/cmake/2013-August/055510.html
2163 add_custom_target(SerializeTarget
2165 ${CMAKE_CURRENT_BINARY_DIR}/grammar.c
2166 ${CMAKE_CURRENT_BINARY_DIR}/scanner.c
2169 set_source_files_properties(${PROJECT_EXTERNAL_OBJECT_LIST} PROPERTIES
2170 EXTERNAL_OBJECT TRUE)
2172 if(BUILD_SHARED_LIBS)
2173 add_library(${LIBRARY_NAME} SHARED
2174 ${PROJECT_SOURCE_LIST_C}
2175 ${CMAKE_CURRENT_BINARY_DIR}/grammar.c
2176 ${CMAKE_CURRENT_BINARY_DIR}/scanner.c
2177 ${PROJECT_EXTERNAL_OBJECT_LIST}
2179 add_dependencies(${LIBRARY_NAME} SerializeTarget)
2180 set_target_properties(${LIBRARY_NAME} PROPERTIES
2181 COMPILE_DEFINITIONS BUILDING_PCAP)
2183 # No matter what the library is called - it might be called "wpcap"
2184 # in a Windows build - the symbol to define to indicate that we're
2185 # building the library, rather than a program using the library,
2186 # and thus that we're exporting functions defined in our public
2187 # header files, rather than importing those functions, is
2190 set_target_properties(${LIBRARY_NAME} PROPERTIES
2191 DEFINE_SYMBOL pcap_EXPORTS)
2192 if(NOT "${SANITIZER_FLAGS}" STREQUAL "")
2193 set_target_properties(${LIBRARY_NAME} PROPERTIES
2194 LINK_FLAGS "${SANITIZER_FLAGS}")
2196 endif(BUILD_SHARED_LIBS)
2198 add_library(${LIBRARY_NAME}_static STATIC
2199 ${PROJECT_SOURCE_LIST_C}
2200 ${CMAKE_CURRENT_BINARY_DIR}/grammar.c
2201 ${CMAKE_CURRENT_BINARY_DIR}/scanner.c
2202 ${PROJECT_EXTERNAL_OBJECT_LIST}
2204 add_dependencies(${LIBRARY_NAME}_static SerializeTarget)
2205 set_target_properties(${LIBRARY_NAME}_static PROPERTIES
2206 COMPILE_DEFINITIONS BUILDING_PCAP)
2209 if(BUILD_SHARED_LIBS)
2210 set_target_properties(${LIBRARY_NAME} PROPERTIES
2211 VERSION ${PACKAGE_VERSION_NOSUFFIX} # only MAJOR and MINOR are needed
2213 endif(BUILD_SHARED_LIBS)
2215 # XXX For DLLs, the TARGET_PDB_FILE generator expression can be used to locate
2216 # its PDB file's output directory for installation.
2217 # cmake doesn't offer a generator expression for PDB files generated by the
2218 # compiler (static libraries).
2219 # So instead of considering any possible output there is (there are many),
2220 # this will search for the PDB file in the compiler's initial output directory,
2221 # which is always ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles\wpcap_static.dir
2222 # regardless of architecture, build generator etc.
2223 # Quite hackish indeed.
2224 set(CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY $<TARGET_FILE_DIR:${LIBRARY_NAME}_static>)
2225 set_target_properties(${LIBRARY_NAME}_static PROPERTIES
2226 COMPILE_PDB_NAME ${LIBRARY_NAME}_static
2227 OUTPUT_NAME "${LIBRARY_NAME}_static"
2231 # For compatibility, build the shared library without the "lib" prefix on
2234 set_target_properties(${LIBRARY_NAME} PROPERTIES
2236 OUTPUT_NAME "${LIBRARY_NAME}"
2238 set_target_properties(${LIBRARY_NAME}_static PROPERTIES
2239 OUTPUT_NAME "${LIBRARY_NAME}"
2243 if(BUILD_SHARED_LIBS)
2245 set_target_properties(${LIBRARY_NAME} PROPERTIES
2246 VERSION ${PACKAGE_VERSION}
2250 set_target_properties(${LIBRARY_NAME} PROPERTIES
2251 VERSION ${PACKAGE_VERSION}
2252 SOVERSION ${PACKAGE_VERSION_MAJOR}
2255 endif(BUILD_SHARED_LIBS)
2256 set_target_properties(${LIBRARY_NAME}_static PROPERTIES
2257 OUTPUT_NAME "${LIBRARY_NAME}"
2261 if(BUILD_SHARED_LIBS)
2262 if(NOT C_ADDITIONAL_FLAGS STREQUAL "")
2263 set_target_properties(${LIBRARY_NAME} PROPERTIES COMPILE_FLAGS ${C_ADDITIONAL_FLAGS})
2265 target_link_libraries(${LIBRARY_NAME} ${PCAP_LINK_LIBRARIES})
2266 endif(BUILD_SHARED_LIBS)
2268 if(NOT C_ADDITIONAL_FLAGS STREQUAL "")
2269 set_target_properties(${LIBRARY_NAME}_static PROPERTIES COMPILE_FLAGS ${C_ADDITIONAL_FLAGS})
2273 # On macOS, build libpcap for the appropriate architectures, if
2274 # CMAKE_OSX_ARCHITECTURES isn't set (if it is, let that control
2275 # the architectures for which to build it).
2277 if(APPLE AND "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "")
2279 # Get the major version of Darwin.
2281 string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MAJOR "${CMAKE_SYSTEM_VERSION}")
2283 if(SYSTEM_VERSION_MAJOR LESS 8)
2285 # Pre-Tiger. Build only for 32-bit PowerPC.
2287 set(OSX_LIBRARY_ARCHITECTURES "ppc")
2288 elseif(SYSTEM_VERSION_MAJOR EQUAL 8)
2290 # Tiger. Is this prior to, or with, Intel support?
2292 # Get the minor version of Darwin.
2294 string(REPLACE "${SYSTEM_VERSION_MAJOR}." "" SYSTEM_MINOR_AND_PATCH_VERSION ${CMAKE_SYSTEM_VERSION})
2295 string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MINOR "${SYSTEM_MINOR_AND_PATCH_VERSION}")
2296 if(SYSTEM_VERSION_MINOR LESS 4)
2298 # Prior to Intel support. Build for 32-bit
2299 # PowerPC and 64-bit PowerPC, with 32-bit PowerPC
2300 # first. (I'm guessing that's what Apple does.)
2302 set(OSX_LIBRARY_ARCHITECTURES "ppc;ppc64")
2303 elseif(SYSTEM_VERSION_MINOR LESS 7)
2305 # With Intel support but prior to x86-64 support.
2306 # Build for 32-bit PowerPC, 64-bit PowerPC, and 32-bit x86,
2307 # with 32-bit PowerPC first.
2308 # (I'm guessing that's what Apple does.)
2310 set(OSX_LIBRARY_ARCHITECTURES "ppc;ppc64;i386")
2313 # With Intel support including x86-64 support.
2314 # Build for 32-bit PowerPC, 64-bit PowerPC, 32-bit x86,
2315 # and x86-64, with 32-bit PowerPC first.
2316 # (I'm guessing that's what Apple does.)
2318 set(OSX_LIBRARY_ARCHITECTURES "ppc;ppc64;i386;x86_64")
2320 elseif(SYSTEM_VERSION_MAJOR EQUAL 9)
2322 # Leopard. Build for 32-bit PowerPC, 64-bit
2323 # PowerPC, 32-bit x86, and x86-64, with 32-bit PowerPC
2324 # first. (That's what Apple does.)
2326 set(OSX_LIBRARY_ARCHITECTURES "ppc;ppc64;i386;x86_64")
2327 elseif(SYSTEM_VERSION_MAJOR EQUAL 10)
2329 # Snow Leopard. Build for x86-64, 32-bit x86, and
2330 # 32-bit PowerPC, with x86-64 first. (That's
2331 # what Apple does, even though Snow Leopard
2332 # doesn't run on PPC, so PPC libpcap runs under
2333 # Rosetta, and Rosetta doesn't support BPF
2334 # ioctls, so PPC programs can't do live
2337 set(OSX_LIBRARY_ARCHITECTURES "x86_64;i386;ppc")
2340 # Post-Snow Leopard. Build for x86-64 and 32-bit x86,
2341 # with x86-64 first. (That's what Apple does)
2342 # XXX - update if and when Apple drops support
2343 # for 32-bit x86 code and if and when Apple adds
2344 # ARM-based Macs. (You're on your own for iOS etc.)
2346 # First, check whether we're building with OpenSSL.
2347 # If so, don't bother trying to build fat.
2350 set(X86_32_BIT_SUPPORTED NO)
2351 set(OSX_LIBRARY_ARCHITECTURES "x86_64")
2352 message(WARNING "We're assuming the OpenSSL libraries are 64-bit only, so we're not compiling for 32-bit x86")
2355 # Now, check whether we *can* build for i386.
2357 cmake_push_check_state()
2358 set(CMAKE_REQUIRED_FLAGS "-arch i386")
2359 check_c_source_compiles(
2366 X86_32_BIT_SUPPORTED)
2367 cmake_pop_check_state()
2368 if(X86_32_BIT_SUPPORTED)
2369 set(OSX_LIBRARY_ARCHITECTURES "x86_64;i386")
2371 set(OSX_LIBRARY_ARCHITECTURES "x86_64")
2373 # We can't build fat; suggest that the user install the
2374 # /usr/include headers if they want to build fat.
2376 if(SYSTEM_VERSION_MAJOR LESS 18)
2378 # Pre-Mojave; the command-line tools should be sufficient to
2379 # enable 32-bit x86 builds.
2381 message(WARNING "Compiling for 32-bit x86 gives an error; try installing the command-line tools")
2383 message(WARNING "Compiling for 32-bit x86 gives an error; try installing the command-line tools and, after that, installing the /usr/include headers from the /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg package")
2388 if(BUILD_SHARED_LIBS)
2389 set_target_properties(${LIBRARY_NAME} PROPERTIES
2390 OSX_ARCHITECTURES "${OSX_LIBRARY_ARCHITECTURES}")
2391 endif(BUILD_SHARED_LIBS)
2392 set_target_properties(${LIBRARY_NAME}_static PROPERTIES
2393 OSX_ARCHITECTURES "${OSX_LIBRARY_ARCHITECTURES}")
2396 ######################################
2397 # Write out the config.h file
2398 ######################################
2400 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
2402 ######################################
2403 # Install pcap library, include files, and man pages
2404 ######################################
2407 # "Define GNU standard installation directories", which actually
2408 # are also defined, to some degree, by autotools, and at least
2409 # some of which are general UN*X conventions.
2411 include(GNUInstallDirs)
2413 set(LIBRARY_NAME_STATIC ${LIBRARY_NAME}_static)
2415 function(install_manpage_symlink SOURCE TARGET MANDIR)
2417 find_program(LINK_EXECUTABLE ln)
2419 set(LINK_COMMAND "\"${LINK_EXECUTABLE}\" \"-s\" \"${SOURCE}\" \"${TARGET}\"")
2420 else(LINK_EXECUTABLE)
2421 message(FATAL_ERROR "ln (http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ln.html) not found.")
2422 endif(LINK_EXECUTABLE)
2424 set(LINK_COMMAND "\"${CMAKE_COMMAND}\" \"-E\" \"create_symlink\" \"${SOURCE}\" \"${TARGET}\"")
2428 "message(STATUS \"Symlinking: ${CMAKE_INSTALL_PREFIX}/${MANDIR}/${SOURCE} to ${TARGET}\")
2430 COMMAND \"${CMAKE_COMMAND}\" \"-E\" \"remove\" \"${TARGET}\"
2431 WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${MANDIR}
2434 COMMAND ${LINK_COMMAND}
2435 WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${MANDIR}
2436 RESULT_VARIABLE EXIT_STATUS
2438 if(NOT EXIT_STATUS EQUAL 0)
2439 message(FATAL_ERROR \"Could not create symbolic link from ${CMAKE_INSTALL_PREFIX}/${MANDIR}/${SOURCE} to ${TARGET}\")
2441 set(CMAKE_INSTALL_MANIFEST_FILES \${CMAKE_INSTALL_MANIFEST_FILES} ${CMAKE_INSTALL_PREFIX}/${MANDIR}/${TARGET})")
2442 endfunction(install_manpage_symlink)
2444 set(MAN1_NOEXPAND pcap-config.1)
2447 pcap_compile.3pcap.in
2448 pcap_datalink.3pcap.in
2449 pcap_dump_open.3pcap.in
2450 pcap_get_tstamp_precision.3pcap.in
2451 pcap_list_datalinks.3pcap.in
2452 pcap_list_tstamp_types.3pcap.in
2453 pcap_open_dead.3pcap.in
2454 pcap_open_offline.3pcap.in
2455 pcap_set_immediate_mode.3pcap.in
2456 pcap_set_tstamp_precision.3pcap.in
2457 pcap_set_tstamp_type.3pcap.in
2459 set(MAN3PCAP_NOEXPAND
2461 pcap_breakloop.3pcap
2462 pcap_can_set_rfmon.3pcap
2465 pcap_datalink_name_to_val.3pcap
2466 pcap_datalink_val_to_name.3pcap
2468 pcap_dump_close.3pcap
2469 pcap_dump_file.3pcap
2470 pcap_dump_flush.3pcap
2471 pcap_dump_ftell.3pcap
2474 pcap_findalldevs.3pcap
2476 pcap_get_required_select_timeout.3pcap
2477 pcap_get_selectable_fd.3pcap
2480 pcap_is_swapped.3pcap
2481 pcap_lib_version.3pcap
2482 pcap_lookupdev.3pcap
2483 pcap_lookupnet.3pcap
2485 pcap_major_version.3pcap
2487 pcap_offline_filter.3pcap
2488 pcap_open_live.3pcap
2489 pcap_set_buffer_size.3pcap
2490 pcap_set_datalink.3pcap
2491 pcap_set_promisc.3pcap
2492 pcap_set_protocol_linux.3pcap
2493 pcap_set_rfmon.3pcap
2494 pcap_set_snaplen.3pcap
2495 pcap_set_timeout.3pcap
2496 pcap_setdirection.3pcap
2497 pcap_setfilter.3pcap
2498 pcap_setnonblock.3pcap
2501 pcap_statustostr.3pcap
2503 pcap_tstamp_type_name_to_val.3pcap
2504 pcap_tstamp_type_val_to_name.3pcap
2506 set(MANFILE_EXPAND pcap-savefile.manfile.in)
2508 pcap-filter.manmisc.in
2509 pcap-linktype.manmisc.in
2510 pcap-tstamp.manmisc.in
2513 if(NOT BUILD_SHARED_LIBS)
2515 endif(NOT BUILD_SHARED_LIBS)
2518 if(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8)
2520 # Install 64-bit code built with MSVC in the amd64 subdirectories,
2521 # as that's where it expects it to be.
2523 install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC}
2524 RUNTIME DESTINATION bin/amd64
2525 LIBRARY DESTINATION lib/amd64
2526 ARCHIVE DESTINATION lib/amd64)
2528 install(FILES $<TARGET_FILE_DIR:${LIBRARY_NAME_STATIC}>/${LIBRARY_NAME_STATIC}.pdb
2529 DESTINATION bin/amd64 OPTIONAL)
2530 if(BUILD_SHARED_LIBS)
2531 install(FILES $<TARGET_PDB_FILE:${LIBRARY_NAME}>
2532 DESTINATION bin/amd64 OPTIONAL)
2533 endif(BUILD_SHARED_LIBS)
2535 else(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8)
2537 # Install 32-bit code, and 64-bit code not built with MSVC
2538 # in the top-level directories, as those are where they
2541 install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC}
2542 RUNTIME DESTINATION bin
2543 LIBRARY DESTINATION lib
2544 ARCHIVE DESTINATION lib)
2546 install(FILES $<TARGET_FILE_DIR:${LIBRARY_NAME_STATIC}>/${LIBRARY_NAME_STATIC}.pdb
2547 DESTINATION bin OPTIONAL)
2548 if(BUILD_SHARED_LIBS)
2549 install(FILES $<TARGET_PDB_FILE:${LIBRARY_NAME}>
2550 DESTINATION bin OPTIONAL)
2551 endif(BUILD_SHARED_LIBS)
2553 endif(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8)
2555 install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC} DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR})
2558 install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/pcap/ DESTINATION include/pcap)
2559 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pcap.h DESTINATION include)
2560 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pcap-bpf.h DESTINATION include)
2561 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pcap-namedb.h DESTINATION include)
2563 # On UN*X, and on Windows when not using MSVC, generate libpcap.pc and
2564 # pcap-config and process man pages and arrange that they be installed.
2566 set(PACKAGE_NAME ${LIBRARY_NAME})
2567 set(prefix ${CMAKE_INSTALL_PREFIX})
2568 set(exec_prefix "\${prefix}")
2569 set(includedir "\${prefix}/include")
2570 set(libdir "\${exec_prefix}/lib")
2571 if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR
2572 CMAKE_SYSTEM_NAME STREQUAL "NetBSD" OR
2573 CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR
2574 CMAKE_SYSTEM_NAME STREQUAL "DragonFly BSD" OR
2575 CMAKE_SYSTEM_NAME STREQUAL "Linux" OR
2576 CMAKE_SYSTEM_NAME STREQUAL "OSF1")
2578 # Platforms where the linker is the GNU linker
2579 # or accepts command-line arguments like
2580 # those the GNU linker accepts.
2582 set(V_RPATH_OPT "-Wl,-rpath,")
2583 elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_VERSION MATCHES "5[.][0-9.]*")
2587 # XXX - this assumes GCC is using the Sun linker,
2588 # rather than the GNU linker.
2590 set(V_RPATH_OPT "-Wl,-R,")
2593 # No option needed to set the RPATH.
2598 foreach(LIB ${PCAP_LINK_LIBRARIES})
2599 set(LIBS "${LIBS} -l${LIB}")
2601 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/pcap-config.in ${CMAKE_CURRENT_BINARY_DIR}/pcap-config @ONLY)
2602 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpcap.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libpcap.pc @ONLY)
2603 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/pcap-config DESTINATION bin)
2604 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpcap.pc DESTINATION lib/pkgconfig)
2609 # For each section of the manual for which we have man pages
2610 # that require macro expansion, do the expansion.
2613 foreach(MANPAGE ${MAN1_NOEXPAND})
2614 set(MAN1 ${MAN1} ${CMAKE_CURRENT_SOURCE_DIR}/${MANPAGE})
2616 install(FILES ${MAN1} DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
2619 foreach(MANPAGE ${MAN3PCAP_NOEXPAND})
2620 set(MAN3PCAP ${MAN3PCAP} ${CMAKE_CURRENT_SOURCE_DIR}/${MANPAGE})
2622 foreach(TEMPLATE_MANPAGE ${MAN3PCAP_EXPAND})
2623 string(REPLACE ".in" "" MANPAGE ${TEMPLATE_MANPAGE})
2624 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY)
2625 set(MAN3PCAP ${MAN3PCAP} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE})
2626 endforeach(TEMPLATE_MANPAGE)
2627 install(FILES ${MAN3PCAP} DESTINATION ${CMAKE_INSTALL_MANDIR}/man3)
2628 install_manpage_symlink(pcap_datalink_val_to_name.3pcap pcap_datalink_val_to_description.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2629 install_manpage_symlink(pcap_dump_open.3pcap pcap_dump_fopen.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2630 install_manpage_symlink(pcap_findalldevs.3pcap pcap_freealldevs.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2631 install_manpage_symlink(pcap_geterr.3pcap pcap_perror.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2632 install_manpage_symlink(pcap_inject.3pcap pcap_sendpacket.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2633 install_manpage_symlink(pcap_list_datalinks.3pcap pcap_free_datalinks.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2634 install_manpage_symlink(pcap_list_tstamp_types.3pcap pcap_free_tstamp_types.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2635 install_manpage_symlink(pcap_loop.3pcap pcap_dispatch.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2636 install_manpage_symlink(pcap_major_version.3pcap pcap_minor_version.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2637 install_manpage_symlink(pcap_next_ex.3pcap pcap_next.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2638 install_manpage_symlink(pcap_open_dead.3pcap pcap_open_dead_with_tstamp_precision.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2639 install_manpage_symlink(pcap_open_offline.3pcap pcap_open_offline_with_tstamp_precision.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2640 install_manpage_symlink(pcap_open_offline.3pcap pcap_fopen_offline.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2641 install_manpage_symlink(pcap_open_offline.3pcap pcap_fopen_offline_with_tstamp_precision.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2642 install_manpage_symlink(pcap_tstamp_type_val_to_name.3pcap pcap_tstamp_type_val_to_description.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2643 install_manpage_symlink(pcap_setnonblock.3pcap pcap_getnonblock.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2646 foreach(TEMPLATE_MANPAGE ${MANFILE_EXPAND})
2647 string(REPLACE ".manfile.in" ".${MAN_FILE_FORMATS}" MANPAGE ${TEMPLATE_MANPAGE})
2648 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY)
2649 set(MANFILE ${MANFILE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE})
2650 endforeach(TEMPLATE_MANPAGE)
2651 install(FILES ${MANFILE} DESTINATION ${CMAKE_INSTALL_MANDIR}/man${MAN_FILE_FORMATS})
2654 foreach(TEMPLATE_MANPAGE ${MANMISC_EXPAND})
2655 string(REPLACE ".manmisc.in" ".${MAN_MISC_INFO}" MANPAGE ${TEMPLATE_MANPAGE})
2656 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY)
2657 set(MANMISC ${MANMISC} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE})
2658 endforeach(TEMPLATE_MANPAGE)
2659 install(FILES ${MANMISC} DESTINATION ${CMAKE_INSTALL_MANDIR}/man${MAN_MISC_INFO})
2664 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
2665 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
2668 add_custom_target(uninstall
2669 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)