3 # We need 3.12 or later, so that we can set policy CMP0074; see
6 cmake_minimum_required(VERSION 3.12)
11 # if this is a version of CMake less than 3.5, require only
12 # 2.8.12, just in case somebody is configuring with CMake
13 # on a "long-term support" version # of some OS and that
14 # version supplies an older version of CMake;
16 # otherwise, if it's a version less than 3.10, require only
17 # 3.5, just in case somebody is configuring with CMake
18 # on a "long-term support" version # of some OS and that
19 # version supplies an older version of CMake;
21 # otherwise, require 3.10, so we don't get messages warning
22 # that support for versions of CMake lower than 3.10 is
25 if(CMAKE_VERSION VERSION_LESS "3.5")
26 cmake_minimum_required(VERSION 2.8.12)
27 elseif(CMAKE_VERSION VERSION_LESS "3.10")
28 cmake_minimum_required(VERSION 3.5)
30 cmake_minimum_required(VERSION 3.10)
35 # We want find_path() and find_library() to honor {packagename}_ROOT,
36 # as that appears to be the standard way to say "hey, look here for
37 # this package" from the command line.
40 cmake_policy(SET CMP0074 NEW)
46 # When building on NetBSD, with a libpcap installed from pkgsrc,
47 # a -Wl,-rpath,/usr/pkg/lib option is added to the options when
48 # linking tcpdump. This puts /usr/pkg/lib into the run-time path.
50 # However, by default, CMake adds a rule to the install CMake script
51 # a CMake command (using an undocumented subcommand of file()) that
52 # strips /usr/pkg/lib *out* of the run-time path; the message in the
53 # output for the "install" target is
55 # -- Set runtime path of "{target-directory}/tcpdump" to ""
57 # I am not certain what the rationale is for doing this, but a
58 # *consequence* of this is that, when you run the installed tcpdump,
59 # it fails to find libpcap.so:
61 # $ {target-directory}/tcpdump -h
62 # {target-directory}/tcpdump: Shared object "libpcap.so.0" not found
64 # It also appears to be the case that, on Ubuntu 22.04, FreeBSD 12,
65 # DragonFly BSD 5.8, OpenBSD 6.6, and Solaris 11.4,
67 # On Ubuntu and Solaris, even if you have a libpcap in /usr/local, you
68 # have to provide not only -I/usr/local/include and -L/usr/local/lib,
69 # you also must provide -Wl,-rpath,/usr/local/lib in order to have
70 # the run-time linker look in /usr/local/lib for libpcap. If it's not
71 # specified, then, if the shared library major version number of the
72 # libpcap in /usr/lib is the same as the shared major version number
73 # of the libpcap in /usr/local/lib, the run-time linker will find the
74 # libpcap in /usr/lib; if the versions are different, the run-time
75 # linker will fail to find the libpcap in /usr/lib, so the program will
78 # We suppress this by setting CMAKE_INSTALL_RPATH_USE_LINK_PATH to TRUE;
79 # as the documentation for that variable says:
81 # Add paths to linker search and installed rpath.
83 # CMAKE_INSTALL_RPATH_USE_LINK_PATH is a boolean that if set to True
84 # will append to the runtime search path (rpath) of installed
85 # binaries any directories outside the project that are in the linker
86 # search path or contain linked library files. The directories are
87 # appended after the value of the INSTALL_RPATH target property.
89 # If, for whatever reason, directories in which we search for external
90 # libraries, other than the standard system library directories, are
91 # added to the executable's rpath in the build process, we most
92 # definitely want them in the installed image's rpath if they are
93 # necessary in order to find the libraries at run time.
95 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
97 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
100 # We explicitly indicate what languages are used in tcpdump to avoid
101 # checking for a C++ compiler.
103 # One reason to avoid that check is that there's no need to waste
104 # configuration time performing it.
106 # Another reason is that:
108 # CMake will try to determine the sizes of some data types, including
109 # void *, early in the process of configuration; apparently, it's done
110 # as part of processing the project() command.
112 # At least as of CMake 2.8.6, it does so by checking the size of
113 # "void *" in C, setting CMAKE_C_SIZEOF_DATA_PTR based on that,
114 # setting CMAKE_SIZEOF_VOID_P to that, and then checking the size
115 # of "void *" in C++, setting CMAKE_CXX_SIZEOF_DATA_PTR based on
116 # that, and then setting CMAKE_SIZEOF_VOID_P to *that*.
118 # The compile tests include whatever C flags may have been provided
119 # to CMake in the CFLAGS and CXXFLAGS environment variables.
121 # If you set an architecture flag such as -m32 or -m64 in CFLAGS
122 # but *not* in CXXFLAGS, the size for C++ will win, and hilarity
125 # Or if, at least on Solaris, you have a newer version of GCC
126 # installed, but *not* a newer version of G++, and you have Oracle
127 # Studio installed, it will find GCC, which will default to building
128 # 64-bit, and Oracle Studio's C++ compiler, which will default to
129 # building 32-bit, the size for C++ will win, and, again, hilarity
135 # Export the size of void * as SIZEOF_VOID_P so that it can be
138 set(SIZEOF_VOID_P "${CMAKE_SIZEOF_VOID_P}")
141 # Show the bit width for which we're compiling.
142 # This can help debug problems if you're dealing with a compiler that
143 # defaults to generating 32-bit code even when running on a 64-bit
144 # platform, and where that platform may provide only 64-bit versions of
145 # libraries that we might use (looking at *you*, Oracle Studio!).
147 if(CMAKE_SIZEOF_VOID_P EQUAL 4)
148 message(STATUS "Building 32-bit")
149 elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
150 message(STATUS "Building 64-bit")
154 # Solaris pkg-config is annoying. For at least one package (D-Bus, I'm
155 # looking at *you*!), there are separate include files for 32-bit and
156 # 64-bit builds (I guess using "unsigned long long" as a 64-bit integer
157 # type on a 64-bit build is like crossing the beams or something), and
158 # there are two separate .pc files, so if we're doing a 32-bit build we
159 # should make sure we look in /usr/lib/pkgconfig for .pc files and if
160 # we're doing a 64-bit build we should make sure we look in
161 # /usr/lib/amd64/pkgconfig for .pc files.
163 if(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_VERSION MATCHES "5[.][0-9.]*")
165 # Note: string(REPLACE) does not appear to support using ENV{...}
166 # as an argument, so we set a variable and then use set() to set
167 # the environment variable.
169 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
171 # 64-bit build. If /usr/lib/pkgconfig appears in the path,
172 # prepend /usr/lib/amd64/pkgconfig to it; otherwise,
173 # put /usr/lib/amd64 at the end.
175 if((NOT DEFINED ENV{PKG_CONFIG_PATH}) OR "$ENV{PKG_CONFIG_PATH}" EQUAL "")
177 # Not set, or empty. Set it to /usr/lib/amd64/pkgconfig.
179 set(fixed_path "/usr/lib/amd64/pkgconfig")
180 elseif("$ENV{PKG_CONFIG_PATH}" MATCHES "/usr/lib/pkgconfig")
182 # It contains /usr/lib/pkgconfig. Prepend
183 # /usr/lib/amd64/pkgconfig to /usr/lib/pkgconfig.
185 string(REPLACE "/usr/lib/pkgconfig"
186 "/usr/lib/amd64/pkgconfig:/usr/lib/pkgconfig"
187 fixed_path "$ENV{PKG_CONFIG_PATH}")
190 # Not empty, but doesn't contain /usr/lib/pkgconfig.
191 # Append /usr/lib/amd64/pkgconfig to it.
193 set(fixed_path "$ENV{PKG_CONFIG_PATH}:/usr/lib/amd64/pkgconfig")
195 set(ENV{PKG_CONFIG_PATH} "${fixed_path}")
196 elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
198 # 32-bit build. If /usr/amd64/lib/pkgconfig appears in the path,
199 # prepend /usr/lib/pkgconfig to it.
201 if("$ENV{PKG_CONFIG_PATH}" MATCHES "/usr/lib/amd64/pkgconfig")
203 # It contains /usr/lib/amd64/pkgconfig. Prepend
204 # /usr/lib/pkgconfig to /usr/lib/amd64/pkgconfig.
206 string(REPLACE "/usr/lib/amd64/pkgconfig"
207 "/usr/lib/pkgconfig:/usr/lib/amd64/pkgconfig"
208 fixed_path "$ENV{PKG_CONFIG_PATH}")
209 set(ENV{PKG_CONFIG_PATH} "${fixed_path}")
215 # For checking if a compiler flag works and adding it if it does.
217 include(CheckCCompilerFlag)
218 macro(check_and_add_compiler_option _option)
219 message(STATUS "Checking C compiler flag ${_option}")
220 string(REPLACE "=" "-" _temp_option_variable ${_option})
221 string(REGEX REPLACE "^-" "" _option_variable ${_temp_option_variable})
222 check_c_compiler_flag("${_option}" ${_option_variable})
223 if(${${_option_variable}})
224 set(C_ADDITIONAL_FLAGS "${C_ADDITIONAL_FLAGS} ${_option}")
229 # If we're building with Visual Studio, we require Visual Studio 2015,
230 # in order to get sufficient C99 compatibility. Check for that.
232 # If not, try the appropriate flag for the compiler to enable C99
235 set(C_ADDITIONAL_FLAGS "")
237 if(MSVC_VERSION LESS 1900)
238 message(FATAL_ERROR "Visual Studio 2015 or later is required")
242 # Treat source files as being in UTF-8 with MSVC if it's not using
243 # the Clang front end.
244 # We assume that UTF-8 source is OK with other compilers and with
245 # MSVC if it's using the Clang front end.
247 if(NOT ${CMAKE_C_COMPILER} MATCHES "clang*")
248 set(C_ADDITIONAL_FLAGS "${C_ADDITIONAL_FLAGS} /utf-8")
249 endif(NOT ${CMAKE_C_COMPILER} MATCHES "clang*")
252 # Try to enable as many C99 features as we can.
253 # At minimum, we want C++/C99-style // comments.
255 # Newer versions of compilers might default to supporting C99, but
256 # older versions may require a special flag.
258 # Prior to CMake 3.1, setting CMAKE_C_STANDARD will not have any effect,
259 # so, unless and until we require CMake 3.1 or later, we have to do it
260 # ourselves on pre-3.1 CMake, so we just do it ourselves on all versions
263 # Note: with CMake 3.1 through 3.5, the only compilers for which CMake
264 # handles CMAKE_C_STANDARD are GCC and Clang. 3.6 adds support only
265 # for Intel C; 3.9 adds support for PGI C, Sun C, and IBM XL C, and
266 # 3.10 adds support for Cray C and IAR C, but no version of CMake has
267 # support for HP C. Therefore, even if we use CMAKE_C_STANDARD with
268 # compilers for which CMake supports it, we may still have to do it
269 # ourselves on other compilers.
271 # See the CMake documentation for the CMAKE_<LANG>_COMPILER_ID variables
272 # for a list of compiler IDs.
274 # XXX - this just tests whether the option works and adds it if it does.
275 # We don't test whether it's necessary in order to get the C99 features
276 # that we use; if we ever have a user who tries to compile with a compiler
277 # that can't be made to support those features, we can add a test to make
278 # sure we actually *have* C99 support.
280 if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR
281 CMAKE_C_COMPILER_ID MATCHES "Clang")
282 check_and_add_compiler_option("-std=gnu99")
283 elseif(CMAKE_C_COMPILER_ID MATCHES "XL")
285 # We want support for extensions picked up for GNU C compatibility,
286 # so we use -qlanglvl=extc99.
288 check_and_add_compiler_option("-qlanglvl=extc99")
289 elseif(CMAKE_C_COMPILER_ID MATCHES "HP")
290 check_and_add_compiler_option("-AC99")
291 elseif(CMAKE_C_COMPILER_ID MATCHES "Sun")
292 check_and_add_compiler_option("-xc99")
293 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
294 check_and_add_compiler_option("-c99")
298 set(LIBRARY_NAME netdissect)
300 ###################################################################
302 ###################################################################
304 option(WITH_SMI "Build with libsmi, if available" ON)
305 option(WITH_CRYPTO "Build with OpenSSL/libressl libcrypto, if available" ON)
306 option(WITH_CAPSICUM "Build with Capsicum security functions, if available" ON)
307 option(WITH_CAP_NG "Use libcap-ng, if available" ON)
308 option(ENABLE_SMB "Build with the SMB dissector" OFF)
311 # String parameters. Neither of them are set, initially; only if the
312 # user explicitly configures them are they set.
314 # WITH_CHROOT is STRING, not PATH, as the directory need not exist
317 set(WITH_CHROOT CACHE STRING
318 "Directory to which to chroot when dropping privileges")
319 set(WITH_USER CACHE STRING
320 "User to whom to set the UID when dropping privileges")
323 # By default, build universal with the appropriate set of architectures
324 # for the OS on which we're doing the build.
326 if(APPLE AND "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "")
328 # Get the major version of Darwin.
330 string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MAJOR "${CMAKE_SYSTEM_VERSION}")
332 if(SYSTEM_VERSION_MAJOR EQUAL 9)
334 # Leopard. Build for x86 and 32-bit PowerPC, with
335 # x86 first. (That's what Apple does.)
337 set(CMAKE_OSX_ARCHITECTURES "i386;ppc")
338 elseif(SYSTEM_VERSION_MAJOR EQUAL 10)
340 # Snow Leopard. Build for x86-64 and x86, with
341 # x86-64 first. (That's what Apple does.)
343 set(CMAKE_OSX_ARCHITECTURES "x86_64;i386")
347 ###################################################################
349 ###################################################################
351 # Get, parse, format and set tcpdump's version string from
352 # [tcpdump_root]/VERSION for later use.
354 # Get MAJOR, MINOR, PATCH & SUFFIX
355 file(STRINGS ${tcpdump_SOURCE_DIR}/VERSION
357 LIMIT_COUNT 1 # Read only the first line
360 ######################################
362 ######################################
365 ${CMAKE_CURRENT_BINARY_DIR}
366 ${tcpdump_SOURCE_DIR}
370 add_definitions(-D__STDC__)
371 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
376 MESSAGE(STATUS "Use STATIC runtime")
378 set (CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /MT")
379 set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MT")
380 set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
381 set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
383 set (CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} /MT")
384 set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /MT")
385 set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
386 set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
388 MESSAGE(STATUS "Use DYNAMIC runtime")
390 set (CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /MD")
391 set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MD")
392 set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD")
393 set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd")
395 set (CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} /MD")
396 set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /MD")
397 set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MD")
398 set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MDd")
399 endif (USE_STATIC_RT)
403 # CMake's definition of "cross-compiling" appears to be "compiling
404 # for an *operating system* other than the one on which the build
407 # This is an inadequate definition, as people build for the same
408 # operating system but a different instruction set, e.g. building
409 # on an IA-32 or x86-64 Linux box for an Arm embedded Linux box,
410 # or building Arm code on an IA-32 or x86-64 Windows box.
412 # So just test whether check_c_source_runs() on a trivial program
413 # works; if not, it's probably because the generated code won't
414 # run on the platform on which we're running.
416 include(CheckCSourceRuns)
417 if (NOT CMAKE_CROSSCOMPILING)
418 check_c_source_runs("
424 CHECK_C_SOURCE_RUNS_WORKS
426 if (NOT CHECK_C_SOURCE_RUNS_WORKS)
427 set(CMAKE_CROSSCOMPILING TRUE)
431 ###################################################################
432 # Detect available platform features
433 ###################################################################
435 include(CMakePushCheckState)
436 include(CheckIncludeFile)
437 include(CheckIncludeFiles)
438 include(CheckFunctionExists)
439 include(CheckLibraryExists)
440 include(CheckSymbolExists)
441 include(CheckStructHasMember)
442 include(CheckVariableExists)
443 include(CheckTypeSize)
446 # Get the size of a time_t, to know whether it's 32-bit or 64-bit. Print it.
448 cmake_push_check_state()
449 set(CMAKE_EXTRA_INCLUDE_FILES time.h)
450 check_type_size("time_t" SIZEOF_TIME_T)
451 if(SIZEOF_TIME_T EQUAL 4)
452 message(STATUS "32-bit time_t")
453 elseif(SIZEOF_TIME_T EQUAL 8)
454 message(STATUS "64-bit time_t")
456 cmake_pop_check_state()
461 check_include_file(rpc/rpc.h HAVE_RPC_RPC_H)
462 check_include_file(net/if.h HAVE_NET_IF_H)
464 check_include_files("rpc/rpc.h;rpc/rpcent.h" HAVE_RPC_RPCENT_H)
465 endif(HAVE_RPC_RPC_H)
470 check_function_exists(strlcat HAVE_STRLCAT)
471 check_function_exists(strlcpy HAVE_STRLCPY)
472 check_function_exists(strdup HAVE_STRDUP)
473 check_function_exists(strsep HAVE_STRSEP)
476 # Find library needed for gethostbyaddr.
477 # NOTE: if you hand check_library_exists as its last argument a variable
478 # that's been set, it skips the test, so we need different variables.
480 set(TCPDUMP_LINK_LIBRARIES "")
483 # We need winsock2.h and ws2tcpip.h.
485 cmake_push_check_state()
486 set(CMAKE_REQUIRED_LIBRARIES ws2_32)
487 check_symbol_exists(gethostbyaddr "winsock2.h;ws2tcpip.h" LIBWS2_32_HAS_GETHOSTBYADDR)
488 cmake_pop_check_state()
489 if(LIBWS2_32_HAS_GETHOSTBYADDR)
490 set(TCPDUMP_LINK_LIBRARIES ws2_32 ${TCPDUMP_LINK_LIBRARIES})
491 else(LIBWS2_32_HAS_GETHOSTBYADDR)
492 message(FATAL_ERROR "gethostbyaddr is required, but wasn't found")
493 endif(LIBWS2_32_HAS_GETHOSTBYADDR)
495 check_function_exists(gethostbyaddr STDLIBS_HAVE_GETHOSTBYADDR)
496 if(NOT STDLIBS_HAVE_GETHOSTBYADDR)
497 check_library_exists(socket gethostbyaddr "" LIBSOCKET_HAS_GETHOSTBYADDR)
498 if(LIBSOCKET_HAS_GETHOSTBYADDR)
499 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} socket)
500 else(LIBSOCKET_HAS_GETHOSTBYADDR)
501 check_library_exists(nsl gethostbyaddr "" LIBNSL_HAS_GETHOSTBYADDR)
502 if(LIBNSL_HAS_GETHOSTBYADDR)
503 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} nsl)
504 else(LIBNSL_HAS_GETHOSTBYADDR)
505 check_library_exists(network gethostbyaddr "" LIBNETWORK_HAS_GETHOSTBYADDR)
506 if(LIBNETWORK_HAS_GETHOSTBYADDR)
507 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} network)
508 else(LIBNETWORK_HAS_GETHOSTBYADDR)
509 message(FATAL_ERROR "gethostbyaddr is required, but wasn't found")
510 endif(LIBNETWORK_HAS_GETHOSTBYADDR)
511 endif(LIBNSL_HAS_GETHOSTBYADDR)
512 endif(LIBSOCKET_HAS_GETHOSTBYADDR)
513 endif(NOT STDLIBS_HAVE_GETHOSTBYADDR)
517 # This may require additional libraries.
519 cmake_push_check_state()
520 set(CMAKE_REQUIRED_LIBRARIES ${TCPDUMP_LINK_LIBRARIES})
521 check_function_exists(getservent STDLIBS_HAVE_GETSERVENT)
522 if(STDLIBS_HAVE_GETSERVENT)
523 set(HAVE_GETSERVENT TRUE)
524 else(STDLIBS_HAVE_GETSERVENT)
526 # Some platforms may need -lsocket for getservent.
528 set(CMAKE_REQUIRED_LIBRARIES socket ${TCPDUMP_LINK_LIBRARIES})
529 check_function_exists(getservent LIBSOCKET_HAS_GETSERVENT)
530 if(LIBSOCKET_HAS_GETSERVENT)
531 set(HAVE_GETSERVENT TRUE)
532 set(TCPDUMP_LINK_LIBRARIES socket ${TCPDUMP_LINK_LIBRARIES})
533 endif(LIBSOCKET_HAS_GETSERVENT)
534 endif(STDLIBS_HAVE_GETSERVENT)
535 cmake_pop_check_state()
537 if (NOT CMAKE_CROSSCOMPILING)
539 # Require a proof of suitable snprintf(3), same as in Autoconf.
541 check_c_source_runs("
544 #include <inttypes.h>
545 #include <sys/types.h>
547 #if defined(_WIN32) && !defined(_SSIZE_T_DEFINED)
549 * On UN*Xes, this is a signed integer type of the same size as size_t.
551 * It's not defined by Visual Studio; we assume that ptrdiff_t will
552 * be a type that is a signed integer type of the same size as size_t.
554 typedef ptrdiff_t ssize_t;
558 * Avoid trying to cast negative values to unsigned types, or doing
559 * shifts of signed types, in order not to have the test program fail
560 * if we're building with undefined-behavior sanitizers enabled.
565 unsigned int ui = sizeof(buf);
567 int64_t i64 = INT64_C(0x100000000);
568 uint64_t ui64 = UINT64_C(0x100000000);
570 snprintf(buf, sizeof(buf), \"%zu\", (size_t)ui);
571 if (strncmp(buf, \"100\", sizeof(buf)))
574 snprintf(buf, sizeof(buf), \"%zd\", (ssize_t)(-i));
575 if (strncmp(buf, \"-100\", sizeof(buf)))
578 snprintf(buf, sizeof(buf), \"%\" PRId64, -i64);
579 if (strncmp(buf, \"-4294967296\", sizeof(buf)))
582 snprintf(buf, sizeof(buf), \"0o%\" PRIo64, ui64);
583 if (strncmp(buf, \"0o40000000000\", sizeof(buf)))
586 snprintf(buf, sizeof(buf), \"0x%\" PRIx64, ui64);
587 if (strncmp(buf, \"0x100000000\", sizeof(buf)))
590 snprintf(buf, sizeof(buf), \"%\" PRIu64, ui64);
591 if (strncmp(buf, \"4294967296\", sizeof(buf)))
600 if(NOT SUITABLE_SNPRINTF)
602 "The snprintf(3) implementation in this libc is not suitable,
603 tcpdump would not work correctly even if it managed to compile."
607 message(STATUS "Skipped SUITABLE_SNPRINTF because cross-compiling.")
610 check_function_exists(getopt_long HAVE_GETOPT_LONG)
611 check_function_exists(setlinebuf HAVE_SETLINEBUF)
613 # For Windows, don't need to waste time checking for fork() or vfork().
616 check_function_exists(fork HAVE_FORK)
617 check_function_exists(vfork HAVE_VFORK)
621 # Some platforms may need -lnsl for getrpcbynumber.
623 cmake_push_check_state()
624 set(CMAKE_REQUIRED_LIBRARIES ${TCPDUMP_LINK_LIBRARIES})
625 check_function_exists(getrpcbynumber STDLIBS_HAVE_GETRPCBYNUMBER)
626 if(STDLIBS_HAVE_GETRPCBYNUMBER)
627 set(HAVE_GETRPCBYNUMBER TRUE)
628 else(STDLIBS_HAVE_GETRPCBYNUMBER)
629 set(CMAKE_REQUIRED_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} nsl)
630 check_function_exists(getrpcbynumber LIBNSL_HAS_GETRPCBYNUMBER)
631 if(LIBNSL_HAS_GETRPCBYNUMBER)
632 set(HAVE_GETRPCBYNUMBER TRUE)
633 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} nsl)
634 endif(LIBNSL_HAS_GETRPCBYNUMBER)
635 endif(STDLIBS_HAVE_GETRPCBYNUMBER)
636 cmake_pop_check_state()
639 # This requires the libraries we require, as ether_ntohost might be
640 # in one of those libraries. That means we have to do this after
641 # we check for those libraries.
643 # You are in a twisty little maze of UN*Xes, all different.
644 # Some might not have ether_ntohost().
645 # Some might have it and declare it in <net/ethernet.h>.
646 # Some might have it and declare it in <netinet/ether.h>
647 # Some might have it and declare it in <sys/ethernet.h>.
648 # Some might have it and declare it in <arpa/inet.h>.
649 # Some might have it and declare it in <netinet/if_ether.h>.
650 # Some might have it and not declare it in any header file.
652 # Before you is a C compiler.
654 cmake_push_check_state()
655 set(CMAKE_REQUIRED_LIBRARIES ${TCPDUMP_LINK_LIBRARIES})
656 check_function_exists(ether_ntohost HAVE_ETHER_NTOHOST)
657 if(HAVE_ETHER_NTOHOST)
659 # OK, we have ether_ntohost(). We don't check whether it's buggy,
660 # as we assume any system that has CMake is likely to be new enough
661 # that, if it has ether_ntohost(), whatever bug is checked for in
662 # autotools is fixed; we just decide to use it.
664 set(USE_ETHER_NTOHOST TRUE)
667 # Is it declared in <net/ethernet.h>?
669 # This test fails if we don't have <net/ethernet.h> or if we do
670 # but it doesn't declare ether_ntohost().
672 check_symbol_exists(ether_ntohost net/ethernet.h NET_ETHERNET_H_DECLARES_ETHER_NTOHOST)
673 if(NET_ETHERNET_H_DECLARES_ETHER_NTOHOST)
675 # Yes - we have it declared.
677 set(HAVE_DECL_ETHER_NTOHOST TRUE)
682 if(NOT HAVE_DECL_ETHER_NTOHOST)
684 # No - how about <netinet/ether.h>, as on Linux?
686 # This test fails if we don't have <netinet/ether.h>
687 # or if we do but it doesn't declare ether_ntohost().
689 check_symbol_exists(ether_ntohost netinet/ether.h NETINET_ETHER_H_DECLARES_ETHER_NTOHOST)
690 if(NETINET_ETHER_H_DECLARES_ETHER_NTOHOST)
692 # Yes - we have it declared.
694 set(HAVE_DECL_ETHER_NTOHOST TRUE)
700 if(NOT HAVE_DECL_ETHER_NTOHOST)
702 # No - how about <sys/ethernet.h>, as on Solaris 10 and later?
704 # This test fails if we don't have <sys/ethernet.h>
705 # or if we do but it doesn't declare ether_ntohost().
707 check_symbol_exists(ether_ntohost sys/ethernet.h SYS_ETHERNET_H_DECLARES_ETHER_NTOHOST)
708 if(SYS_ETHERNET_H_DECLARES_ETHER_NTOHOST)
710 # Yes - we have it declared.
712 set(HAVE_DECL_ETHER_NTOHOST TRUE)
718 if(NOT HAVE_DECL_ETHER_NTOHOST)
720 # No, how about <arpa/inet.h>, as on AIX?
722 # This test fails if we don't have <arpa/inet.h>
723 # or if we do but it doesn't declare ether_ntohost().
725 check_symbol_exists(ether_ntohost arpa/inet.h ARPA_INET_H_DECLARES_ETHER_NTOHOST)
726 if(ARPA_INET_H_DECLARES_ETHER_NTOHOST)
728 # Yes - we have it declared.
730 set(HAVE_DECL_ETHER_NTOHOST TRUE)
736 if(NOT HAVE_DECL_ETHER_NTOHOST)
738 # No, how about <netinet/if_ether.h>?
739 # On some platforms, it requires <net/if.h> and
740 # <netinet/in.h>, and we always include it with
741 # both of them, so test it with both of them.
743 # This test fails if we don't have <netinet/if_ether.h>
744 # and the headers we include before it, or if we do but
745 # <netinet/if_ether.h> doesn't declare ether_ntohost().
747 check_symbol_exists(ether_ntohost "sys/types.h;sys/socket.h;net/if.h;netinet/in.h;netinet/if_ether.h" NETINET_IF_ETHER_H_DECLARES_ETHER_NTOHOST)
748 if(NETINET_IF_ETHER_H_DECLARES_ETHER_NTOHOST)
750 # Yes - we have it declared.
752 set(HAVE_DECL_ETHER_NTOHOST TRUE)
756 # After all that, is ether_ntohost() declared?
758 if(NOT HAVE_DECL_ETHER_NTOHOST)
760 # No, we'll have to declare it ourselves.
761 # Do we have "struct ether_addr" if we include<netinet/if_ether.h>?
763 check_struct_has_member("struct ether_addr" octet "sys/types.h;sys/socket.h;net/if.h;netinet/in.h;netinet/if_ether.h" HAVE_STRUCT_ETHER_ADDR)
766 cmake_pop_check_state()
771 # XXX - there's no check_struct() macro that's like check_struct_has_member()
772 # except that it only checks for the existence of the structure type,
773 # so we use check_struct_has_member() and look for ss_family.
777 # Check for IPv6 support.
778 # We just check for AF_INET6 and struct in6_addr.
780 cmake_push_check_state()
782 set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h ws2tcpip.h)
783 check_symbol_exists(AF_INET6 "sys/types.h;ws2tcpip.h" HAVE_AF_INET6)
785 set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h sys/socket.h netinet/in.h)
786 check_symbol_exists(AF_INET6 "sys/types.h;sys/socket.h;netinet/in.h" HAVE_AF_INET6)
788 check_type_size("struct in6_addr" HAVE_STRUCT_IN6_ADDR)
789 cmake_pop_check_state()
790 if(HAVE_AF_INET6 AND HAVE_STRUCT_IN6_ADDR)
791 set(HAVE_OS_IPV6_SUPPORT TRUE)
792 endif(HAVE_AF_INET6 AND HAVE_STRUCT_IN6_ADDR)
794 ######################################
795 # External dependencies
796 ######################################
799 # libpcap/WinPcap/Npcap.
802 find_package(PCAP REQUIRED)
803 include_directories(${PCAP_INCLUDE_DIRS})
805 cmake_push_check_state()
810 set(CMAKE_REQUIRED_INCLUDES ${PCAP_INCLUDE_DIRS})
813 # Check whether we have pcap/pcap-inttypes.h.
814 # If we do, we use that to get the C99 types defined.
816 check_include_file(pcap/pcap-inttypes.h HAVE_PCAP_PCAP_INTTYPES_H)
819 # At compile time HAVE_PCAP_FINDALLDEVS depends on HAVE_PCAP_IF_T.
821 cmake_push_check_state()
822 set(CMAKE_EXTRA_INCLUDE_FILES pcap.h)
823 check_type_size(pcap_if_t PCAP_IF_T)
824 cmake_pop_check_state()
827 # Check for various functions in libpcap/WinPcap/Npcap.
829 cmake_push_check_state()
830 set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARIES})
833 # Check for "pcap_list_datalinks()" and use a substitute version if
834 # it's not present. If it is present, check for "pcap_free_datalinks()";
835 # if it's not present, we don't replace it for now. (We could do so
836 # on UN*X, but not on Windows, where hilarity ensues if a program
837 # built with one version of the MSVC support library tries to free
838 # something allocated by a library built with another version of
839 # the MSVC support library.)
841 check_function_exists(pcap_list_datalinks HAVE_PCAP_LIST_DATALINKS)
842 if(HAVE_PCAP_LIST_DATALINKS)
843 check_function_exists(pcap_free_datalinks HAVE_PCAP_FREE_DATALINKS)
844 endif(HAVE_PCAP_LIST_DATALINKS)
847 # Check for "pcap_datalink_name_to_val()", and use a substitute
848 # version if it's not present. If it is present, check for
849 # "pcap_datalink_val_to_description()", and if we don't have it,
850 # use a substitute version.
852 check_function_exists(pcap_datalink_name_to_val HAVE_PCAP_DATALINK_NAME_TO_VAL)
853 if(HAVE_PCAP_DATALINK_NAME_TO_VAL)
854 check_function_exists(pcap_datalink_val_to_description HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION)
855 endif(HAVE_PCAP_DATALINK_NAME_TO_VAL)
858 # Check for "pcap_set_datalink()"; you can't substitute for it if
859 # it's absent (it has hooks into libpcap), so just define the
860 # HAVE_ value if it's there.
862 check_function_exists(pcap_set_datalink HAVE_PCAP_SET_DATALINK)
865 # Check for "pcap_breakloop()"; you can't substitute for it if
866 # it's absent (it has hooks into the live capture routines),
867 # so just define the HAVE_ value if it's there.
869 check_function_exists(pcap_breakloop HAVE_PCAP_BREAKLOOP)
872 # Check for "pcap_dump_ftell()"; we use a substitute version
873 # if it's not present.
875 check_function_exists(pcap_dump_ftell HAVE_PCAP_DUMP_FTELL)
878 # Do we have the new open API? Check for pcap_create() and for
879 # pcap_statustostr(), and assume that, if we have both of them,
880 # we also have pcap_activate() and the other new routines
881 # introduced in libpcap 1.0.0. (We check for pcap_statustostr()
882 # as well, because WinPcap 4.1.3 screwed up and exported pcap_create()
883 # but not other routines such as pcap_statustostr(), even though it
884 # defined them and even though you really want pcap_statustostr() to
885 # get strings corresponding to some of the status returns from the
888 check_function_exists(pcap_statustostr HAVE_PCAP_STATUSTOSTR)
890 # If we don't have pcap_statustostr(), don't check for pcap_create(),
891 # so we pretend we don't have it.
893 if(HAVE_PCAP_STATUSTOSTR)
894 check_function_exists(pcap_create HAVE_PCAP_CREATE)
895 endif(HAVE_PCAP_STATUSTOSTR)
898 # OK, do we have pcap_set_tstamp_type? If so, assume we have
899 # pcap_list_tstamp_types and pcap_free_tstamp_types as well.
901 check_function_exists(pcap_set_tstamp_type HAVE_PCAP_SET_TSTAMP_TYPE)
904 # And do we have pcap_set_tstamp_precision? If so, we assume
905 # we also have pcap_open_offline_with_tstamp_precision.
907 check_function_exists(pcap_set_tstamp_precision HAVE_PCAP_SET_TSTAMP_PRECISION)
908 endif(HAVE_PCAP_CREATE)
911 # Check for a miscellaneous collection of functions which we use
914 check_function_exists(pcap_findalldevs HAVE_PCAP_FINDALLDEVS)
915 check_function_exists(pcap_dump_flush HAVE_PCAP_DUMP_FLUSH)
916 check_function_exists(pcap_lib_version HAVE_PCAP_LIB_VERSION)
917 if(NOT HAVE_PCAP_LIB_VERSION)
918 # Check for the pcap_version string variable and set HAVE_PCAP_VERSION
919 endif(NOT HAVE_PCAP_LIB_VERSION)
920 check_function_exists(pcap_setdirection HAVE_PCAP_SETDIRECTION)
921 check_function_exists(pcap_set_immediate_mode HAVE_PCAP_SET_IMMEDIATE_MODE)
922 check_function_exists(pcap_dump_ftell64 HAVE_PCAP_DUMP_FTELL64)
924 # macOS Sonoma's libpcap includes stub versions of the remote-
925 # capture APIs. They are exported as "weakly linked symbols".
927 # Xcode 15 offers only a macOS Sonoma SDK, which has a .tbd
928 # file for libpcap that claims it includes those APIs. (Newer
929 # versions of macOS don't provide the system shared libraries,
930 # they only provide the dyld shared cache containing those
931 # libraries, so the OS provides SDKs that include a .tbd file
932 # to use when linking.)
934 # This means that check_function_exists() will think that
935 # the remote-capture APIs are present, including pcap_open()
936 # and pcap_findalldevs_ex().
938 # However, they are *not* present in macOS Ventura and earlier,
939 # which means that building on Ventura with Xcode 15 produces
940 # executables that fail to start because one of those APIs
941 # isn't found in the system libpcap.
943 # Protecting calls to those APIs with __builtin_available()
944 # does not prevent this, because the libpcap header files
945 # in the Sonoma SDK mark them as being first available
946 # in macOS 10.13, just like all the other routines introduced
947 # in libpcap 1.9, even though they're only available if libpcap
948 # is built with remote capture enabled or stub routines are
949 # provided. (A fix to enable this has been checked into the
950 # libpcap repository, and may end up in a later version of
953 # Given all that, and given that the versions of the
954 # remote-capture APIs in Sonoma are stubs that always fail,
955 # there doesn't seem to be any point in checking for pcap_open()
956 # and pcap_findalldevs_ex() if we're linking against the Apple libpcap.
958 # However, if we're *not* linking against the Apple libpcap,
959 # we should check for it, so that we can use it if it's present.
961 # So we check for pcap_open() and pcap_findalldevs_ex() if 1) this isn't
962 # macOS or 2) the the libpcap we found is not a system library, meaning
963 # that its path begins neither with /usr/lib (meaning it's a system
964 # dylib) nor /Application/Xcode.app (meaning it's a file in
968 (PCAP_LIBRARIES MATCHES "/usr/lib/.*" OR
969 PCAP_LIBRARIES MATCHES "/Application/Xcode.app/.*"))
970 check_function_exists(pcap_open HAVE_PCAP_OPEN)
971 check_function_exists(pcap_findalldevs_ex HAVE_PCAP_FINDALLDEVS_EX)
975 # On Windows, check for pcap_wsockinit(); if we don't have it, check for
979 check_function_exists(pcap_wsockinit HAVE_PCAP_WSOCKINIT)
980 if(NOT HAVE_PCAP_WSOCKINIT)
981 check_function_exists(wsockinit HAVE_WSOCKINIT)
982 endif(NOT HAVE_PCAP_WSOCKINIT)
986 # Check for special debugging functions
988 check_function_exists(pcap_set_parser_debug HAVE_PCAP_SET_PARSER_DEBUG)
989 if(NOT HAVE_PCAP_SET_PARSER_DEBUG)
990 # Check whether libpcap defines pcap_debug or yydebug
991 check_variable_exists(pcap_debug HAVE_PCAP_DEBUG)
992 if(NOT HAVE_PCAP_DEBUG)
993 check_variable_exists(yydebug HAVE_YYDEBUG)
994 endif(NOT HAVE_PCAP_DEBUG)
995 endif(NOT HAVE_PCAP_SET_PARSER_DEBUG)
997 check_function_exists(pcap_set_optimizer_debug HAVE_PCAP_SET_OPTIMIZER_DEBUG)
998 check_function_exists(bpf_dump HAVE_BPF_DUMP)
1000 cmake_pop_check_state()
1005 include_directories(SYSTEM ${PCAP_INCLUDE_DIRS})
1006 set(TCPDUMP_LINK_LIBRARIES ${PCAP_LIBRARIES} ${TCPDUMP_LINK_LIBRARIES})
1009 # Optional libraries.
1018 include_directories(SYSTEM ${SMI_INCLUDE_DIRS})
1019 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} ${SMI_LIBRARIES})
1025 # OpenSSL/libressl libcrypto.
1028 find_package(CRYPTO)
1031 # 1) do we have EVP_CIPHER_CTX_new?
1032 # If so, we use it to allocate an EVP_CIPHER_CTX, as
1033 # EVP_CIPHER_CTX may be opaque; otherwise, we allocate
1036 cmake_push_check_state()
1037 set(CMAKE_REQUIRED_LIBRARIES "${CRYPTO_LIBRARIES}")
1039 check_function_exists(EVP_CIPHER_CTX_new HAVE_EVP_CIPHER_CTX_NEW)
1042 # 2) do we have EVP_DecryptInit_ex()?
1043 # If so, we use it, because we need to be able to make two
1044 # "initialize the cipher" calls, one with the cipher and key,
1045 # and one with the IV, and, as of OpenSSL 1.1, You Can't Do That
1046 # with EVP_DecryptInit(), because a call to EVP_DecryptInit() will
1047 # unconditionally clear the context, and if you don't supply a
1048 # cipher, it'll clear the cipher, rendering the context unusable
1049 # and causing a crash.
1051 check_function_exists(EVP_DecryptInit_ex HAVE_EVP_DECRYPTINIT_EX)
1053 cmake_pop_check_state()
1056 # We have libcrypto.
1058 include_directories(SYSTEM ${CRYPTO_INCLUDE_DIRS})
1059 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} ${CRYPTO_LIBRARIES})
1060 set(HAVE_LIBCRYPTO ON)
1065 # Capsicum sandboxing.
1066 # Some of this is in the system library, some of it is in other libraries.
1069 check_include_files("sys/capsicum.h" HAVE_SYS_CAPSICUM_H)
1070 if(HAVE_SYS_CAPSICUM_H)
1071 check_function_exists(cap_enter HAVE_CAP_ENTER)
1072 check_function_exists(cap_rights_limit HAVE_CAP_RIGHTS_LIMIT)
1073 check_function_exists(cap_ioctls_limit HAVE_CAP_IOCTLS_LIMIT)
1074 check_function_exists(openat HAVE_OPENAT)
1075 if(HAVE_CAP_ENTER AND HAVE_CAP_RIGHTS_LIMIT AND
1076 HAVE_CAP_IOCTLS_LIMIT AND HAVE_OPENAT)
1078 # OK, we have the functions we need to support Capsicum.
1080 set(HAVE_CAPSICUM TRUE)
1083 # OK, can we use Casper?
1085 check_library_exists(casper cap_init "" HAVE_CAP_INIT)
1087 cmake_push_check_state()
1088 set(CMAKE_REQUIRED_LIBRARIES casper)
1089 check_library_exists(cap_dns cap_gethostbyaddr "" HAVE_CAP_GETHOSTBYADDR)
1090 cmake_pop_check_state()
1091 if(HAVE_CAP_GETHOSTBYADDR)
1092 set(HAVE_CASPER TRUE)
1093 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} casper cap_dns)
1094 endif(HAVE_CAP_GETHOSTBYADDR)
1095 endif(HAVE_CAP_INIT)
1096 endif(HAVE_CAP_ENTER AND HAVE_CAP_RIGHTS_LIMIT AND
1097 HAVE_CAP_IOCTLS_LIMIT AND HAVE_OPENAT)
1098 endif(HAVE_SYS_CAPSICUM_H)
1099 endif(WITH_CAPSICUM)
1105 check_include_file(cap-ng.h HAVE_CAP_NG_H)
1106 check_library_exists(cap-ng capng_change_id "" HAVE_LIBCAP_NG)
1108 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} cap-ng)
1109 endif(HAVE_LIBCAP_NG)
1112 ###################################################################
1114 ###################################################################
1117 # Check and add warning options if we have a .devel file.
1119 if(EXISTS ${CMAKE_SOURCE_DIR}/.devel OR EXISTS ${CMAKE_BINARY_DIR}/.devel)
1123 if(MSVC AND NOT ${CMAKE_C_COMPILER} MATCHES "clang*")
1125 # MSVC, with Microsoft's front end and code generator.
1126 # "MSVC" is also set for Microsoft's compiler with a Clang
1127 # front end and their code generator ("Clang/C2"), so we
1128 # check for clang.exe and treat that differently.
1130 check_and_add_compiler_option(-Wall)
1132 # Disable some pointless warnings that /Wall turns on.
1134 # Unfortunately, MSVC does not appear to have an equivalent
1135 # to "__attribute__((unused))" to mark a particular function
1136 # parameter as being known to be unused, so that the compiler
1137 # won't warn about it (for example, the function might have
1138 # that parameter because a pointer to it is being used, and
1139 # the signature of that function includes that parameter).
1140 # C++ lets you give a parameter a type but no name, but C
1141 # doesn't have that.
1143 check_and_add_compiler_option(-wd4100)
1145 # In theory, we care whether somebody uses f() rather than
1146 # f(void) to declare a function with no arguments, but, in
1147 # practice, there are places in the Windows header files
1148 # that appear to do that, so we squelch that warning.
1150 check_and_add_compiler_option(-wd4255)
1152 # Windows FD_SET() generates this, so we suppress it.
1154 check_and_add_compiler_option(-wd4548)
1156 # Perhaps testing something #defined to be 0 with #ifdef is an
1157 # error, and it should be tested with #if, but perhaps it's
1158 # not, and Microsoft does that in its headers, so we squelch
1161 check_and_add_compiler_option(-wd4574)
1163 # The Windows headers also test not-defined values in #if, so
1164 # we don't want warnings about that, either.
1166 check_and_add_compiler_option(-wd4668)
1168 # We do *not* care whether some function is, or isn't, going to be
1171 check_and_add_compiler_option(-wd4710)
1172 check_and_add_compiler_option(-wd4711)
1174 # We do *not* care whether we're adding padding bytes after
1175 # structure members.
1177 check_and_add_compiler_option(-wd4820)
1179 # We do *not* care about every single place the compiler would
1180 # have inserted Spectre mitigation if only we had told it to
1181 # do so with /Qspectre. I guess the theory is that it's seeing
1182 # bounds checks that would prevent out-of-bounds loads and that
1183 # those out-of-bounds loads could be done speculatively and that
1184 # the Spectre attack could detect the value of the out-of-bounds
1185 # data *if* it's within our address space, but unless I'm
1186 # missing something I don't see that as being any form of
1189 # XXX - add /Qspectre if that is really worth doing.
1191 check_and_add_compiler_option(-wd5045)
1193 # We do *not* care whether a structure had padding added at
1194 # the end because of __declspec(align) - *we* don't use
1195 # __declspec(align), because the only structures whose layout
1196 # we precisely specify are those that get overlaid on packet
1197 # data, and in those every element is an array of octets so
1198 # that we have full control over the size and alignment, and,
1199 # apparently, jmp_buf has such a declaration on x86, meaning
1200 # that everything that includes netdissect.h, i.e. almost every
1201 # file in tcpdump, gets a warning.
1203 check_and_add_compiler_option(-wd4324)
1206 # Other compilers, including MSVC with a Clang front end and
1207 # Microsoft's code generator. We currently treat them as if
1208 # they might support GCC-style -W options.
1210 check_and_add_compiler_option(-W)
1211 check_and_add_compiler_option(-Wall)
1212 check_and_add_compiler_option(-Wassign-enum)
1213 check_and_add_compiler_option(-Wcast-qual)
1214 check_and_add_compiler_option(-Wmissing-prototypes)
1215 check_and_add_compiler_option(-Wmissing-variable-declarations)
1216 check_and_add_compiler_option(-Wold-style-definition)
1217 if(NOT CMAKE_C_COMPILER_ID MATCHES "Sun")
1218 # In Sun C versions that implement GCC compatibility "-Wpedantic"
1219 # means the same as "-pedantic". The latter is mutually exclusive
1220 # with several other options. One of those is "-xc99", which has
1221 # already been set for Sun C above.
1222 check_and_add_compiler_option(-Wpedantic)
1224 check_and_add_compiler_option(-Wpointer-arith)
1225 check_and_add_compiler_option(-Wpointer-sign)
1226 check_and_add_compiler_option(-Wshadow)
1227 check_and_add_compiler_option(-Wsign-compare)
1228 check_and_add_compiler_option(-Wstrict-prototypes)
1229 check_and_add_compiler_option(-Wundef)
1230 check_and_add_compiler_option(-Wunreachable-code-return)
1231 check_and_add_compiler_option(-Wused-but-marked-unused)
1232 check_and_add_compiler_option(-Wwrite-strings)
1237 # Extra compiler options for the build matrix scripts to request -Werror or
1238 # its equivalent if required. The CMake variable name cannot be CFLAGS
1239 # because that is already used for a different purpose in CMake. Example
1240 # usage: cmake -DEXTRA_CFLAGS='-Wall -Wextra -Werror' ...
1242 if(NOT "${EXTRA_CFLAGS}" STREQUAL "")
1243 # The meaning of EXTRA_CFLAGS is "use the exact specified options, or the
1244 # build risks failing to fail", not "try every specified option, omit those
1245 # that do not work and use the rest". Thus use add_compile_options(), not
1246 # foreach()/check_and_add_compiler_option(). Another reason to do that is
1247 # that the effect lasts in testprogs/ and testprogs/fuzz/.
1248 string(REPLACE " " ";" _extra_cflags_list ${EXTRA_CFLAGS})
1249 add_compile_options(${_extra_cflags_list})
1250 message(STATUS "Added extra compile options (${EXTRA_CFLAGS})")
1253 ######################################
1255 ######################################
1259 # We allow the SMB dissector to be omitted.
1261 set(LOCALSRC ${LOCALSRC}
1266 set(NETDISSECT_SOURCE_LIST_C
1380 print-openflow-1.0.c
1381 print-openflow-1.3.c
1450 # Replace missing functions
1452 foreach(FUNC strlcat strlcpy strdup strsep getservent getopt_long)
1453 string(TOUPPER ${FUNC} FUNC_UPPERCASE)
1454 set(HAVE_FUNC_UPPERCASE HAVE_${FUNC_UPPERCASE})
1455 if(NOT ${HAVE_FUNC_UPPERCASE})
1456 set(NETDISSECT_SOURCE_LIST_C ${NETDISSECT_SOURCE_LIST_C} missing/${FUNC}.c)
1460 add_library(netdissect STATIC
1461 ${NETDISSECT_SOURCE_LIST_C}
1463 if(NOT C_ADDITIONAL_FLAGS STREQUAL "")
1464 set_target_properties(netdissect PROPERTIES COMPILE_FLAGS ${C_ADDITIONAL_FLAGS})
1467 set(TCPDUMP_SOURCE_LIST_C fptype.c tcpdump.c)
1469 if(NOT HAVE_BPF_DUMP)
1470 set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} bpf_dump.c)
1471 endif(NOT HAVE_BPF_DUMP)
1472 if(NOT HAVE_PCAP_DUMP_FTELL)
1473 set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} missing/pcap_dump_ftell.c)
1474 endif(NOT HAVE_PCAP_DUMP_FTELL)
1476 if(NOT HAVE_PCAP_LIST_DATALINKS)
1477 set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} missing/datalinks.c)
1478 endif(NOT HAVE_PCAP_LIST_DATALINKS)
1480 if((NOT HAVE_PCAP_DATALINK_NAME_TO_VAL) OR (NOT HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION))
1481 set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} missing/dlnames.c)
1482 endif((NOT HAVE_PCAP_DATALINK_NAME_TO_VAL) OR (NOT HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION))
1484 set(PROJECT_SOURCE_LIST_C ${NETDISSECT_SOURCE_LIST_C} ${TCPDUMP_SOURCE_LIST_C})
1486 file(GLOB PROJECT_SOURCE_LIST_H
1491 # Assume, by default, no support for shared libraries and V7/BSD
1492 # convention for man pages (devices in section 4, file formats in
1493 # section 5, miscellaneous info in section 7, administrative commands
1494 # and daemons in section 8). Individual cases can override this.
1495 # Individual cases can override this.
1497 set(MAN_FILE_FORMATS 5)
1498 set(MAN_MISC_INFO 7)
1499 if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
1500 # Workaround to enable certain features
1502 elseif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
1504 # Use System V conventions for man pages.
1506 set(MAN_FILE_FORMATS 4)
1507 set(MAN_MISC_INFO 5)
1508 elseif(CMAKE_SYSTEM_NAME STREQUAL "IRIX" OR CMAKE_SYSTEM_NAME STREQUAL "IRIX64")
1510 # Use IRIX conventions for man pages; they're the same as the
1511 # System V conventions, except that they use section 8 for
1512 # administrative commands and daemons.
1514 set(MAN_FILE_FORMATS 4)
1515 set(MAN_MISC_INFO 5)
1516 elseif(CMAKE_SYSTEM_NAME STREQUAL "OSF1")
1518 # DEC OSF/1, a/k/a Digital UNIX, a/k/a Tru64 UNIX.
1519 # Use Tru64 UNIX conventions for man pages; they're the same as the
1520 # System V conventions except that they use section 8 for
1521 # administrative commands and daemons.
1523 set(MAN_FILE_FORMATS 4)
1524 set(MAN_MISC_INFO 5)
1525 elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_VERSION MATCHES "5[.][0-9.]*")
1529 if(CMAKE_SYSTEM_VERSION STREQUAL "5.12")
1532 # Use System V conventions for man pages.
1534 set(MAN_FILE_FORMATS 4)
1535 set(MAN_MISC_INFO 5)
1539 source_group("Source Files" FILES ${PROJECT_SOURCE_LIST_C})
1540 source_group("Header Files" FILES ${PROJECT_SOURCE_LIST_H})
1542 ######################################
1544 ######################################
1546 add_executable(tcpdump ${TCPDUMP_SOURCE_LIST_C})
1547 if(NOT C_ADDITIONAL_FLAGS STREQUAL "")
1548 set_target_properties(tcpdump PROPERTIES COMPILE_FLAGS ${C_ADDITIONAL_FLAGS})
1550 if(NOT "${PCAP_LINK_FLAGS}" STREQUAL "")
1551 set_target_properties(tcpdump PROPERTIES LINK_FLAGS ${PCAP_LINK_FLAGS})
1553 target_link_libraries(tcpdump netdissect ${TCPDUMP_LINK_LIBRARIES})
1555 ######################################
1556 # Write out the config.h file
1557 ######################################
1559 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
1561 ######################################
1562 # Install tcpdump and man pages
1563 ######################################
1566 # "Define GNU standard installation directories", which actually
1567 # are also defined, to some degree, by autotools, and at least
1568 # some of which are general UN*X conventions.
1570 include(GNUInstallDirs)
1572 set(MAN1_EXPAND tcpdump.1.in)
1575 # XXX TODO where to install on Windows?
1577 install(TARGETS tcpdump DESTINATION bin)
1580 # On UN*X, and on Windows when not using MSVC, process man pages and
1581 # arrange that they be installed.
1586 # For each section of the manual for which we have man pages
1587 # that require macro expansion, do the expansion.
1590 foreach(TEMPLATE_MANPAGE ${MAN1_EXPAND})
1591 string(REPLACE ".in" "" MANPAGE ${TEMPLATE_MANPAGE})
1592 configure_file(${CMAKE_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY)
1593 set(MAN1 ${MAN1} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE})
1594 endforeach(TEMPLATE_MANPAGE)
1595 install(FILES ${MAN1} DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
1600 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
1601 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
1604 add_custom_target(uninstall
1605 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
1609 # We try to find the Perl interpreter and, if we do, we have the check
1610 # rule run tests/TESTrun with it, because just trying to run the TESTrun
1611 # script as a command won't work on Windows.
1613 find_program(PERL perl)
1615 message(STATUS "Found perl at ${PERL}")
1616 add_custom_target(check
1617 COMMAND ${PERL} ${CMAKE_SOURCE_DIR}/tests/TESTrun)
1619 message(STATUS "Didn't find perl")