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)
17 # Try to enable as many C99 features as we can.
18 # At minimum, we want C++/C99-style // comments.
20 # Newer versions of compilers might default to supporting C99, but older
21 # versions may require a special flag.
23 # Prior to CMake 3.1, setting CMAKE_C_STANDARD will not have any effect,
24 # so, unless and until we require CMake 3.1 or later, we have to do it
25 # ourselves on pre-3.1 CMake, so we just do it ourselves on all versions
28 # Note: with CMake 3.1 through 3.5, the only compilers for which CMake
29 # handles CMAKE_C_STANDARD are GCC and Clang. 3.6 adds support only
30 # for Intel C; 3.9 adds support for PGI C, Sun C, and IBM XL C, and
31 # 3.10 adds support for Cray C and IAR C, but no version of CMake has
32 # support for HP C. Therefore, even if we use CMAKE_C_STANDARD with
33 # compilers for which CMake supports it, we may still have to do it
34 # ourselves on other compilers.
36 # See the CMake documentation for the CMAKE_<LANG>_COMPILER_ID variables
37 # for a list of compiler IDs.
39 # We don't worry about MSVC; it doesn't have such a flag - either it
40 # doesn't support the C99 features we need at all, or it supports them
41 # regardless of the compiler flag.
43 # XXX - this just tests whether the option works and adds it if it does.
44 # We don't test whether it's necessary in order to get the C99 features
45 # that we use; if we ever have a user who tries to compile with a compiler
46 # that can't be made to support those features, we can add a test to make
47 # sure we actually *have* C99 support.
49 include(CheckCCompilerFlag)
50 macro(check_and_add_compiler_option _option)
51 message(STATUS "Checking C compiler flag ${_option}")
52 string(REPLACE "=" "-" _temp_option_variable ${_option})
53 string(REGEX REPLACE "^-" "" _option_variable ${_temp_option_variable})
54 check_c_compiler_flag("${_option}" ${_option_variable})
55 if(${${_option_variable}})
56 set(C_ADDITIONAL_FLAGS "${C_ADDITIONAL_FLAGS} ${_option}")
60 set(C_ADDITIONAL_FLAGS "")
61 if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR
62 CMAKE_C_COMPILER_ID MATCHES "Clang")
63 check_and_add_compiler_option("-std=gnu99")
64 elseif(CMAKE_C_COMPILER_ID MATCHES "XL")
66 # We want support for extensions picked up for GNU C compatibility,
67 # so we use -qlanglvl=extc99.
69 check_and_add_compiler_option("-qlanglvl=extc99")
70 elseif(CMAKE_C_COMPILER_ID MATCHES "HP")
71 check_and_add_compiler_option("-AC99")
72 elseif(CMAKE_C_COMPILER_ID MATCHES "Sun")
73 check_and_add_compiler_option("-xc99")
74 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
75 check_and_add_compiler_option("-c99")
79 # Build all runtimes in the top-level binary directory; that way,
80 # on Windows, the executables will be in the same directory as
81 # the DLLs, so the system will find pcap.dll when any of the
82 # executables are run.
84 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run)
86 ###################################################################
88 ###################################################################
92 # On Windows, allow the library name to be overridden, for the
93 # benefit of projects that combine libpcap with their own
94 # kernel-mode code to support capturing.
96 set(LIBRARY_NAME pcap CACHE STRING "Library name")
99 # On UN*X, it's always been libpcap.
101 set(LIBRARY_NAME pcap)
104 option(INET6 "Enable IPv6" ON)
106 option(USE_STATIC_RT "Use static Runtime" ON)
108 option(BUILD_SHARED_LIBS "Build shared libraries" ON)
110 set(PACKET_DLL_DIR "" CACHE PATH "Path to directory with include and lib subdirectories for packet.dll")
113 # To pacify those who hate the protochain instruction
114 option(NO_PROTOCHAIN "Disable protochain instruction" OFF)
117 # Start out with the capture mechanism type unspecified; the user
118 # can explicitly specify it and, if they don't, we'll pick an
121 set(PCAP_TYPE "" CACHE STRING "Packet capture type")
124 # Default to having remote capture support on Windows and, for now, to
125 # not having it on UN*X.
128 option(ENABLE_REMOTE "Enable remote capture" ON)
130 option(ENABLE_REMOTE "Enable remote capture" OFF)
133 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
134 option(PCAP_SUPPORT_PACKET_RING "Enable Linux packet ring support" ON)
135 option(BUILD_WITH_LIBNL "Build with libnl" ON)
139 # By default, build universal with the appropriate set of architectures
140 # for the OS on which we're doing the build.
142 if(APPLE AND "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "")
144 # Get the major version of Darwin.
146 string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MAJOR "${CMAKE_SYSTEM_VERSION}")
148 if(SYSTEM_VERSION_MAJOR LESS 8)
150 # Pre-Tiger. Build only for 32-bit PowerPC.
152 set(CMAKE_OSX_ARCHITECTURES "ppc")
153 elseif(SYSTEM_VERSION_MAJOR EQUAL 8)
155 # Tiger. Is this prior to, or with, Intel support?
157 # Get the minor version of Darwin.
159 string(REPLACE "${SYSTEM_VERSION_MAJOR}." "" SYSTEM_MINOR_AND_PATCH_VERSION ${CMAKE_SYSTEM_VERSION})
160 string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MINOR "${SYSTEM_MINOR_AND_PATCH_VERSION}")
161 if(SYSTEM_VERSION_MINOR LESS 4)
163 # Prior to Intel support. Build for 32-bit
164 # PowerPC and 64-bit PowerPC, with 32-bit PowerPC
165 # first. (I'm guessing that's what Apple does.)
167 set(CMAKE_OSX_ARCHITECTURES "ppc;ppc64")
168 elseif(SYSTEM_VERSION_MINOR LESS 7)
170 # With Intel support but prior to x86-64 support.
171 # Build for 32-bit PowerPC, 64-bit PowerPC, and x86,
172 # with 32-bit PowerPC first.
173 # (I'm guessing that's what Apple does.)
175 set(CMAKE_OSX_ARCHITECTURES "ppc;ppc64;i386")
178 # With Intel support including x86-64 support.
179 # Build for 32-bit PowerPC, 64-bit PowerPC, x86,
180 # and x86-64, with 32-bit PowerPC first.
181 # (I'm guessing that's what Apple does.)
183 set(CMAKE_OSX_ARCHITECTURES "ppc;ppc64;i386;x86_64")
185 elseif(SYSTEM_VERSION_MAJOR EQUAL 9)
187 # Leopard. Build for 32-bit PowerPC, 64-bit
188 # PowerPC, x86, and x86-64, with 32-bit PowerPC
189 # first. (That's what Apple does.)
191 set(CMAKE_OSX_ARCHITECTURES "ppc;ppc64;i386;x86_64")
192 elseif(SYSTEM_VERSION_MAJOR EQUAL 10)
194 # Snow Leopard. Build for x86-64, x86, and
195 # 32-bit PowerPC, with x86-64 first. (That's
196 # what Apple does, even though Snow Leopard
197 # doesn't run on PPC, so PPC libpcap runs under
198 # Rosetta, and Rosetta doesn't support BPF
199 # ioctls, so PPC programs can't do live
202 set(CMAKE_OSX_ARCHITECTURES "x86_64;i386;ppc")
205 # Post-Snow Leopard. Build for x86-64 and
206 # x86, with x86-64 first. (That's probably what
207 # Apple does, given that Rosetta is gone.)
208 # XXX - update if and when Apple drops support
209 # for 32-bit x86 code.
211 set(CMAKE_OSX_ARCHITECTURES "x86_64;i386")
216 # Additional capture modules.
218 option(DISABLE_USB "Disable USB sniffing support" OFF)
219 option(DISABLE_BLUETOOTH "Disable Bluetooth sniffing support" OFF)
220 option(DISABLE_NETMAP "Disable netmap support" OFF)
222 # We don't support D-Bus sniffing on macOS; see
224 # https://bugs.freedesktop.org/show_bug.cgi?id=74029
227 option(DISABLE_DBUS "Disable D-Bus sniffing support" ON)
229 option(DISABLE_DBUS "Disable D-Bus sniffing support" OFF)
231 option(DISABLE_RDMA "Disable RDMA sniffing support" OFF)
233 option(DISABLE_DAG "Disable Endace DAG card support" OFF)
235 option(DISABLE_SEPTEL "Disable Septel card support" OFF)
236 set(SEPTEL_ROOT "${CMAKE_SOURCE_DIR}/../septel" CACHE PATH "Path to directory with include and lib subdirectories for Septel API")
238 option(DISABLE_SNF "Disable Myricom SNF support" OFF)
240 option(DISABLE_TC "Disable Riverbed TurboCap support" OFF)
245 option(BDEBUG "Build optimizer debugging code" OFF)
246 option(YYDEBUG "Build parser debugging code" OFF)
248 ###################################################################
250 ###################################################################
252 # Get, parse, format and set pcap's version string from [pcap_root]/VERSION
255 # Get MAJOR, MINOR, PATCH & SUFFIX
256 file(STRINGS ${pcap_SOURCE_DIR}/VERSION
258 LIMIT_COUNT 1 # Read only the first line
262 string(REGEX MATCH "^([0-9]+)" PACKAGE_VERSION_MAJOR "${PACKAGE_VERSION}")
264 # Get MAJOR, MINOR & PATCH
265 string(REGEX MATCH "^([0-9]+.)?([0-9]+.)?([0-9]+)" PACKAGE_VERSION_NOSUFFIX "${PACKAGE_VERSION}")
268 # Convert PCAP_VERSION_NOSUFFIX to Windows preferred version format
269 string(REPLACE "." "," PACKAGE_VERSION_PREDLL ${PACKAGE_VERSION_NOSUFFIX})
271 # Append NANO (used for Windows internal versioning) to PCAP_VERSION_PREDLL
273 set(PACKAGE_VERSION_DLL ${PACKAGE_VERSION_PREDLL},0)
276 set(PACKAGE_NAME "${LIBRARY_NAME}")
277 set(PACKAGE_STRING "${LIBRARY_NAME} ${PACKAGE_VERSION}")
279 ######################################
281 ######################################
283 add_definitions(-DHAVE_CONFIG_H)
286 ${CMAKE_CURRENT_BINARY_DIR}
290 include(CheckFunctionExists)
291 include(CMakePushCheckState)
295 if(IS_DIRECTORY ${CMAKE_HOME_DIRECTORY}/../../Common)
296 include_directories(${CMAKE_HOME_DIRECTORY}/../../Common)
297 endif(IS_DIRECTORY ${CMAKE_HOME_DIRECTORY}/../../Common)
301 set(HAVE_PACKET32 TRUE)
302 include_directories(${PACKET_INCLUDE_DIRS})
304 # Check whether we have the NPcap PacketIsLoopbackAdapter()
307 cmake_push_check_state()
308 set(CMAKE_REQUIRED_LIBRARIES ${PACKET_LIBRARIES})
309 check_function_exists(PacketIsLoopbackAdapter HAVE_PACKET_IS_LOOPBACK_ADAPTER)
310 cmake_pop_check_state()
316 add_definitions(-D__STDC__)
317 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
321 message(STATUS "Use STATIC runtime")
324 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
325 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
326 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
327 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
328 string(REGEX REPLACE "/MD" "/MT" ${RT_FLAG} "${${RT_FLAG}}")
331 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc")
334 message(STATUS "Use DYNAMIC runtime")
337 ###################################################################
338 # Detect available platform features
339 ###################################################################
341 include(CheckIncludeFile)
342 include(CheckIncludeFiles)
343 include(CheckStructHasMember)
344 include(CheckTypeSize)
349 check_include_file(inttypes.h HAVE_INTTYPES_H)
350 check_include_file(stdint.h HAVE_STDINT_H)
351 check_include_file(unistd.h HAVE_UNISTD_H)
352 if(NOT HAVE_UNISTD_H)
353 add_definitions(-DYY_NO_UNISTD_H)
354 endif(NOT HAVE_UNISTD_H)
355 check_include_file(bitypes.h HAVE_SYS_BITYPES_H)
357 check_include_file(sys/ioccom.h HAVE_SYS_IOCCOM_H)
358 check_include_file(sys/sockio.h HAVE_SYS_SOCKIO_H)
359 check_include_file(sys/select.h HAVE_SYS_SELECT_H)
361 check_include_file(limits.h HAVE_LIMITS_H)
363 check_include_file(netpacket/packet.h HAVE_NETPACKET_PACKET_H)
364 check_include_files("sys/types.h;sys/socket.h;net/if.h;net/pfvar.h" HAVE_NET_PFVAR_H)
367 # Check for various PF actions.
369 check_c_source_compiles(
370 "#include <sys/types.h>
371 #include <sys/socket.h>
373 #include <net/pfvar.h>
378 return PF_NAT+PF_NONAT+PF_BINAT+PF_NOBINAT+PF_RDR+PF_NORDR;
381 HAVE_PF_NAT_THROUGH_PF_NORDR)
382 endif(HAVE_NET_PFVAR_H)
383 check_include_file(netinet/if_ether.h HAVE_NETINET_IF_ETHER_H)
384 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
385 check_include_file(linux/sockios.h HAVE_LINUX_SOCKIOS_H)
387 # linux/if_bonding.h requires sys/socket.h.
389 check_include_files("sys/socket.h;linux/if_bonding.h" HAVE_LINUX_IF_BONDING_H)
396 check_function_exists(strerror HAVE_STRERROR)
397 check_function_exists(strerror_r HAVE_STRERROR_R)
398 check_function_exists(strerror_s HAVE_STRERROR_S)
399 check_function_exists(strlcpy HAVE_STRLCPY)
400 check_function_exists(strlcat HAVE_STRLCAT)
401 check_function_exists(snprintf HAVE_SNPRINTF)
402 check_function_exists(vsnprintf HAVE_VSNPRINTF)
403 check_function_exists(strtok_r HAVE_STRTOK_R)
406 # These tests are for network applications that need socket functions
407 # and getaddrinfo()/getnameinfo()-ish functions. We now require
408 # getaddrinfo() and getnameinfo(). On UN*X systems, we also prefer
409 # versions of recvmsg() that conform to the Single UNIX Specification,
410 # so that we can check whether a datagram received with recvmsg() was
411 # truncated when received due to the buffer being too small.
413 # On Windows, getaddrinfo() is in the ws2_32 library.
415 # On most UN*X systems, they're available in the system library.
417 # Under Solaris, we need to link with libsocket and libnsl to get
418 # getaddrinfo() and getnameinfo() and, if we have libxnet, we need to
419 # link with libxnet before libsocket to get a version of recvmsg()
420 # that conforms to the Single UNIX Specification.
422 # We use getaddrinfo() because we want a portable thread-safe way
423 # of getting information for a host name or port; there exist _r
424 # versions of gethostbyname() and getservbyname() on some platforms,
425 # but not on all platforms.
427 # NOTE: if you hand check_library_exists as its last argument a variable
428 # that's been set, it skips the test, so we need different variables.
430 set(PCAP_LINK_LIBRARIES "")
431 include(CheckLibraryExists)
432 include(CheckSymbolExists)
435 # We need winsock2.h and ws2tcpip.h.
437 cmake_push_check_state()
438 set(CMAKE_REQUIRED_LIBRARIES ws2_32)
439 check_symbol_exists(getaddrinfo "winsock2.h;ws2tcpip.h" LIBWS2_32_HAS_GETADDRINFO)
440 cmake_pop_check_state()
441 if(LIBWS2_32_HAS_GETADDRINFO)
442 set(PCAP_LINK_LIBRARIES ws2_32 ${PCAP_LINK_LIBRARIES})
443 else(LIBWS2_32_HAS_GETADDRINFO)
444 message(FATAL_ERROR "getaddrinfo is required, but wasn't found")
445 endif(LIBWS2_32_HAS_GETADDRINFO)
448 # UN*X. First try the system libraries, then try the libraries
449 # for Solaris and possibly other systems that picked up the
450 # System V library split.
452 check_function_exists(getaddrinfo STDLIBS_HAVE_GETADDRINFO)
453 if(NOT STDLIBS_HAVE_GETADDRINFO)
455 # Not found in the standard system libraries.
456 # Try libsocket, which requires libnsl.
458 cmake_push_check_state()
459 set(CMAKE_REQUIRED_LIBRARIES nsl)
460 check_library_exists(socket getaddrinfo "" LIBSOCKET_HAS_GETADDRINFO)
461 cmake_pop_check_state()
462 if(LIBSOCKET_HAS_GETADDRINFO)
464 # OK, we found it in libsocket.
466 set(PCAP_LINK_LIBRARIES socket nsl ${PCAP_LINK_LIBRARIES})
467 else(LIBSOCKET_HAS_GETADDRINFO)
471 message(FATAL_ERROR "getaddrinfo is required, but wasn't found")
472 endif(LIBSOCKET_HAS_GETADDRINFO)
475 # OK, do we have recvmsg() in libxnet?
476 # We also link with libsocket and libnsl.
478 cmake_push_check_state()
479 set(CMAKE_REQUIRED_LIBRARIES socket nsl)
480 check_library_exists(xnet recvmsg "" LIBXNET_HAS_RECVMSG)
481 cmake_pop_check_state()
482 if(LIBXNET_HAS_RECVMSG)
484 # Yes - link with it as well.
486 set(PCAP_LINK_LIBRARIES xnet ${PCAP_LINK_LIBRARIES})
487 endif(LIBXNET_HAS_RECVMSG)
488 endif(NOT STDLIBS_HAVE_GETADDRINFO)
490 # DLPI needs putmsg under HPUX so test for -lstr while we're at it
491 check_function_exists(putmsg STDLIBS_HAVE_PUTMSG)
492 if(NOT STDLIBS_HAVE_PUTMSG)
493 check_library_exists(str putmsg "" LIBSTR_HAS_PUTMSG)
494 if(LIBSTR_HAS_PUTMSG)
495 set(PCAP_LINK_LIBRARIES str ${PCAP_LINK_LIBRARIES})
496 endif(LIBSTR_HAS_PUTMSG)
497 endif(NOT STDLIBS_HAVE_PUTMSG)
501 # Check for reentrant versions of getnetbyname_r(), as provided by
502 # Linux (glibc), Solaris/IRIX, and AIX (with three different APIs!).
503 # If we don't find one, we just use getnetbyname(), which uses
504 # thread-specific data on many platforms, but doesn't use it on
505 # NetBSD or OpenBSD, and may not use it on older versions of other
508 # Only do the check if we have a declaration of getnetbyname_r();
509 # without it, we can't check which API it has. (We assume that
510 # if there's a declaration, it has a prototype, so that the API
513 cmake_push_check_state()
514 set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LINK_LIBRARIES})
515 check_symbol_exists(getnetbyname_r netdb.h NETDB_H_DECLARES_GETNETBYNAME_R)
516 if(NETDB_H_DECLARES_GETNETBYNAME_R)
517 check_c_source_compiles(
523 struct netent netent_buf;
525 struct netent *resultp;
528 return getnetbyname_r((const char *)0, &netent_buf, buf, sizeof buf, &resultp, &h_errnoval);
531 HAVE_LINUX_GETNETBYNAME_R)
532 if(NOT HAVE_LINUX_GETNETBYNAME_R)
533 check_c_source_compiles(
539 struct netent netent_buf;
542 return getnetbyname_r((const char *)0, &netent_buf, buf, (int)sizeof buf) != NULL;
545 HAVE_SOLARIS_IRIX_GETNETBYNAME_R)
546 if(NOT HAVE_SOLARIS_IRIX_GETNETBYNAME_R)
547 check_c_source_compiles(
553 struct netent netent_buf;
554 struct netent_data net_data;
556 return getnetbyname_r((const char *)0, &netent_buf, &net_data);
559 HAVE_AIX_GETNETBYNAME_R)
560 endif(NOT HAVE_SOLARIS_IRIX_GETNETBYNAME_R)
561 endif(NOT HAVE_LINUX_GETNETBYNAME_R)
562 endif(NETDB_H_DECLARES_GETNETBYNAME_R)
563 cmake_pop_check_state()
566 # Check for reentrant versions of getprotobyname_r(), as provided by
567 # Linux (glibc), Solaris/IRIX, and AIX (with three different APIs!).
568 # If we don't find one, we just use getprotobyname(), which uses
569 # thread-specific data on many platforms, but doesn't use it on
570 # NetBSD or OpenBSD, and may not use it on older versions of other
573 # Only do the check if we have a declaration of getprotobyname_r();
574 # without it, we can't check which API it has. (We assume that
575 # if there's a declaration, it has a prototype, so that the API
578 cmake_push_check_state()
579 set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LINK_LIBRARIES})
580 check_symbol_exists(getprotobyname_r netdb.h NETDB_H_DECLARES_GETPROTOBYNAME_R)
581 if(NETDB_H_DECLARES_GETPROTOBYNAME_R)
582 check_c_source_compiles(
588 struct protoent protoent_buf;
590 struct protoent *resultp;
592 return getprotobyname_r((const char *)0, &protoent_buf, buf, sizeof buf, &resultp);
595 HAVE_LINUX_GETPROTOBYNAME_R)
596 if(NOT HAVE_LINUX_GETPROTOBYNAME_R)
597 check_c_source_compiles(
603 struct protoent protoent_buf;
606 return getprotobyname_r((const char *)0, &protoent_buf, buf, (int)sizeof buf) != NULL;
609 HAVE_SOLARIS_IRIX_GETPROTOBYNAME_R)
610 if(NOT HAVE_SOLARIS_IRIX_GETPROTOBYNAME_R)
611 check_c_source_compiles(
617 struct protoent protoent_buf;
618 struct protoent_data proto_data;
620 return getprotobyname_r((const char *)0, &protoent_buf, &proto_data);
623 HAVE_AIX_GETPROTOBYNAME_R)
624 endif(NOT HAVE_SOLARIS_IRIX_GETPROTOBYNAME_R)
625 endif(NOT HAVE_LINUX_GETPROTOBYNAME_R)
626 endif(NETDB_H_DECLARES_GETPROTOBYNAME_R)
627 cmake_pop_check_state()
632 # XXX - there's no check_type() macro that's like check_type_size()
633 # except that it only checks for the existence of the structure type,
634 # so we use check_type_size() and ignore the size.
636 cmake_push_check_state()
638 set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h)
640 set(CMAKE_EXTRA_INCLUDE_FILES unistd.h sys/socket.h)
642 check_type_size("struct sockaddr_storage" STRUCT_SOCKADDR_STORAGE)
643 check_type_size("socklen_t" SOCKLEN_T)
644 cmake_pop_check_state()
650 check_struct_has_member("struct sockaddr" sa_len winsock2.h HAVE_STRUCT_SOCKADDR_SA_LEN)
652 check_struct_has_member("struct sockaddr" sa_len sys/socket.h HAVE_STRUCT_SOCKADDR_SA_LEN)
656 # Do we have ffs(), and is it declared in <strings.h>?
658 check_function_exists(ffs HAVE_FFS)
661 # OK, we have ffs(). Is it declared in <strings.h>?
663 # This test fails if we don't have <strings.h> or if we do
664 # but it doesn't declare ffs().
666 check_symbol_exists(ffs strings.h STRINGS_H_DECLARES_FFS)
670 # This requires the libraries that we require, as ether_hostton might be
671 # in one of those libraries. That means we have to do this after
672 # we check for those libraries.
674 # You are in a twisty little maze of UN*Xes, all different.
675 # Some might not have ether_hostton().
676 # Some might have it and declare it in <net/ethernet.h>.
677 # Some might have it and declare it in <netinet/ether.h>
678 # Some might have it and declare it in <sys/ethernet.h>.
679 # Some might have it and declare it in <arpa/inet.h>.
680 # Some might have it and declare it in <netinet/if_ether.h>.
681 # Some might have it and not declare it in any header file.
683 # Before you is a C compiler.
685 cmake_push_check_state()
686 set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LINK_LIBRARIES})
687 check_function_exists(ether_hostton HAVE_ETHER_HOSTTON)
688 if(HAVE_ETHER_HOSTTON)
690 # OK, we have ether_hostton(). Is it declared in <net/ethernet.h>?
692 # This test fails if we don't have <net/ethernet.h> or if we do
693 # but it doesn't declare ether_hostton().
695 check_symbol_exists(ether_hostton net/ethernet.h NET_ETHERNET_H_DECLARES_ETHER_HOSTTON)
696 if(NET_ETHERNET_H_DECLARES_ETHER_HOSTTON)
698 # Yes - we have it declared.
700 set(HAVE_DECL_ETHER_HOSTTON TRUE)
705 if(NOT HAVE_DECL_ETHER_HOSTTON)
707 # No - how about <netinet/ether.h>, as on Linux?
709 # This test fails if we don't have <netinet/ether.h>
710 # or if we do but it doesn't declare ether_hostton().
712 check_symbol_exists(ether_hostton netinet/ether.h NETINET_ETHER_H_DECLARES_ETHER_HOSTTON)
713 if(NETINET_ETHER_H_DECLARES_ETHER_HOSTTON)
715 # Yes - we have it declared.
717 set(HAVE_DECL_ETHER_HOSTTON TRUE)
723 if(NOT HAVE_DECL_ETHER_HOSTTON)
725 # No - how about <sys/ethernet.h>, as on Solaris 10 and later?
727 # This test fails if we don't have <sys/ethernet.h>
728 # or if we do but it doesn't declare ether_hostton().
730 check_symbol_exists(ether_hostton sys/ethernet.h SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON)
731 if(SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON)
733 # Yes - we have it declared.
735 set(HAVE_DECL_ETHER_HOSTTON TRUE)
741 if(NOT HAVE_DECL_ETHER_HOSTTON)
743 # No, how about <arpa/inet.h>, as on AIX?
745 # This test fails if we don't have <arpa/inet.h>
746 # or if we do but it doesn't declare ether_hostton().
748 check_symbol_exists(ether_hostton arpa/inet.h ARPA_INET_H_DECLARES_ETHER_HOSTTON)
749 if(ARPA_INET_H_DECLARES_ETHER_HOSTTON)
751 # Yes - we have it declared.
753 set(HAVE_DECL_ETHER_HOSTTON TRUE)
759 if(NOT HAVE_DECL_ETHER_HOSTTON)
761 # No, how about <netinet/if_ether.h>?
762 # On some platforms, it requires <net/if.h> and
763 # <netinet/in.h>, and we always include it with
764 # both of them, so test it with both of them.
766 # This test fails if we don't have <netinet/if_ether.h>
767 # and the headers we include before it, or if we do but
768 # <netinet/if_ether.h> doesn't declare ether_hostton().
770 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)
771 if(NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON)
773 # Yes - we have it declared.
775 set(HAVE_DECL_ETHER_HOSTTON TRUE)
779 # After all that, is ether_hostton() declared?
781 if(NOT HAVE_DECL_ETHER_HOSTTON)
783 # No, we'll have to declare it ourselves.
784 # Do we have "struct ether_addr" if we include <netinet/if_ether.h>?
786 # XXX - there's no check_type() macro that's like check_type_size()
787 # except that it only checks for the existence of the structure type,
788 # so we use check_type_size() and ignore the size.
790 cmake_push_check_state()
791 set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h sys/socket.h net/if.h netinet/in.h netinet/if_ether.h)
792 check_type_size("struct ether_addr" STRUCT_ETHER_ADDR)
793 cmake_pop_check_state()
796 cmake_pop_check_state()
799 # Large file support on UN*X, a/k/a LFS.
805 # Add the required #defines.
807 add_definitions(${LFS_DEFINITIONS})
811 # Check for fseeko as well.
818 # Add the required #defines.
820 add_definitions(${FSEEKO_DEFINITIONS})
825 message(STATUS "Support IPv6")
830 # We might need them, because some libraries we use might use them,
831 # but we don't necessarily need them.
832 # That's only on UN*X; on Windows, if they use threads, we assume
833 # they're native Windows threads.
836 set(CMAKE_THREAD_PREFER_PTHREAD ON)
837 find_package(Threads)
838 if(NOT CMAKE_USE_PTHREADS_INIT)
840 # If it's not pthreads, we won't use it; we use it for libraries
843 set(CMAKE_THREAD_LIBS_INIT "")
844 endif(NOT CMAKE_USE_PTHREADS_INIT)
847 ######################################
849 ######################################
851 set(PROJECT_SOURCE_LIST_C
868 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/win_snprintf.c)
870 if(NOT HAVE_SNPRINTF)
871 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/snprintf.c)
872 endif(NOT HAVE_SNPRINTF)
873 if(NOT HAVE_STRTOK_R)
874 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/strtok_r.c)
875 endif(NOT HAVE_STRTOK_R)
879 # Determine the main pcap-XXX.c file to use, and the libraries with
880 # which we need to link libpcap, if any.
886 # Has the user explicitly specified a capture type?
888 if(PCAP_TYPE STREQUAL "")
890 # The user didn't explicitly specify a capture mechanism.
891 # Check whether we have packet.dll.
895 # We have packet.dll.
896 # Set the capture type to NPF.
901 # We don't have any capture type we know about, so just use
902 # the null capture type, and only support reading (and writing)
912 # Figure out what type of packet capture mechanism we have, and
913 # what libraries we'd need to link libpcap with, if any.
917 # Has the user explicitly specified a capture type?
919 if(PCAP_TYPE STREQUAL "")
921 # Check for a bunch of headers for various packet capture mechanisms.
923 check_include_files("sys/types.h;net/bpf.h" HAVE_NET_BPF_H)
926 # Does it define BIOCSETIF?
927 # I.e., is it a header for an LBL/BSD-style capture
928 # mechanism, or is it just a header for a BPF filter
929 # engine? Some versions of Arch Linux, for example,
930 # have a net/bpf.h that doesn't define BIOCSETIF;
931 # as it's a Linux, it should use packet sockets,
937 # sys/types.h, because FreeBSD 10's net/bpf.h
938 # requires that various BSD-style integer types
941 # sys/ioctl.h and, if we have it, sys/ioccom.h,
942 # because net/bpf.h defines ioctls;
944 # net/if.h, because it defines some structures
945 # used in ioctls defined by net/bpf.h;
947 # sys/socket.h, because OpenBSD 5.9's net/bpf.h
948 # defines some structure fields as being
951 # and net/bpf.h doesn't necessarily include all
952 # of those headers itself.
954 if(HAVE_SYS_IOCCOM_H)
955 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)
956 else(HAVE_SYS_IOCCOM_H)
957 check_symbol_exists(BIOCSETIF "sys/types.h;sys/ioctl.h;sys/socket.h;net/bpf.h;net/if.h" BPF_H_DEFINES_BIOCSETIF)
958 endif(HAVE_SYS_IOCCOM_H)
959 endif(HAVE_NET_BPF_H)
960 check_include_file(net/pfilt.h HAVE_NET_PFILT_H)
961 check_include_file(net/enet.h HAVE_NET_ENET_H)
962 check_include_file(net/nit.h HAVE_NET_NIT_H)
963 check_include_file(sys/net/nit.h HAVE_SYS_NET_NIT_H)
964 check_include_file(linux/socket.h HAVE_LINUX_SOCKET_H)
965 check_include_file(net/raw.h HAVE_NET_RAW_H)
966 check_include_file(sys/dlpi.h HAVE_SYS_DLPI_H)
968 if(BPF_H_DEFINES_BIOCSETIF)
971 # Check this before DLPI, so that we pick BPF on
972 # Solaris 11 and later.
975 elseif(HAVE_LINUX_SOCKET_H)
977 # No prizes for guessing this one.
980 elseif(HAVE_NET_PFILT_H)
982 # DEC OSF/1, Digital UNIX, Tru64 UNIX
985 elseif(HAVE_NET_ENET_H)
987 # Stanford Enetfilter.
990 elseif(HAVE_NET_NIT_H)
992 # SunOS 4.x STREAMS NIT.
995 elseif(HAVE_SYS_NET_NIT_H)
997 # Pre-SunOS 4.x non-STREAMS NIT.
1000 elseif(HAVE_NET_RAW_H)
1004 set(PCAP_TYPE snoop)
1005 elseif(HAVE_SYS_DLPI_H)
1007 # DLPI on pre-Solaris 11 SunOS 5, HP-UX, possibly others.
1012 # Nothing we support.
1018 message(STATUS "Packet capture mechanism type: ${PCAP_TYPE}")
1021 # Do capture-mechanism-dependent tests.
1024 if(PCAP_TYPE STREQUAL "npf")
1026 # Link with packet.dll before WinSock2.
1028 set(PCAP_LINK_LIBRARIES ${PACKET_LIBRARIES} ${PCAP_LINK_LIBRARIES})
1029 elseif(PCAP_TYPE STREQUAL "null")
1031 message(ERROR "${PCAP_TYPE} is not a valid pcap type")
1034 if(PCAP_TYPE STREQUAL "dlpi")
1036 # Needed for common functions used by pcap-[dlpi,libdlpi].c
1038 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} dlpisubs.c)
1041 # Checks for some header files.
1043 check_include_file(sys/bufmod.h HAVE_SYS_BUFMOD_H)
1044 check_include_file(sys/dlpi_ext.h HAVE_SYS_DLPI_EXT_H)
1047 # Checks to see if Solaris has the public libdlpi(3LIB) library.
1048 # Note: The existence of /usr/include/libdlpi.h does not mean it is the
1049 # public libdlpi(3LIB) version. Before libdlpi was made public, a
1050 # private version also existed, which did not have the same APIs.
1051 # Due to a gcc bug, the default search path for 32-bit libraries does
1052 # not include /lib, we add it explicitly here.
1053 # [http://bugs.opensolaris.org/view_bug.do?bug_id=6619485].
1054 # Also, due to the bug above applications that link to libpcap with
1055 # libdlpi will have to add "-L/lib" option to "configure".
1057 cmake_push_check_state()
1058 set(CMAKE_REQUIRED_FLAGS "-L/lib")
1059 set(CMAKE_REQUIRED_LIBRARIES dlpi)
1060 check_function_exists(dlpi_walk HAVE_LIBDLPI)
1061 cmake_pop_check_state()
1066 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} dlpi)
1067 set(PCAP_TYPE libdlpi)
1071 # This check is for Solaris with DLPI support for passive modes.
1072 # See dlpi(7P) for more details.
1074 # XXX - there's no check_type() macro that's like check_type_size()
1075 # except that it only checks for the existence of the structure type,
1076 # so we use check_type_size() and ignore the size.
1078 cmake_push_check_state()
1079 set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h sys/dlpi.h)
1080 check_type_size(dl_passive_req_t DL_PASSIVE_REQ_T)
1081 cmake_pop_check_state()
1082 elseif(PCAP_TYPE STREQUAL "linux")
1084 # Do we have the wireless extensions?
1085 # linux/wireless.h requires sys/socket.h.
1087 check_include_files("sys/socket.h;linux/wireless.h" HAVE_LINUX_WIRELESS_H)
1092 if(BUILD_WITH_LIBNL)
1094 # Try libnl 3.x first.
1096 cmake_push_check_state()
1097 set(CMAKE_REQUIRED_LIBRARIES nl-3)
1098 check_function_exists(nl_socket_alloc HAVE_LIBNL)
1099 cmake_pop_check_state()
1102 # Yes, we have libnl 3.x.
1104 set(PCAP_LINK_LIBRARIES nl-genl-3 nl-3 ${PCAP_LINK_LIBRARIES})
1105 set(HAVE_LIBNL_3_x ON)
1106 set(HAVE_LIBNL_NLE ON)
1107 set(HAVE_LIBNL_SOCKETS ON)
1108 include_directories("/usr/include/libnl3")
1113 cmake_push_check_state()
1114 set(CMAKE_REQUIRED_LIBRARIES nl)
1115 check_function_exists(nl_socket_alloc HAVE_LIBNL)
1116 cmake_pop_check_state()
1119 # Yes, we have libnl 2.x.
1121 set(PCAP_LINK_LIBRARIES nl-genl nl ${PCAP_LINK_LIBRARIES})
1122 set(HAVE_LIBNL_2_x ON)
1123 set(HAVE_LIBNL_NLE ON)
1124 set(HAVE_LIBNL_SOCKETS ON)
1127 # No, we don't; do we have libnl 1.x?
1129 cmake_push_check_state()
1130 set(CMAKE_REQUIRED_LIBRARIES nl)
1131 check_function_exists(nl_handle_alloc HAVE_LIBNL)
1132 cmake_pop_check_state()
1134 set(PCAP_LINK_LIBRARIES nl ${PCAP_LINK_LIBRARIES})
1140 check_include_file(linux/ethtool.h HAVE_LINUX_ETHTOOL_H)
1143 # Checks to see if tpacket_stats is defined in linux/if_packet.h
1144 # If so then pcap-linux.c can use this to report proper statistics.
1146 # XXX - there's no check_type() macro that's like check_type_size()
1147 # except that it only checks for the existence of the structure type,
1148 # so we use check_type_size() and ignore the size.
1150 cmake_push_check_state()
1151 set(CMAKE_EXTRA_INCLUDE_FILES linux/if_packet.h)
1152 check_type_size("struct tpacket_stats" STRUCT_TPACKET_STATS)
1153 cmake_pop_check_state()
1155 check_struct_has_member("struct tpacket_auxdata" tp_vlan_tci linux/if_packet.h HAVE_STRUCT_TPACKET_AUXDATA_TP_VLAN_TCI)
1156 elseif(PCAP_TYPE STREQUAL "bpf")
1158 # Check whether we have the *BSD-style ioctls.
1160 check_include_files("sys/types.h;net/if_media.h" HAVE_NET_IF_MEDIA_H)
1163 # Check whether we have struct BPF_TIMEVAL.
1165 # XXX - there's no check_type() macro that's like check_type_size()
1166 # except that it only checks for the existence of the structure type,
1167 # so we use check_type_size() and ignore the size.
1169 cmake_push_check_state()
1170 if(HAVE_SYS_IOCCOM_H)
1171 set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h sys/ioccom.h net/bpf.h)
1172 check_type_size("struct BPF_TIMEVAL" STRUCT_BPF_TIMEVAL)
1174 set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h net/bpf.h)
1175 check_type_size("struct BPF_TIMEVAL" STRUCT_BPF_TIMEVAL)
1177 cmake_pop_check_state()
1178 elseif(PCAP_TYPE STREQUAL "null")
1180 message(FATAL_ERROR "${PCAP_TYPE} is not a valid pcap type")
1184 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-${PCAP_TYPE}.c)
1187 # Now figure out how we get a list of interfaces and addresses,
1188 # if we support capturing. Don't bother if we don't support
1193 # UN*X - figure out what type of interface list mechanism we
1196 # If the capture type is null, that means we can't capture,
1197 # so we can't open any capture devices, so we won't return
1200 if(NOT PCAP_TYPE STREQUAL "null")
1201 cmake_push_check_state()
1202 set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LINK_LIBRARIES})
1203 check_function_exists(getifaddrs HAVE_GETIFADDRS)
1204 cmake_pop_check_state()
1205 if(NOT HAVE_GETIFADDRS)
1207 # It's not in the libraries that, at this point, we've
1208 # found we need to link libpcap with.
1210 # It's in libsocket on Solaris and possibly other OSes;
1211 # as long as we're not linking with libxnet, check there.
1213 # NOTE: if you hand check_library_exists as its last
1214 # argument a variable that's been set, it skips the test,
1215 # so we need different variables.
1217 if(NOT LIBXNET_HAS_GETHOSTBYNAME)
1218 check_library_exists(socket getifaddrs "" SOCKET_HAS_GETIFADDRS)
1219 if(SOCKET_HAS_GETIFADDRS)
1220 set(PCAP_LINK_LIBRARIES socket ${PCAP_LINK_LIBRARIES})
1221 set(HAVE_GETIFADDRS TRUE)
1227 # We have "getifaddrs()"; make sure we have <ifaddrs.h>
1228 # as well, just in case some platform is really weird.
1229 # It may require that sys/types.h be included first,
1230 # so include it first.
1232 check_include_files("sys/types.h;ifaddrs.h" HAVE_IFADDRS_H)
1235 # We have the header, so we use "getifaddrs()" to
1236 # get the list of interfaces.
1238 set(FINDALLDEVS_TYPE getad)
1241 # We don't have the header - give up.
1242 # XXX - we could also fall back on some other
1243 # mechanism, but, for now, this'll catch this
1244 # problem so that we can at least try to figure
1245 # out something to do on systems with "getifaddrs()"
1246 # but without "ifaddrs.h", if there is something
1247 # we can do on those systems.
1249 message(FATAL_ERROR "Your system has getifaddrs() but doesn't have a usable <ifaddrs.h>.")
1253 # Well, we don't have "getifaddrs()", at least not with the
1254 # libraries with which we've decided we need to link
1255 # libpcap with, so we have to use some other mechanism.
1257 # Note that this may happen on Solaris, which has
1258 # getifaddrs(), but in -lsocket, not in -lxnet, so we
1259 # won't find it if we link with -lxnet, which we want
1260 # to do for other reasons.
1262 # For now, we use either the SIOCGIFCONF ioctl or the
1263 # SIOCGLIFCONF ioctl, preferring the latter if we have
1264 # it; the latter is a Solarisism that first appeared
1265 # in Solaris 8. (Solaris's getifaddrs() appears to
1266 # be built atop SIOCGLIFCONF; using it directly
1267 # avoids a not-all-that-useful middleman.)
1269 try_compile(HAVE_SIOCGLIFCONF ${CMAKE_CURRENT_BINARY_DIR} "${pcap_SOURCE_DIR}/cmake/have_siocglifconf.c" )
1270 if(HAVE_SIOCGLIFCONF)
1271 set(FINDALLDEVS_TYPE glifc)
1273 set(FINDALLDEVS_TYPE gifc)
1276 message(STATUS "Find-interfaces mechanism type: ${FINDALLDEVS_TYPE}")
1277 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} fad-${FINDALLDEVS_TYPE}.c)
1281 # Check for hardware timestamp support.
1282 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
1283 check_include_file(linux/net_tstamp.h HAVE_LINUX_NET_TSTAMP_H)
1287 # Check for additional native sniffing capabilities.
1290 # Check for USB sniffing support on Linux.
1291 # On FreeBSD, it uses BPF, so we don't need to do anything special here.
1293 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
1294 set(PCAP_SUPPORT_USB TRUE)
1295 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-usb-linux.c)
1296 set(LINUX_USB_MON_DEV /dev/usbmon)
1298 # Do we have a version of <linux/compiler.h> available?
1299 # If so, we might need it for <linux/usbdevice_fs.h>.
1301 check_include_files("linux/compiler.h" HAVE_LINUX_COMPILER_H)
1302 if(HAVE_LINUX_COMPILER_H)
1304 # Yes - include it when testing for <linux/usbdevice_fs.h>.
1306 check_include_files("linux/compiler.h;linux/usbdevice_fs.h" HAVE_LINUX_USBDEVICE_FS_H)
1307 else(HAVE_LINUX_COMPILER_H)
1308 check_include_files("linux/usbdevice_fs.h" HAVE_LINUX_USBDEVICE_FS_H)
1309 endif(HAVE_LINUX_COMPILER_H)
1310 if(HAVE_LINUX_USBDEVICE_FS_H)
1312 # OK, does it define bRequestType? Older versions of the kernel
1313 # define fields with names like "requesttype, "request", and
1314 # "value", rather than "bRequestType", "bRequest", and
1317 if(HAVE_LINUX_COMPILER_H)
1318 check_struct_has_member("struct usbdevfs_ctrltransfer" bRequestType "linux/compiler.h;linux/usbdevice_fs.h" HAVE_STRUCT_USBDEVFS_CTRLTRANSFER_BREQUESTTYPE)
1319 else(HAVE_LINUX_COMPILER_H)
1320 check_struct_has_member("struct usbdevfs_ctrltransfer" bRequestType "linux/usbdevice_fs.h" HAVE_STRUCT_USBDEVFS_CTRLTRANSFER_BREQUESTTYPE)
1321 endif(HAVE_LINUX_COMPILER_H)
1326 # Check for netfilter sniffing support.
1327 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
1329 # Life's too short to deal with trying to get this to compile
1330 # if you don't get the right types defined with
1331 # __KERNEL_STRICT_NAMES getting defined by some other include.
1333 # Check whether the includes Just Work. If not, don't turn on
1334 # netfilter support.
1336 check_c_source_compiles(
1337 "#include <sys/socket.h>
1338 #include <netinet/in.h>
1339 #include <linux/types.h>
1341 #include <linux/netlink.h>
1342 #include <linux/netfilter.h>
1343 #include <linux/netfilter/nfnetlink.h>
1344 #include <linux/netfilter/nfnetlink_log.h>
1345 #include <linux/netfilter/nfnetlink_queue.h>
1353 PCAP_SUPPORT_NETFILTER)
1354 if(PCAP_SUPPORT_NETFILTER)
1355 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-netfilter-linux.c)
1356 endif(PCAP_SUPPORT_NETFILTER)
1359 # Check for netmap sniffing support.
1360 if(NOT DISABLE_NETMAP)
1362 # Check whether net/netmap_user.h is usable if NETMAP_WITH_LIBS is
1363 # defined; it's not usable on DragonFly BSD 4.6 if NETMAP_WITH_LIBS
1364 # is defined, for example, as it includes a non-existent malloc.h
1367 check_c_source_compiles(
1368 "#define NETMAP_WITH_LIBS
1369 #include <net/netmap_user.h>
1377 PCAP_SUPPORT_NETMAP)
1378 if(PCAP_SUPPORT_NETMAP)
1379 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-netmap.c)
1380 endif(PCAP_SUPPORT_NETMAP)
1383 # Check for Bluetooth sniffing support
1384 if(NOT DISABLE_BLUETOOTH)
1385 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
1386 check_include_file(bluetooth/bluetooth.h HAVE_BLUETOOTH_BLUETOOTH_H)
1387 if(HAVE_BLUETOOTH_BLUETOOTH_H)
1388 set(PCAP_SUPPORT_BT TRUE)
1389 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-bt-linux.c)
1391 # OK, does struct sockaddr_hci have an hci_channel
1394 check_struct_has_member("struct sockaddr_hci" hci_channel "bluetooth/bluetooth.h;bluetooth/hci.h" HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL)
1395 if(HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL)
1397 # OK, is HCI_CHANNEL_MONITOR defined?
1399 check_c_source_compiles(
1400 "#include <bluetooth/bluetooth.h>
1401 #include <bluetooth/hci.h>
1406 u_int i = HCI_CHANNEL_MONITOR;
1410 PCAP_SUPPORT_BT_MONITOR)
1411 if(PCAP_SUPPORT_BT_MONITOR)
1413 # Yes, so we can also support Bluetooth monitor
1416 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-bt-monitor-linux.c)
1417 endif(PCAP_SUPPORT_BT_MONITOR)
1418 endif(HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL)
1419 endif(HAVE_BLUETOOTH_BLUETOOTH_H)
1423 # Check for Bluetooth sniffing support
1424 if(NOT DISABLE_DBUS)
1426 # We don't support D-Bus sniffing on macOS; see
1428 # https://bugs.freedesktop.org/show_bug.cgi?id=74029
1431 message(FATAL_ERROR "Due to freedesktop.org bug 74029, D-Bus capture support is not available on macOS")
1433 include(FindPkgConfig)
1434 pkg_check_modules(DBUS dbus-1)
1436 set(PCAP_SUPPORT_DBUS TRUE)
1437 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-dbus.c)
1438 include_directories(${DBUS_INCLUDE_DIRS})
1439 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${DBUS_LIBRARIES})
1441 endif(NOT DISABLE_DBUS)
1443 # Check for RDMA sniffing support
1444 if(NOT DISABLE_RDMA)
1445 check_library_exists(ibverbs ibv_get_device_list "" LIBIBVERBS_HAS_IBV_GET_DEVICE_LIST)
1446 if(LIBIBVERBS_HAS_IBV_GET_DEVICE_LIST)
1447 check_include_file(infiniband/verbs.h HAVE_INFINIBAND_VERBS_H)
1448 if(HAVE_INFINIBAND_VERBS_H)
1449 check_symbol_exists(ibv_create_flow infiniband/verbs.h PCAP_SUPPORT_RDMASNIFF)
1450 if(PCAP_SUPPORT_RDMASNIFF)
1451 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-rdmasniff.c)
1452 set(PCAP_LINK_LIBRARIES ibverbs ${PCAP_LINK_LIBRARIES})
1453 endif(PCAP_SUPPORT_RDMASNIFF)
1454 endif(HAVE_INFINIBAND_VERBS_H)
1455 endif(LIBIBVERBS_HAS_IBV_GET_DEVICE_LIST)
1456 endif(NOT DISABLE_RDMA)
1459 # Check for sniffing capabilities using third-party APIs.
1462 # Check for Endace DAG card support.
1465 # Try to find the DAG header file and library.
1475 # Check for various DAG API functions.
1477 cmake_push_check_state()
1478 set(CMAKE_REQUIRED_INCLUDES ${DAG_INCLUDE_DIRS})
1479 set(CMAKE_REQUIRED_LIBRARIES ${DAG_LIBRARIES})
1480 check_function_exists(dag_attach_stream HAVE_DAG_STREAMS_API)
1481 if(NOT HAVE_DAG_STREAMS_API)
1482 message(FATAL_ERROR "DAG library lacks streams support")
1484 check_function_exists(dag_attach_stream64 HAVE_DAG_LARGE_STREAMS_API)
1485 check_function_exists(dag_get_erf_types HAVE_DAG_GET_ERF_TYPES)
1486 check_function_exists(dag_get_stream_erf_types HAVE_DAG_GET_STREAM_ERF_TYPES)
1487 cmake_pop_check_state()
1489 include_directories(AFTER ${DAG_INCLUDE_DIRS})
1490 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-dag.c)
1491 set(HAVE_DAG_API TRUE)
1492 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${DAG_LIBRARIES})
1494 if(HAVE_DAG_LARGE_STREAMS_API)
1495 get_filename_component(DAG_LIBRARY_DIR ${DAG_LIBRARY} PATH)
1496 check_library_exists(vdag vdag_set_device_info ${DAG_LIBRARY_DIR} HAVE_DAG_VDAG)
1498 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
1504 # Check for Septel card support.
1505 set(PROJECT_EXTERNAL_OBJECT_LIST "")
1506 if(NOT DISABLE_SEPTEL)
1508 # Do we have the msg.h header?
1510 set(SEPTEL_INCLUDE_DIRS "${SEPTEL_ROOT}/INC")
1511 cmake_push_check_state()
1512 set(CMAKE_REQUIRED_INCLUDES ${SEPTEL_INCLUDE_DIRS})
1513 check_include_file(msg.h HAVE_INC_MSG_H)
1514 cmake_pop_check_state()
1519 include_directories(AFTER ${SEPTEL_INCLUDE_DIRS})
1520 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-septel.c)
1521 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")
1522 set(HAVE_SEPTEL_API TRUE)
1526 # Check for Myricom SNF support.
1529 # Try to find the SNF header file and library.
1540 include_directories(AFTER ${SNF_INCLUDE_DIRS})
1541 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-snf.c)
1542 set(HAVE_SNF_API TRUE)
1543 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${SNF_LIBRARIES})
1547 # Check for Riverbed TurboCap support.
1550 # Try to find the TurboCap header file and library.
1561 include_directories(AFTER ${TC_INCLUDE_DIRS})
1562 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-tc.c)
1563 set(HAVE_TC_API TRUE)
1564 set(PCAP_LINK_LIBRARIES "${PCAP_LINK_LIBRARIES} ${TC_LIBRARIES} ${CMAKE_USE_PTHREADS_INIT} stdc++")
1569 # Remote capture support.
1574 # Check for various members of struct msghdr.
1575 # We need to include ftmacros.h on some platforms, to make sure we
1576 # get the POSIX/Single USER Specification version of struct msghdr,
1577 # which has those members, rather than the backwards-compatible
1578 # version, which doesn't. That's not a system header file, and
1579 # at least some versions of CMake include it as <ftmacros.h>, which
1580 # won't check the current directory, so we add the top-level
1581 # source directory to the list of include directories when we do
1584 cmake_push_check_state()
1585 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_SOURCE_DIR})
1586 check_struct_has_member("struct msghdr" msg_control "ftmacros.h;sys/socket.h" HAVE_STRUCT_MSGHDR_MSG_CONTROL)
1587 check_struct_has_member("struct msghdr" msg_flags "ftmacros.h;sys/socket.h" HAVE_STRUCT_MSGHDR_MSG_FLAGS)
1588 cmake_pop_check_state()
1589 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C}
1590 pcap-new.c pcap-rpcap.c rpcap-protocol.c sockutils.c)
1591 endif(ENABLE_REMOTE)
1593 ###################################################################
1595 ###################################################################
1598 # Check and add warning options if we have a .devel file.
1600 if(EXISTS ${CMAKE_SOURCE_DIR}/.devel OR EXISTS ${CMAKE_BINARY_DIR}/.devel)
1604 if(MSVC AND NOT ${CMAKE_C_COMPILER} MATCHES "clang*")
1606 # MSVC, with Microsoft's front end and code generator.
1607 # "MSVC" is also set for Microsoft's compiler with a Clang
1608 # front end and their code generator ("Clang/C2"), so we
1609 # check for clang.exe and treat that differently.
1611 check_and_add_compiler_option(-Wall)
1613 # Disable some pointless warnings that /Wall turns on.
1615 # Unfortunately, MSVC does not appear to have an equivalent
1616 # to "__attribute__((unused))" to mark a particular function
1617 # parameter as being known to be unused, so that the compiler
1618 # won't warn about it (for example, the function might have
1619 # that parameter because a pointer to it is being used, and
1620 # the signature of that function includes that parameter).
1621 # C++ lets you give a parameter a type but no name, but C
1622 # doesn't have that.
1624 check_and_add_compiler_option(-wd4100)
1626 # In theory, we care whether somebody uses f() rather than
1627 # f(void) to declare a function with no arguments, but, in
1628 # practice, there are places in the Windows header files
1629 # that appear to do that, so we squelch that warning.
1631 check_and_add_compiler_option(-wd4255)
1633 # Windows FD_SET() generates this, so we suppress it.
1635 check_and_add_compiler_option(-wd4548)
1637 # Perhaps testing something #defined to be 0 with #ifdef is an
1638 # error, and it should be tested with #if, but perhaps it's
1639 # not, and Microsoft does that in its headers, so we squelch
1642 check_and_add_compiler_option(-wd4574)
1644 # The Windows headers also test not-defined values in #if, so
1645 # we don't want warnings about that, either.
1647 check_and_add_compiler_option(-wd4668)
1649 # We do *not* care whether some function is, or isn't, going to be
1652 check_and_add_compiler_option(-wd4710)
1653 check_and_add_compiler_option(-wd4711)
1655 # We do *not* care whether we're adding padding bytes after
1656 # structure members.
1658 check_and_add_compiler_option(-wd4820)
1661 # Other compilers, including MSVC with a Clang front end and
1662 # Microsoft's code generator. We currently treat them as if
1663 # they might support GCC-style -W options.
1665 check_and_add_compiler_option(-Wall)
1666 check_and_add_compiler_option(-Wsign-compare)
1667 check_and_add_compiler_option(-Wmissing-prototypes)
1668 check_and_add_compiler_option(-Wstrict-prototypes)
1669 check_and_add_compiler_option(-Wshadow)
1670 check_and_add_compiler_option(-Wdeclaration-after-statement)
1671 check_and_add_compiler_option(-Wused-but-marked-unused)
1672 check_and_add_compiler_option(-Wdocumentation)
1673 check_and_add_compiler_option(-Wcomma)
1674 check_and_add_compiler_option(-Wmissing-noreturn)
1675 # Warns about safeguards added in case the enums are extended
1676 # check_and_add_compiler_option(-Wcovered-switch-default)
1677 check_and_add_compiler_option(-Wmissing-variable-declarations)
1682 # Suppress some warnings we get with MSVC even without /Wall.
1684 if(MSVC AND NOT ${CMAKE_C_COMPILER} MATCHES "clang*")
1686 # Yes, we have some functions that never return but that
1687 # have a non-void return type. That's because, on some
1688 # platforms, they *do* return values but, on other
1689 # platforms, including Windows, they just fail and
1690 # longjmp out by calling bpf_error().
1692 check_and_add_compiler_option(-wd4646)
1695 file(GLOB PROJECT_SOURCE_LIST_H
1701 # Add subdirectories after we've set C_ADDITIONAL_FLAGS, so they
1702 # pick up those flags.
1705 add_subdirectory(rpcapd)
1706 endif(ENABLE_REMOTE)
1709 # Try to have the compiler default to hiding symbols, so that only
1710 # symbols explicitly exported with PCAP_API will be visible outside
1711 # (shared) libraries.
1713 # Not necessary with MSVC, as that's the default.
1715 # XXX - we don't use ADD_COMPILER_EXPORT_FLAGS, because, as of CMake
1716 # 2.8.12.2, it doesn't know about Sun C/Oracle Studio, and, as of
1717 # CMake 2.8.6, it only sets the C++ compiler flags, rather than
1718 # allowing an arbitrary variable to be set with the "hide symbols
1719 # not explicitly exported" flag.
1722 if(CMAKE_C_COMPILER_ID MATCHES "SunPro")
1724 # Sun C/Oracle Studio.
1726 check_and_add_compiler_option(-xldscope=hidden)
1729 # Try this for all other compilers; it's what GCC uses,
1730 # and a number of other compilers, such as Clang and Intel C,
1733 check_and_add_compiler_option(-fvisibility=hidden)
1738 # Flex/Lex and YACC/Berkeley YACC/Bison.
1739 # From a mail message to the CMake mailing list by Andy Cedilnik of
1744 # Try to find Flex, a Windows version of Flex, or Lex.
1746 find_program(LEX_EXECUTABLE NAMES flex win_flex lex)
1747 if(LEX_EXECUTABLE STREQUAL "LEX_EXECUTABLE-NOTFOUND")
1748 message(FATAL_ERROR "Neither flex nor win_flex nor lex was found.")
1750 message(STATUS "Lexical analyzer generator: ${LEX_EXECUTABLE}")
1753 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/scanner.c ${CMAKE_CURRENT_BINARY_DIR}/scanner.h
1754 SOURCE ${pcap_SOURCE_DIR}/scanner.l
1755 COMMAND ${LEX_EXECUTABLE} -P pcap_ --header-file=scanner.h --nounput -o${CMAKE_CURRENT_BINARY_DIR}/scanner.c ${pcap_SOURCE_DIR}/scanner.l
1756 DEPENDS ${pcap_SOURCE_DIR}/scanner.l
1760 # Since scanner.c does not exist yet when cmake is run, mark
1763 # Since scanner.c includes grammar.h, mark that as a dependency.
1765 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/scanner.c PROPERTIES
1767 OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/scanner.h
1771 # Add scanner.c to the list of sources.
1773 #set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${CMAKE_CURRENT_BINARY_DIR}/scanner.c)
1776 # Try to find YACC or Bison.
1778 find_program(YACC_EXECUTABLE NAMES bison win_bison byacc yacc)
1779 if(YACC_EXECUTABLE STREQUAL "YACC_EXECUTABLE-NOTFOUND")
1780 message(FATAL_ERROR "Neither bison nor win_bison nor byacc nor yacc was found.")
1782 message(STATUS "Parser generator: ${YACC_EXECUTABLE}")
1785 # Create custom command for the scanner.
1786 # Find out whether it's Bison or not by looking at the last component
1787 # of the path (without a .exe extension, if this is Windows).
1789 get_filename_component(YACC_NAME ${YACC_EXECUTABLE} NAME_WE)
1790 if("${YACC_NAME}" STREQUAL "bison" OR "${YACC_NAME}" STREQUAL "win_bison")
1791 set(YACC_COMPATIBILITY_FLAG "-y")
1794 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/grammar.c ${CMAKE_CURRENT_BINARY_DIR}/grammar.h
1795 SOURCE ${pcap_SOURCE_DIR}/grammar.y
1796 COMMAND ${YACC_EXECUTABLE} ${YACC_COMPATIBILITY_FLAG} -p pcap_ -o ${CMAKE_CURRENT_BINARY_DIR}/grammar.c -d ${pcap_SOURCE_DIR}/grammar.y
1797 DEPENDS ${pcap_SOURCE_DIR}/grammar.y
1801 # Since grammar.c does not exists yet when cmake is run, mark
1804 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/grammar.c PROPERTIES
1809 # Add grammar.c to the list of sources.
1811 #set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${CMAKE_CURRENT_BINARY_DIR}/grammar.c)
1814 # Assume, by default, V7/BSD convention for man pages (file formats in
1815 # section 5, miscellaneous info in section 7).
1816 # Individual cases can override this.
1818 set(MAN_FILE_FORMATS 5)
1819 set(MAN_MISC_INFO 7)
1820 set(MAN_USERMOD_SECTION 8)
1821 if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
1822 # Workaround to enable certain features
1824 if(PCAP_TYPE STREQUAL "bpf")
1826 # If we're using BPF, we need libodm and libcfg, as
1827 # we use them to load the BPF module.
1829 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} odm cfg)
1831 elseif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
1832 if(CMAKE_SYSTEM_VERSION MATCHES "[A-Z.]*9\.[0-9]*")
1836 set(HAVE_HPUX9 TRUE)
1837 elseif(CMAKE_SYSTEM_VERSION MATCHES "[A-Z.]*10\.0")
1841 elseif(CMAKE_SYSTEM_VERSION MATCHES "[A-Z.]*10\.1")
1847 # HP-UX 10.20 and later.
1849 set(HAVE_HPUX10_20_OR_LATER TRUE)
1853 # Use System V conventions for man pages.
1855 set(MAN_FILE_FORMATS 4)
1856 set(MAN_MISC_INFO 5)
1857 elseif(CMAKE_SYSTEM_NAME STREQUAL "IRIX" OR CMAKE_SYSTEM_NAME STREQUAL "IRIX64")
1859 # Use System V conventions for man pages.
1861 set(MAN_FILE_FORMATS 4)
1862 set(MAN_MISC_INFO 5)
1863 elseif(CMAKE_SYSTEM_NAME STREQUAL "OSF1")
1865 # DEC OSF/1, a/k/a Digial UNIX, a/k/a Tru64 UNIX.
1866 # Use System V conventions for man pages.
1868 set(MAN_FILE_FORMATS 4)
1869 set(MAN_MISC_INFO 5)
1870 elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_VERSION MATCHES "5[.][0-9.]*")
1874 set(HAVE_SOLARIS TRUE)
1876 # Make sure errno is thread-safe, in case we're called in
1877 # a multithreaded program. We don't guarantee that two
1878 # threads can use the *same* pcap_t safely, but the
1879 # current version does guarantee that you can use different
1880 # pcap_t's in different threads, and even that pcap_compile()
1881 # is thread-safe (it wasn't thread-safe in some older versions).
1883 add_definitions(-D_TS_ERRNO)
1885 if(CMAKE_SYSTEM_VERSION STREQUAL "5.12")
1888 # Use System V conventions for man pages.
1890 set(MAN_USERMOD_SECTION 1m)
1891 set(MAN_FILE_FORMATS 4)
1892 set(MAN_MISC_INFO 5)
1896 source_group("Source Files" FILES ${PROJECT_SOURCE_LIST_C})
1897 source_group("Header Files" FILES ${PROJECT_SOURCE_LIST_H})
1901 # Add pcap-dll.rc to the list of sources.
1903 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${pcap_SOURCE_DIR}/pcap-dll.rc)
1906 add_subdirectory(testprogs)
1908 ######################################
1910 ######################################
1913 # Special target to serialize the building of the generated source.
1917 # http://public.kitware.com/pipermail/cmake/2013-August/055510.html
1919 add_custom_target(SerializeTarget
1921 ${CMAKE_CURRENT_BINARY_DIR}/grammar.c
1922 ${CMAKE_CURRENT_BINARY_DIR}/scanner.c
1925 set_source_files_properties(${PROJECT_EXTERNAL_OBJECT_LIST} PROPERTIES
1926 EXTERNAL_OBJECT TRUE)
1928 if(BUILD_SHARED_LIBS)
1929 add_library(${LIBRARY_NAME} SHARED
1930 ${PROJECT_SOURCE_LIST_C}
1931 ${CMAKE_CURRENT_BINARY_DIR}/grammar.c
1932 ${CMAKE_CURRENT_BINARY_DIR}/scanner.c
1933 ${PROJECT_EXTERNAL_OBJECT_LIST}
1935 add_dependencies(${LIBRARY_NAME} SerializeTarget)
1936 set_target_properties(${LIBRARY_NAME} PROPERTIES
1937 COMPILE_DEFINITIONS BUILDING_PCAP)
1938 endif(BUILD_SHARED_LIBS)
1940 add_library(${LIBRARY_NAME}_static STATIC
1941 ${PROJECT_SOURCE_LIST_C}
1942 ${CMAKE_CURRENT_BINARY_DIR}/grammar.c
1943 ${CMAKE_CURRENT_BINARY_DIR}/scanner.c
1944 ${PROJECT_EXTERNAL_OBJECT_LIST}
1946 add_dependencies(${LIBRARY_NAME}_static SerializeTarget)
1947 set_target_properties(${LIBRARY_NAME}_static PROPERTIES
1948 COMPILE_DEFINITIONS BUILDING_PCAP)
1951 if(BUILD_SHARED_LIBS)
1952 set_target_properties(${LIBRARY_NAME} PROPERTIES
1953 VERSION ${PACKAGE_VERSION_NOSUFFIX} # only MAJOR and MINOR are needed
1955 endif(BUILD_SHARED_LIBS)
1957 # XXX For DLLs, the TARGET_PDB_FILE generator expression can be used to locate
1958 # its PDB file's output directory for installation.
1959 # cmake doesn't offer a generator expression for PDB files generated by the
1960 # compiler (static libraries).
1961 # So instead of considering any possible output there is (there are many),
1962 # this will search for the PDB file in the compiler's initial output directory,
1963 # which is always ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles\wpcap_static.dir
1964 # regardless of architecture, build generator etc.
1965 # Quite hackish indeed.
1966 set(CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY $<TARGET_FILE_DIR:${LIBRARY_NAME}_static>)
1967 set_target_properties(${LIBRARY_NAME}_static PROPERTIES
1968 COMPILE_PDB_NAME ${LIBRARY_NAME}_static
1969 OUTPUT_NAME "${LIBRARY_NAME}_static"
1973 # For compatibility, build the shared library without the "lib" prefix on
1976 set_target_properties(${LIBRARY_NAME} PROPERTIES
1978 OUTPUT_NAME "${LIBRARY_NAME}"
1980 set_target_properties(${LIBRARY_NAME}_static PROPERTIES
1981 OUTPUT_NAME "${LIBRARY_NAME}"
1985 if(BUILD_SHARED_LIBS)
1987 set_target_properties(${LIBRARY_NAME} PROPERTIES
1988 VERSION ${PACKAGE_VERSION}
1992 set_target_properties(${LIBRARY_NAME} PROPERTIES
1993 VERSION ${PACKAGE_VERSION}
1994 SOVERSION ${PACKAGE_VERSION_MAJOR}
1997 endif(BUILD_SHARED_LIBS)
1998 set_target_properties(${LIBRARY_NAME}_static PROPERTIES
1999 OUTPUT_NAME "${LIBRARY_NAME}"
2003 if(BUILD_SHARED_LIBS)
2004 if(NOT C_ADDITIONAL_FLAGS STREQUAL "")
2005 set_target_properties(${LIBRARY_NAME} PROPERTIES COMPILE_FLAGS ${C_ADDITIONAL_FLAGS})
2007 target_link_libraries(${LIBRARY_NAME} ${PCAP_LINK_LIBRARIES})
2008 endif(BUILD_SHARED_LIBS)
2010 if(NOT C_ADDITIONAL_FLAGS STREQUAL "")
2011 set_target_properties(${LIBRARY_NAME}_static PROPERTIES COMPILE_FLAGS ${C_ADDITIONAL_FLAGS})
2014 ######################################
2015 # Write out the config.h file
2016 ######################################
2018 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
2020 ######################################
2021 # Install pcap library, include files, and man pages
2022 ######################################
2025 # "Define GNU standard installation directories", which actually
2026 # are also defined, to some degree, by autotools, and at least
2027 # some of which are general UN*X conventions.
2029 include(GNUInstallDirs)
2031 set(LIBRARY_NAME_STATIC ${LIBRARY_NAME}_static)
2033 function(install_manpage_symlink SOURCE TARGET MANDIR)
2035 find_program(LINK_EXECUTABLE ln)
2037 set(LINK_COMMAND "\"${LINK_EXECUTABLE}\" \"-s\" \"${SOURCE}\" \"${TARGET}\"")
2038 else(LINK_EXECUTABLE)
2039 message(FATAL_ERROR "ln (http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ln.html) not find.")
2040 endif(LINK_EXECUTABLE)
2042 set(LINK_COMMAND "\"${CMAKE_COMMAND}\" \"-E\" \"create_symlink\" \"${SOURCE}\" \"${TARGET}\"")
2046 "message(STATUS \"Symlinking: ${CMAKE_INSTALL_PREFIX}/${MANDIR}/${SOURCE} to ${TARGET}\")
2048 COMMAND \"${CMAKE_COMMAND}\" \"-E\" \"remove\" \"${TARGET}\"
2049 WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${MANDIR}
2052 COMMAND ${LINK_COMMAND}
2053 WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${MANDIR}
2054 RESULT_VARIABLE EXIT_STATUS
2056 if(NOT EXIT_STATUS EQUAL 0)
2057 message(FATAL_ERROR \"Could not create symbolic link from ${CMAKE_INSTALL_PREFIX}/${MANDIR}/${SOURCE} to ${TARGET}\")
2059 set(CMAKE_INSTALL_MANIFEST_FILES \${CMAKE_INSTALL_MANIFEST_FILES} ${CMAKE_INSTALL_PREFIX}/${MANDIR}/${TARGET})")
2060 endfunction(install_manpage_symlink)
2062 set(MAN1_NOEXPAND pcap-config.1)
2065 pcap_compile.3pcap.in
2066 pcap_datalink.3pcap.in
2067 pcap_dump_open.3pcap.in
2068 pcap_get_tstamp_precision.3pcap.in
2069 pcap_list_datalinks.3pcap.in
2070 pcap_list_tstamp_types.3pcap.in
2071 pcap_open_dead.3pcap.in
2072 pcap_open_offline.3pcap.in
2073 pcap_set_tstamp_precision.3pcap.in
2074 pcap_set_tstamp_type.3pcap.in
2076 set(MAN3PCAP_NOEXPAND
2078 pcap_breakloop.3pcap
2079 pcap_can_set_rfmon.3pcap
2082 pcap_datalink_name_to_val.3pcap
2083 pcap_datalink_val_to_name.3pcap
2085 pcap_dump_close.3pcap
2086 pcap_dump_file.3pcap
2087 pcap_dump_flush.3pcap
2088 pcap_dump_ftell.3pcap
2091 pcap_findalldevs.3pcap
2093 pcap_get_required_select_timeout.3pcap
2094 pcap_get_selectable_fd.3pcap
2097 pcap_is_swapped.3pcap
2098 pcap_lib_version.3pcap
2099 pcap_lookupdev.3pcap
2100 pcap_lookupnet.3pcap
2102 pcap_major_version.3pcap
2104 pcap_offline_filter.3pcap
2105 pcap_open_live.3pcap
2106 pcap_set_buffer_size.3pcap
2107 pcap_set_datalink.3pcap
2108 pcap_set_immediate_mode.3pcap
2109 pcap_set_promisc.3pcap
2110 pcap_set_protocol.3pcap
2111 pcap_set_rfmon.3pcap
2112 pcap_set_snaplen.3pcap
2113 pcap_set_timeout.3pcap
2114 pcap_setdirection.3pcap
2115 pcap_setfilter.3pcap
2116 pcap_setnonblock.3pcap
2119 pcap_statustostr.3pcap
2121 pcap_tstamp_type_name_to_val.3pcap
2122 pcap_tstamp_type_val_to_name.3pcap
2124 set(MANFILE_EXPAND pcap-savefile.manfile.in)
2126 pcap-filter.manmisc.in
2127 pcap-linktype.manmisc.in
2128 pcap-tstamp.manmisc.in
2131 if(NOT BUILD_SHARED_LIBS)
2133 endif(NOT BUILD_SHARED_LIBS)
2136 if(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8)
2138 # Install 64-bit code built with MSVC in the amd64 subdirectories,
2139 # as that's where it expects it to be.
2141 install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC}
2142 RUNTIME DESTINATION bin/amd64
2143 LIBRARY DESTINATION lib/amd64
2144 ARCHIVE DESTINATION lib/amd64)
2146 install(FILES $<TARGET_FILE_DIR:${LIBRARY_NAME_STATIC}>/${LIBRARY_NAME_STATIC}.pdb
2147 DESTINATION bin/amd64 OPTIONAL)
2148 if(BUILD_SHARED_LIBS)
2149 install(FILES $<TARGET_PDB_FILE:${LIBRARY_NAME}>
2150 DESTINATION bin/amd64 OPTIONAL)
2151 endif(BUILD_SHARED_LIBS)
2153 else(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8)
2155 # Install 32-bit code, and 64-bit code not built with MSVC
2156 # in the top-level directories, as those are where they
2159 install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC}
2160 RUNTIME DESTINATION bin
2161 LIBRARY DESTINATION lib
2162 ARCHIVE DESTINATION lib)
2164 install(FILES $<TARGET_FILE_DIR:${LIBRARY_NAME_STATIC}>/${LIBRARY_NAME_STATIC}.pdb
2165 DESTINATION bin OPTIONAL)
2166 if(BUILD_SHARED_LIBS)
2167 install(FILES $<TARGET_PDB_FILE:${LIBRARY_NAME}>
2168 DESTINATION bin OPTIONAL)
2169 endif(BUILD_SHARED_LIBS)
2171 endif(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8)
2173 install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC} DESTINATION lib)
2176 install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/pcap/ DESTINATION include/pcap)
2177 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pcap.h DESTINATION include)
2179 # On UN*X, and on Windows when not using MSVC, generate pcap-config and process
2180 # man pages and arrange that they be installed.
2182 set(PACKAGE_NAME ${LIBRARY_NAME})
2183 set(prefix ${CMAKE_INSTALL_PREFIX})
2184 set(exec_prefix "\${prefix}")
2185 set(includedir "\${prefix}/include")
2186 set(libdir "\${exec_prefix}/lib")
2187 if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR
2188 CMAKE_SYSTEM_NAME STREQUAL "NetBSD" OR
2189 CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR
2190 CMAKE_SYSTEM_NAME STREQUAL "DragonFly BSD" OR
2191 CMAKE_SYSTEM_NAME STREQUAL "Linux" OR
2192 CMAKE_SYSTEM_NAME STREQUAL "OSF1")
2194 # Platforms where the linker is the GNU linker
2195 # or accepts command-line arguments like
2196 # those the GNU linker accepts.
2198 set(V_RPATH_OPT "-Wl,-rpath,")
2199 elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_VERSION MATCHES "5[.][0-9.]*")
2203 # XXX - this assumes GCC is using the Sun linker,
2204 # rather than the GNU linker.
2206 set(V_RPATH_OPT "-Wl,-R,")
2209 # No option needed to set the RPATH.
2214 foreach(LIB ${PCAP_LINK_LIBRARIES})
2215 set(LIBS "${LIBS} -l${LIB}")
2217 configure_file(${CMAKE_SOURCE_DIR}/pcap-config.in ${CMAKE_CURRENT_BINARY_DIR}/pcap-config @ONLY)
2218 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/pcap-config DESTINATION bin)
2223 # For each section of the manual for which we have man pages
2224 # that require macro expansion, do the expansion.
2227 foreach(MANPAGE ${MAN1_NOEXPAND})
2228 set(MAN1 ${MAN1} ${CMAKE_SOURCE_DIR}/${MANPAGE})
2230 install(FILES ${MAN1} DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
2233 foreach(MANPAGE ${MAN3PCAP_NOEXPAND})
2234 set(MAN3PCAP ${MAN3PCAP} ${CMAKE_SOURCE_DIR}/${MANPAGE})
2236 foreach(TEMPLATE_MANPAGE ${MAN3PCAP_EXPAND})
2237 string(REPLACE ".in" "" MANPAGE ${TEMPLATE_MANPAGE})
2238 configure_file(${CMAKE_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY)
2239 set(MAN3PCAP ${MAN3PCAP} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE})
2240 endforeach(TEMPLATE_MANPAGE)
2241 install(FILES ${MAN3PCAP} DESTINATION ${CMAKE_INSTALL_MANDIR}/man3)
2242 install_manpage_symlink(pcap_datalink_val_to_name.3pcap pcap_datalink_val_to_description.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2243 install_manpage_symlink(pcap_dump_open.3pcap pcap_dump_fopen.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2244 install_manpage_symlink(pcap_findalldevs.3pcap pcap_freealldevs.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2245 install_manpage_symlink(pcap_geterr.3pcap pcap_perror.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2246 install_manpage_symlink(pcap_inject.3pcap pcap_sendpacket.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2247 install_manpage_symlink(pcap_list_datalinks.3pcap pcap_free_datalinks.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2248 install_manpage_symlink(pcap_list_tstamp_types.3pcap pcap_free_tstamp_types.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2249 install_manpage_symlink(pcap_loop.3pcap pcap_dispatch.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2250 install_manpage_symlink(pcap_major_version.3pcap pcap_minor_version.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2251 install_manpage_symlink(pcap_next_ex.3pcap pcap_next.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2252 install_manpage_symlink(pcap_open_dead.3pcap pcap_open_dead_with_tstamp_precision.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2253 install_manpage_symlink(pcap_open_offline.3pcap pcap_open_offline_with_tstamp_precision.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2254 install_manpage_symlink(pcap_open_offline.3pcap pcap_fopen_offline.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2255 install_manpage_symlink(pcap_open_offline.3pcap pcap_fopen_offline_with_tstamp_precision.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2256 install_manpage_symlink(pcap_tstamp_type_val_to_name.3pcap pcap_tstamp_type_val_to_description.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2257 install_manpage_symlink(pcap_setnonblock.3pcap pcap_getnonblock.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2260 foreach(TEMPLATE_MANPAGE ${MANFILE_EXPAND})
2261 string(REPLACE ".manfile.in" ".${MAN_FILE_FORMATS}" MANPAGE ${TEMPLATE_MANPAGE})
2262 configure_file(${CMAKE_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY)
2263 set(MANFILE ${MANFILE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE})
2264 endforeach(TEMPLATE_MANPAGE)
2265 install(FILES ${MANFILE} DESTINATION ${CMAKE_INSTALL_MANDIR}/man${MAN_FILE_FORMATS})
2268 foreach(TEMPLATE_MANPAGE ${MANMISC_EXPAND})
2269 string(REPLACE ".manmisc.in" ".${MAN_MISC_INFO}" MANPAGE ${TEMPLATE_MANPAGE})
2270 configure_file(${CMAKE_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY)
2271 set(MANMISC ${MANMISC} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE})
2272 endforeach(TEMPLATE_MANPAGE)
2273 install(FILES ${MANMISC} DESTINATION ${CMAKE_INSTALL_MANDIR}/man${MAN_MISC_INFO})
2278 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
2279 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
2282 add_custom_target(uninstall
2283 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)