1if(WIN32) 2 # 3 # We need 3.12 or later, so that we can set policy CMP0074; see 4 # below. 5 cmake_minimum_required(VERSION 3.12) 6else(WIN32) 7 # 8 # For now, require only 2.8.6, just in case somebody is 9 # configuring with CMake on a "long-term support" version 10 # of some OS and that version supplies an older version of 11 # CMake. 12 # 13 # If this is ever updated to CMake 3.1 or later, remove the 14 # stuff in cmake/Modules/FindPCAP.cmake that appends subdirectories 15 # of directories from CMAKE_PREFIX_PATH to the PKG_CONFIG_PATH 16 # environment variable when running pkg-config, to make sure 17 # it finds any .pc file from there. 18 # 19 cmake_minimum_required(VERSION 2.8.12) 20endif(WIN32) 21 22# 23# We want find_path() and find_library() to honor {packagename}_ROOT, 24# as that appears to be the standard way to say "hey, look here for 25# this package" from the command line. 26# 27if(POLICY CMP0074) 28 cmake_policy(SET CMP0074 NEW) 29endif() 30 31# 32# OK, this is a pain. 33# 34# When building on NetBSD, with a libpcap installed from pkgsrc, 35# a -Wl,-rpath,/usr/pkg/lib option is added to the options when 36# linking tcpdump. This puts /usr/pkg/lib into the run-time path. 37# 38# However, by default, CMake adds a rule to the install CMake script 39# a CMake command (using an undocumented subcommand of file()) that 40# strips /usr/pkg/lib *out* of the run-time path; the message in the 41# output for the "install" target is 42# 43# -- Set runtime path of "{target-directory}/tcpdump" to "" 44# 45# I am not certain what the rationale is for doing this, but a 46# *consequence* of this is that, when you run the installed tcpdump, 47# it fails to find libpcap.so: 48# 49# $ {target-directory}/tcpdump -h 50# {target-directory}/tcpdump: Shared object "libpcap.so.0" not found 51# 52# It also appears to be the case that, on Ubuntu 22.04, FreeBSD 12, 53# DragonFly BSD 5.8, OpenBSD 6.6, and Solaris 11.4, 54# 55# On Ubuntu and Solaris, even if you have a libpcap in /usr/local, you 56# have to provide not only -I/usr/local/include and -L/usr/local/lib, 57# you also must provide -Wl,-rpath,/usr/local/lib in order to have 58# the run-time linker look in /usr/local/lib for libpcap. If it's not 59# specified, then, if the shared library major version number of the 60# libpcap in /usr/lib is the same as the shared major version number 61# of the libpcap in /usr/local/lib, the run-time linker will find the 62# libpcap in /usr/lib; if the versions are different, the run-time 63# linker will fail to find the libpcap in /usr/lib, so the program will 64# fail to run. 65# 66# We suppress this by setting CMAKE_INSTALL_RPATH_USE_LINK_PATH to TRUE; 67# as the documentation for that variable says: 68# 69# Add paths to linker search and installed rpath. 70# 71# CMAKE_INSTALL_RPATH_USE_LINK_PATH is a boolean that if set to True 72# will append to the runtime search path (rpath) of installed 73# binaries any directories outside the project that are in the linker 74# search path or contain linked library files. The directories are 75# appended after the value of the INSTALL_RPATH target property. 76# 77# If, for whatever reason, directories in which we search for external 78# libraries, other than the standard system library directories, are 79# added to the executable's rpath in the build process, we most 80# defintely want them in the installed image's rpath if they are 81# necessary in order to find the libraries at run time. 82# 83set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) 84 85set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules) 86 87# 88# OK, this is a royal pain. 89# 90# CMake will try to determine the sizes of some data types, including 91# void *, early in the process of configuration; apparently, it's done 92# as part of processing the project() command. 93# 94# At least as of CMake 2.8.6, it does so by checking the size of 95# "void *" in C, setting CMAKE_C_SIZEOF_DATA_PTR based on that, 96# setting CMAKE_SIZEOF_VOID_P to that, and then checking the size 97# of "void *" in C++, setting CMAKE_CXX_SIZEOF_DATA_PTR based on 98# that, and then setting CMAKE_SIZEOF_VOID_P to *that*. 99# 100# The compile tests include whatever C flags may have been provided 101# to CMake in the CFLAGS and CXXFLAGS environment variables. 102# 103# If you set an architecture flag such as -m32 or -m64 in CFLAGS 104# but *not* in CXXFLAGS, the size for C++ will win, and hilarity 105# will ensue. 106# 107# Or if, at least on Solaris, you have a newer version of GCC 108# installed, but *not* a newer version of G++, and you have Oracle 109# Studio installed, it will find GCC, which will default to building 110# 64-bit, and Oracle Studio's C++ compiler, which will default to 111# building 32-bit, the size for C++ will win, and, again, hilarity 112# will ensue. 113# 114# So we *explicitly* state that only C is used; there is currently no 115# C++ code in tcpdump. 116# 117project(tcpdump C) 118 119# 120# For checking if a compiler flag works and adding it if it does. 121# 122include(CheckCCompilerFlag) 123macro(check_and_add_compiler_option _option) 124 message(STATUS "Checking C compiler flag ${_option}") 125 string(REPLACE "=" "-" _temp_option_variable ${_option}) 126 string(REGEX REPLACE "^-" "" _option_variable ${_temp_option_variable}) 127 check_c_compiler_flag("${_option}" ${_option_variable}) 128 if(${${_option_variable}}) 129 set(C_ADDITIONAL_FLAGS "${C_ADDITIONAL_FLAGS} ${_option}") 130 endif() 131endmacro() 132 133# 134# If we're building with Visual Studio, we require Visual Studio 2015, 135# in order to get sufficient C99 compatibility. Check for that. 136# 137# If not, try the appropriate flag for the compiler to enable C99 138# features. 139# 140set(C_ADDITIONAL_FLAGS "") 141if(MSVC) 142 if(MSVC_VERSION LESS 1900) 143 message(FATAL_ERROR "Visual Studio 2015 or later is required") 144 endif() 145 146 # 147 # Treat source files as being in UTF-8 with MSVC if it's not using 148 # the Clang front end. 149 # We assume that UTF-8 source is OK with other compilers and with 150 # MSVC if it's using the Clang front end. 151 # 152 if(NOT ${CMAKE_C_COMPILER} MATCHES "clang*") 153 set(C_ADDITIONAL_FLAGS "${C_ADDITIONAL_FLAGS} /utf-8") 154 endif(NOT ${CMAKE_C_COMPILER} MATCHES "clang*") 155else(MSVC) 156 # 157 # Try to enable as many C99 features as we can. 158 # At minimum, we want C++/C99-style // comments. 159 # 160 # Newer versions of compilers might default to supporting C99, but 161 # older versions may require a special flag. 162 # 163 # Prior to CMake 3.1, setting CMAKE_C_STANDARD will not have any effect, 164 # so, unless and until we require CMake 3.1 or later, we have to do it 165 # ourselves on pre-3.1 CMake, so we just do it ourselves on all versions 166 # of CMake. 167 # 168 # Note: with CMake 3.1 through 3.5, the only compilers for which CMake 169 # handles CMAKE_C_STANDARD are GCC and Clang. 3.6 adds support only 170 # for Intel C; 3.9 adds support for PGI C, Sun C, and IBM XL C, and 171 # 3.10 adds support for Cray C and IAR C, but no version of CMake has 172 # support for HP C. Therefore, even if we use CMAKE_C_STANDARD with 173 # compilers for which CMake supports it, we may still have to do it 174 # ourselves on other compilers. 175 # 176 # See the CMake documentation for the CMAKE_<LANG>_COMPILER_ID variables 177 # for a list of compiler IDs. 178 # 179 # XXX - this just tests whether the option works and adds it if it does. 180 # We don't test whether it's necessary in order to get the C99 features 181 # that we use; if we ever have a user who tries to compile with a compiler 182 # that can't be made to support those features, we can add a test to make 183 # sure we actually *have* C99 support. 184 # 185 if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR 186 CMAKE_C_COMPILER_ID MATCHES "Clang") 187 check_and_add_compiler_option("-std=gnu99") 188 elseif(CMAKE_C_COMPILER_ID MATCHES "XL") 189 # 190 # We want support for extensions picked up for GNU C compatibility, 191 # so we use -qlanglvl=extc99. 192 # 193 check_and_add_compiler_option("-qlanglvl=extc99") 194 elseif(CMAKE_C_COMPILER_ID MATCHES "HP") 195 check_and_add_compiler_option("-AC99") 196 elseif(CMAKE_C_COMPILER_ID MATCHES "Sun") 197 check_and_add_compiler_option("-xc99") 198 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel") 199 check_and_add_compiler_option("-c99") 200 endif() 201endif(MSVC) 202 203set(LIBRARY_NAME netdissect) 204 205################################################################### 206# Parameters 207################################################################### 208 209option(WITH_SMI "Build with libsmi, if available" ON) 210option(WITH_CRYPTO "Build with OpenSSL/libressl libcrypto, if available" ON) 211option(WITH_CAPSICUM "Build with Capsicum security functions, if available" ON) 212option(WITH_CAP_NG "Use libcap-ng, if available" ON) 213option(ENABLE_SMB "Build with the SMB dissector" OFF) 214 215# 216# String parameters. Neither of them are set, initially; only if the 217# user explicitly configures them are they set. 218# 219# WITH_CHROOT is STRING, not PATH, as the directory need not exist 220# when CMake is run. 221# 222set(WITH_CHROOT CACHE STRING 223 "Directory to which to chroot when dropping privileges") 224set(WITH_USER CACHE STRING 225 "User to whom to set the UID when dropping privileges") 226 227# 228# By default, build universal with the appropriate set of architectures 229# for the OS on which we're doing the build. 230# 231if(APPLE AND "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "") 232 # 233 # Get the major version of Darwin. 234 # 235 string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MAJOR "${CMAKE_SYSTEM_VERSION}") 236 237 if(SYSTEM_VERSION_MAJOR EQUAL 9) 238 # 239 # Leopard. Build for x86 and 32-bit PowerPC, with 240 # x86 first. (That's what Apple does.) 241 # 242 set(CMAKE_OSX_ARCHITECTURES "i386;ppc") 243 elseif(SYSTEM_VERSION_MAJOR EQUAL 10) 244 # 245 # Snow Leopard. Build for x86-64 and x86, with 246 # x86-64 first. (That's what Apple does.) 247 # 248 set(CMAKE_OSX_ARCHITECTURES "x86_64;i386") 249 endif() 250endif() 251 252################################################################### 253# Versioning 254################################################################### 255 256# Get, parse, format and set tcpdump's version string from 257# [tcpdump_root]/VERSION for later use. 258 259# Get MAJOR, MINOR, PATCH & SUFFIX 260file(STRINGS ${tcpdump_SOURCE_DIR}/VERSION 261 PACKAGE_VERSION 262 LIMIT_COUNT 1 # Read only the first line 263) 264 265###################################### 266# Project settings 267###################################### 268 269add_definitions(-DHAVE_CONFIG_H) 270 271include_directories( 272 ${CMAKE_CURRENT_BINARY_DIR} 273 ${tcpdump_SOURCE_DIR} 274) 275 276if(MSVC) 277 add_definitions(-D__STDC__) 278 add_definitions(-D_CRT_SECURE_NO_WARNINGS) 279endif(MSVC) 280 281if(MSVC) 282 if (USE_STATIC_RT) 283 MESSAGE(STATUS "Use STATIC runtime") 284 set(NAME_RT MT) 285 set (CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /MT") 286 set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MT") 287 set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") 288 set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") 289 290 set (CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} /MT") 291 set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /MT") 292 set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT") 293 set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd") 294 else (USE_STATIC_RT) 295 MESSAGE(STATUS "Use DYNAMIC runtime") 296 set(NAME_RT MD) 297 set (CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /MD") 298 set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MD") 299 set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD") 300 set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd") 301 302 set (CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} /MD") 303 set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /MD") 304 set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MD") 305 set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MDd") 306 endif (USE_STATIC_RT) 307endif(MSVC) 308 309################################################################### 310# Detect available platform features 311################################################################### 312 313include(CMakePushCheckState) 314include(CheckIncludeFile) 315include(CheckIncludeFiles) 316include(CheckFunctionExists) 317include(CheckLibraryExists) 318include(CheckSymbolExists) 319include(CheckStructHasMember) 320include(CheckVariableExists) 321include(CheckTypeSize) 322 323# 324# Header files. 325# 326check_include_file(fcntl.h HAVE_FCNTL_H) 327check_include_file(rpc/rpc.h HAVE_RPC_RPC_H) 328check_include_file(net/if.h HAVE_NET_IF_H) 329if(HAVE_RPC_RPC_H) 330 check_include_files("rpc/rpc.h;rpc/rpcent.h" HAVE_RPC_RPCENT_H) 331endif(HAVE_RPC_RPC_H) 332 333# 334# Functions. 335# 336check_function_exists(strlcat HAVE_STRLCAT) 337check_function_exists(strlcpy HAVE_STRLCPY) 338check_function_exists(strdup HAVE_STRDUP) 339check_function_exists(strsep HAVE_STRSEP) 340 341# 342# Find library needed for gethostbyaddr. 343# NOTE: if you hand check_library_exists as its last argument a variable 344# that's been set, it skips the test, so we need different variables. 345# 346set(TCPDUMP_LINK_LIBRARIES "") 347if(WIN32) 348 # 349 # We need winsock2.h and ws2tcpip.h. 350 # 351 cmake_push_check_state() 352 set(CMAKE_REQUIRED_LIBRARIES ws2_32) 353 check_symbol_exists(gethostbyaddr "winsock2.h;ws2tcpip.h" LIBWS2_32_HAS_GETHOSTBYADDR) 354 cmake_pop_check_state() 355 if(LIBWS2_32_HAS_GETHOSTBYADDR) 356 set(TCPDUMP_LINK_LIBRARIES ws2_32 ${TCPDUMP_LINK_LIBRARIES}) 357 else(LIBWS2_32_HAS_GETHOSTBYADDR) 358 message(FATAL_ERROR "gethostbyaddr is required, but wasn't found") 359 endif(LIBWS2_32_HAS_GETHOSTBYADDR) 360else(WIN32) 361 check_function_exists(gethostbyaddr STDLIBS_HAVE_GETHOSTBYADDR) 362 if(NOT STDLIBS_HAVE_GETHOSTBYADDR) 363 check_library_exists(socket gethostbyaddr "" LIBSOCKET_HAS_GETHOSTBYADDR) 364 if(LIBSOCKET_HAS_GETHOSTBYADDR) 365 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} socket) 366 else(LIBSOCKET_HAS_GETHOSTBYADDR) 367 check_library_exists(nsl gethostbyaddr "" LIBNSL_HAS_GETHOSTBYADDR) 368 if(LIBNSL_HAS_GETHOSTBYADDR) 369 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} nsl) 370 else(LIBNSL_HAS_GETHOSTBYADDR) 371 message(FATAL_ERROR "gethostbyaddr is required, but wasn't found") 372 endif(LIBNSL_HAS_GETHOSTBYADDR) 373 endif(LIBSOCKET_HAS_GETHOSTBYADDR) 374 endif(NOT STDLIBS_HAVE_GETHOSTBYADDR) 375endif(WIN32) 376 377# 378# This may require additional libraries. 379# 380cmake_push_check_state() 381set(CMAKE_REQUIRED_LIBRARIES ${TCPDUMP_LINK_LIBRARIES}) 382check_function_exists(getservent STDLIBS_HAVE_GETSERVENT) 383if(STDLIBS_HAVE_GETSERVENT) 384 set(HAVE_GETSERVENT TRUE) 385else(STDLIBS_HAVE_GETSERVENT) 386 # 387 # Some platforms may need -lsocket for getservent. 388 # 389 set(CMAKE_REQUIRED_LIBRARIES socket ${TCPDUMP_LINK_LIBRARIES}) 390 check_function_exists(getservent LIBSOCKET_HAS_GETSERVENT) 391 if(LIBSOCKET_HAS_GETSERVENT) 392 set(HAVE_GETSERVENT TRUE) 393 set(TCPDUMP_LINK_LIBRARIES socket ${TCPDUMP_LINK_LIBRARIES}) 394 endif(LIBSOCKET_HAS_GETSERVENT) 395endif(STDLIBS_HAVE_GETSERVENT) 396cmake_pop_check_state() 397 398# 399# Make sure we have vsnprintf() and snprintf(); we require them. 400# We use check_symbol_exists(), as they aren't necessarily external 401# functions - in Visual Studio, for example, they're inline functions 402# calling a common external function. 403# 404check_symbol_exists(vsnprintf "stdio.h" HAVE_VSNPRINTF) 405if(NOT HAVE_VSNPRINTF) 406 message(FATAL_ERROR "vsnprintf() is required but wasn't found") 407endif(NOT HAVE_VSNPRINTF) 408check_symbol_exists(snprintf "stdio.h" HAVE_SNPRINTF) 409if(NOT HAVE_SNPRINTF) 410 message(FATAL_ERROR "snprintf() is required but wasn't found") 411endif() 412 413check_function_exists(getopt_long HAVE_GETOPT_LONG) 414check_function_exists(strftime HAVE_STRFTIME) 415check_function_exists(setlinebuf HAVE_SETLINEBUF) 416# 417# For Windows, don't need to waste time checking for fork() or vfork(). 418# 419if(NOT WIN32) 420 check_function_exists(fork HAVE_FORK) 421 check_function_exists(vfork HAVE_VFORK) 422endif(NOT WIN32) 423 424# 425# Some platforms may need -lnsl for getrpcbynumber. 426# 427cmake_push_check_state() 428set(CMAKE_REQUIRED_LIBRARIES ${TCPDUMP_LINK_LIBRARIES}) 429check_function_exists(getrpcbynumber STDLIBS_HAVE_GETRPCBYNUMBER) 430if(STDLIBS_HAVE_GETRPCBYNUMBER) 431 set(HAVE_GETRPCBYNUMBER TRUE) 432else(STDLIBS_HAVE_GETRPCBYNUMBER) 433 set(CMAKE_REQUIRED_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} nsl) 434 check_function_exists(getrpcbynumber LIBNSL_HAS_GETRPCBYNUMBER) 435 if(LIBNSL_HAS_GETRPCBYNUMBER) 436 set(HAVE_GETRPCBYNUMBER TRUE) 437 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} nsl) 438 endif(LIBNSL_HAS_GETRPCBYNUMBER) 439endif(STDLIBS_HAVE_GETRPCBYNUMBER) 440cmake_pop_check_state() 441 442# 443# This requires the libraries we require, as ether_ntohost might be 444# in one of those libraries. That means we have to do this after 445# we check for those libraries. 446# 447# You are in a twisty little maze of UN*Xes, all different. 448# Some might not have ether_ntohost(). 449# Some might have it and declare it in <net/ethernet.h>. 450# Some might have it and declare it in <netinet/ether.h> 451# Some might have it and declare it in <sys/ethernet.h>. 452# Some might have it and declare it in <arpa/inet.h>. 453# Some might have it and declare it in <netinet/if_ether.h>. 454# Some might have it and not declare it in any header file. 455# 456# Before you is a C compiler. 457# 458cmake_push_check_state() 459set(CMAKE_REQUIRED_LIBRARIES ${TCPDUMP_LINK_LIBRARIES}) 460check_function_exists(ether_ntohost HAVE_ETHER_NTOHOST) 461if(HAVE_ETHER_NTOHOST) 462 # 463 # OK, we have ether_ntohost(). We don't check whether it's buggy, 464 # as we assume any system that has CMake is likely to be new enough 465 # that, if it has ether_ntohost(), whatever bug is checked for in 466 # autotools is fixed; we just decide to use it. 467 # 468 set(USE_ETHER_NTOHOST TRUE) 469 470 # 471 # Is it declared in <net/ethernet.h>? 472 # 473 # This test fails if we don't have <net/ethernet.h> or if we do 474 # but it doesn't declare ether_ntohost(). 475 # 476 check_symbol_exists(ether_ntohost net/ethernet.h NET_ETHERNET_H_DECLARES_ETHER_NTOHOST) 477 if(NET_ETHERNET_H_DECLARES_ETHER_NTOHOST) 478 # 479 # Yes - we have it declared. 480 # 481 set(HAVE_DECL_ETHER_NTOHOST TRUE) 482 endif() 483 # 484 # Did that succeed? 485 # 486 if(NOT HAVE_DECL_ETHER_NTOHOST) 487 # 488 # No - how about <netinet/ether.h>, as on Linux? 489 # 490 # This test fails if we don't have <netinet/ether.h> 491 # or if we do but it doesn't declare ether_ntohost(). 492 # 493 check_symbol_exists(ether_ntohost netinet/ether.h NETINET_ETHER_H_DECLARES_ETHER_NTOHOST) 494 if(NETINET_ETHER_H_DECLARES_ETHER_NTOHOST) 495 # 496 # Yes - we have it declared. 497 # 498 set(HAVE_DECL_ETHER_NTOHOST TRUE) 499 endif() 500 endif() 501 # 502 # Did that succeed? 503 # 504 if(NOT HAVE_DECL_ETHER_NTOHOST) 505 # 506 # No - how about <sys/ethernet.h>, as on Solaris 10 and later? 507 # 508 # This test fails if we don't have <sys/ethernet.h> 509 # or if we do but it doesn't declare ether_ntohost(). 510 # 511 check_symbol_exists(ether_ntohost sys/ethernet.h SYS_ETHERNET_H_DECLARES_ETHER_NTOHOST) 512 if(SYS_ETHERNET_H_DECLARES_ETHER_NTOHOST) 513 # 514 # Yes - we have it declared. 515 # 516 set(HAVE_DECL_ETHER_NTOHOST TRUE) 517 endif() 518 endif() 519 # 520 # Did that succeed? 521 # 522 if(NOT HAVE_DECL_ETHER_NTOHOST) 523 # 524 # No, how about <arpa/inet.h>, as on AIX? 525 # 526 # This test fails if we don't have <arpa/inet.h> 527 # or if we do but it doesn't declare ether_ntohost(). 528 # 529 check_symbol_exists(ether_ntohost arpa/inet.h ARPA_INET_H_DECLARES_ETHER_NTOHOST) 530 if(ARPA_INET_H_DECLARES_ETHER_NTOHOST) 531 # 532 # Yes - we have it declared. 533 # 534 set(HAVE_DECL_ETHER_NTOHOST TRUE) 535 endif() 536 endif() 537 # 538 # Did that succeed? 539 # 540 if(NOT HAVE_DECL_ETHER_NTOHOST) 541 # 542 # No, how about <netinet/if_ether.h>? 543 # On some platforms, it requires <net/if.h> and 544 # <netinet/in.h>, and we always include it with 545 # both of them, so test it with both of them. 546 # 547 # This test fails if we don't have <netinet/if_ether.h> 548 # and the headers we include before it, or if we do but 549 # <netinet/if_ether.h> doesn't declare ether_ntohost(). 550 # 551 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) 552 if(NETINET_IF_ETHER_H_DECLARES_ETHER_NTOHOST) 553 # 554 # Yes - we have it declared. 555 # 556 set(HAVE_DECL_ETHER_NTOHOST TRUE) 557 endif() 558 endif() 559 # 560 # After all that, is ether_ntohost() declared? 561 # 562 if(NOT HAVE_DECL_ETHER_NTOHOST) 563 # 564 # No, we'll have to declare it ourselves. 565 # Do we have "struct ether_addr" if we include<netinet/if_ether.h>? 566 # 567 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) 568 endif() 569endif() 570cmake_pop_check_state() 571 572# 573# Data types. 574# 575# XXX - there's no check_struct() macro that's like check_struct_has_member() 576# except that it only checks for the existence of the structure type, 577# so we use check_struct_has_member() and look for ss_family. 578# 579 580# 581# Check for IPv6 support. 582# We just check for AF_INET6 and struct in6_addr. 583# 584cmake_push_check_state() 585if(WIN32) 586 set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h ws2tcpip.h) 587 check_symbol_exists(AF_INET6 "sys/types.h;ws2tcpip.h" HAVE_AF_INET6) 588else(WIN32) 589 set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h sys/socket.h netinet/in.h) 590 check_symbol_exists(AF_INET6 "sys/types.h;sys/socket.h;netinet/in.h" HAVE_AF_INET6) 591endif(WIN32) 592check_type_size("struct in6_addr" HAVE_STRUCT_IN6_ADDR) 593cmake_pop_check_state() 594if(HAVE_AF_INET6 AND HAVE_STRUCT_IN6_ADDR) 595 set(HAVE_OS_IPV6_SUPPORT TRUE) 596endif(HAVE_AF_INET6 AND HAVE_STRUCT_IN6_ADDR) 597 598###################################### 599# External dependencies 600###################################### 601 602# 603# libpcap/WinPcap/Npcap. 604# First, find it. 605# 606find_package(PCAP REQUIRED) 607include_directories(${PCAP_INCLUDE_DIRS}) 608 609cmake_push_check_state() 610 611# 612# Now check headers. 613# 614set(CMAKE_REQUIRED_INCLUDES ${PCAP_INCLUDE_DIRS}) 615 616# 617# Check whether we have pcap/pcap-inttypes.h. 618# If we do, we use that to get the C99 types defined. 619# 620check_include_file(pcap/pcap-inttypes.h HAVE_PCAP_PCAP_INTTYPES_H) 621 622# 623# Check for various functions in libpcap/WinPcap/Npcap. 624# 625cmake_push_check_state() 626set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARIES}) 627 628# 629# Check for "pcap_list_datalinks()" and use a substitute version if 630# it's not present. If it is present, check for "pcap_free_datalinks()"; 631# if it's not present, we don't replace it for now. (We could do so 632# on UN*X, but not on Windows, where hilarity ensues if a program 633# built with one version of the MSVC support library tries to free 634# something allocated by a library built with another version of 635# the MSVC support library.) 636# 637check_function_exists(pcap_list_datalinks HAVE_PCAP_LIST_DATALINKS) 638if(HAVE_PCAP_LIST_DATALINKS) 639 check_function_exists(pcap_free_datalinks HAVE_PCAP_FREE_DATALINKS) 640endif(HAVE_PCAP_LIST_DATALINKS) 641 642# 643# Check for "pcap_datalink_name_to_val()", and use a substitute 644# version if it's not present. If it is present, check for 645# "pcap_datalink_val_to_description()", and if we don't have it, 646# use a substitute version. 647# 648check_function_exists(pcap_datalink_name_to_val HAVE_PCAP_DATALINK_NAME_TO_VAL) 649if(HAVE_PCAP_DATALINK_NAME_TO_VAL) 650 check_function_exists(pcap_datalink_val_to_description HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION) 651endif(HAVE_PCAP_DATALINK_NAME_TO_VAL) 652 653# 654# Check for "pcap_set_datalink()"; you can't substitute for it if 655# it's absent (it has hooks into libpcap), so just define the 656# HAVE_ value if it's there. 657# 658check_function_exists(pcap_set_datalink HAVE_PCAP_SET_DATALINK) 659 660# 661# Check for "pcap_breakloop()"; you can't substitute for it if 662# it's absent (it has hooks into the live capture routines), 663# so just define the HAVE_ value if it's there. 664# 665check_function_exists(pcap_breakloop HAVE_PCAP_BREAKLOOP) 666 667# 668# Check for "pcap_dump_ftell()"; we use a substitute version 669# if it's not present. 670# 671check_function_exists(pcap_dump_ftell HAVE_PCAP_DUMP_FTELL) 672 673# 674# Do we have the new open API? Check for pcap_create() and for 675# pcap_statustostr(), and assume that, if we have both of them, 676# we also have pcap_activate() and the other new routines 677# introduced in libpcap 1.0.0. (We check for pcap_statustostr() 678# as well, because WinPcap 4.1.3 screwed up and exported pcap_create() 679# but not other routines such as pcap_statustostr(), even though it 680# defined them and even though you really want pcap_statustostr() to 681# get strings corresponding to some of the status returns from the 682# new routines.) 683# 684check_function_exists(pcap_statustostr HAVE_PCAP_STATUSTOSTR) 685# 686# If we don't have pcap_statustostr(), don't check for pcap_create(), 687# so we pretend we don't have it. 688# 689if(HAVE_PCAP_STATUSTOSTR) 690 check_function_exists(pcap_create HAVE_PCAP_CREATE) 691endif(HAVE_PCAP_STATUSTOSTR) 692if(HAVE_PCAP_CREATE) 693 # 694 # OK, do we have pcap_set_tstamp_type? If so, assume we have 695 # pcap_list_tstamp_types and pcap_free_tstamp_types as well. 696 # 697 check_function_exists(pcap_set_tstamp_type HAVE_PCAP_SET_TSTAMP_TYPE) 698 699 # 700 # And do we have pcap_set_tstamp_precision? If so, we assume 701 # we also have pcap_open_offline_with_tstamp_precision. 702 # 703 check_function_exists(pcap_set_tstamp_precision HAVE_PCAP_SET_TSTAMP_PRECISION) 704endif(HAVE_PCAP_CREATE) 705 706# 707# Check for a miscellaneous collection of functions which we use 708# if we have them. 709# 710check_function_exists(pcap_findalldevs HAVE_PCAP_FINDALLDEVS) 711if(HAVE_PCAP_FINDALLDEVS) 712 # 713 # Check for libpcap having pcap_findalldevs() but the pcap.h header 714 # not having pcap_if_t; some versions of Mac OS X shipped with pcap.h 715 # from 0.6 and libpcap 0.8, so that libpcap had pcap_findalldevs but 716 # pcap.h didn't have pcap_if_t. 717 # 718 cmake_push_check_state() 719 set(CMAKE_REQUIRED_INCLUDES ${PCAP_INCLUDE_DIRS}) 720 set(CMAKE_EXTRA_INCLUDE_FILES pcap.h) 721 check_type_size(pcap_if_t PCAP_IF_T) 722 cmake_pop_check_state() 723endif(HAVE_PCAP_FINDALLDEVS) 724check_function_exists(pcap_dump_flush HAVE_PCAP_DUMP_FLUSH) 725check_function_exists(pcap_lib_version HAVE_PCAP_LIB_VERSION) 726if(NOT HAVE_PCAP_LIB_VERSION) 727 # Check for the pcap_version string variable and set HAVE_PCAP_VERSION 728endif(NOT HAVE_PCAP_LIB_VERSION) 729check_function_exists(pcap_setdirection HAVE_PCAP_SETDIRECTION) 730check_function_exists(pcap_set_immediate_mode HAVE_PCAP_SET_IMMEDIATE_MODE) 731check_function_exists(pcap_dump_ftell64 HAVE_PCAP_DUMP_FTELL64) 732check_function_exists(pcap_open HAVE_PCAP_OPEN) 733check_function_exists(pcap_findalldevs_ex HAVE_PCAP_FINDALLDEVS_EX) 734 735# 736# On Windows, check for pcap_wsockinit(); if we don't have it, check for 737# wsockinit(). 738# 739if(WIN32) 740 check_function_exists(pcap_wsockinit HAVE_PCAP_WSOCKINIT) 741 if(NOT HAVE_PCAP_WSOCKINIT) 742 check_function_exists(wsockinit HAVE_WSOCKINIT) 743 endif(NOT HAVE_PCAP_WSOCKINIT) 744endif(WIN32) 745 746# 747# Check for special debugging functions 748# 749check_function_exists(pcap_set_parser_debug HAVE_PCAP_SET_PARSER_DEBUG) 750if(NOT HAVE_PCAP_SET_PARSER_DEBUG) 751 # Check whether libpcap defines pcap_debug or yydebug 752 check_variable_exists(pcap_debug HAVE_PCAP_DEBUG) 753 if(NOT HAVE_PCAP_DEBUG) 754 check_variable_exists(yydebug HAVE_YYDEBUG) 755 endif(NOT HAVE_PCAP_DEBUG) 756endif(NOT HAVE_PCAP_SET_PARSER_DEBUG) 757 758check_function_exists(pcap_set_optimizer_debug HAVE_PCAP_SET_OPTIMIZER_DEBUG) 759check_function_exists(bpf_dump HAVE_BPF_DUMP) 760 761cmake_pop_check_state() 762 763# 764# We have libpcap. 765# 766include_directories(SYSTEM ${PCAP_INCLUDE_DIRS}) 767set(TCPDUMP_LINK_LIBRARIES ${PCAP_LIBRARIES} ${TCPDUMP_LINK_LIBRARIES}) 768 769# 770# Optional libraries. 771# 772 773# 774# libsmi. 775# 776if(WITH_SMI) 777 find_package(SMI) 778 if(SMI_FOUND) 779 include_directories(SYSTEM ${SMI_INCLUDE_DIRS}) 780 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} ${SMI_LIBRARIES}) 781 set(USE_LIBSMI ON) 782 endif(SMI_FOUND) 783endif(WITH_SMI) 784 785# 786# OpenSSL/libressl libcrypto. 787# 788if(WITH_CRYPTO) 789 find_package(CRYPTO) 790 if(CRYPTO_FOUND) 791 # 792 # Check for some headers and functions. 793 # 794 check_include_file(openssl/evp.h HAVE_OPENSSL_EVP_H) 795 796 # 797 # 1) do we have EVP_CIPHER_CTX_new? 798 # If so, we use it to allocate an EVP_CIPHER_CTX, as 799 # EVP_CIPHER_CTX may be opaque; otherwise, we allocate 800 # it ourselves. 801 # 802 cmake_push_check_state() 803 set(CMAKE_REQUIRED_LIBRARIES "${CRYPTO_LIBRARIES}") 804 805 check_function_exists(EVP_CIPHER_CTX_new HAVE_EVP_CIPHER_CTX_NEW) 806 807 # 808 # 2) do we have EVP_DecryptInit_ex()? 809 # If so, we use it, because we need to be able to make two 810 # "initialize the cipher" calls, one with the cipher and key, 811 # and one with the IV, and, as of OpenSSL 1.1, You Can't Do That 812 # with EVP_DecryptInit(), because a call to EVP_DecryptInit() will 813 # unconditionally clear the context, and if you don't supply a 814 # cipher, it'll clear the cipher, rendering the context unusable 815 # and causing a crash. 816 # 817 check_function_exists(EVP_DecryptInit_ex HAVE_EVP_DECRYPTINIT_EX) 818 819 cmake_pop_check_state() 820 821 # 822 # We have libcrypto. 823 # 824 include_directories(SYSTEM ${CRYPTO_INCLUDE_DIRS}) 825 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} ${CRYPTO_LIBRARIES}) 826 set(HAVE_LIBCRYPTO ON) 827 endif(CRYPTO_FOUND) 828endif(WITH_CRYPTO) 829 830# 831# Capsicum sandboxing. 832# Some of this is in the system library, some of it is in other libraries. 833# 834if(WITH_CAPSICUM) 835 check_include_files("sys/capsicum.h" HAVE_SYS_CAPSICUM_H) 836 if(HAVE_SYS_CAPSICUM_H) 837 check_function_exists(cap_enter HAVE_CAP_ENTER) 838 check_function_exists(cap_rights_limit HAVE_CAP_RIGHTS_LIMIT) 839 check_function_exists(cap_ioctls_limit HAVE_CAP_IOCTLS_LIMIT) 840 check_function_exists(openat HAVE_OPENAT) 841 if(HAVE_CAP_ENTER AND HAVE_CAP_RIGHTS_LIMIT AND 842 HAVE_CAP_IOCTLS_LIMIT AND HAVE_OPENAT) 843 # 844 # OK, we have the functions we need to support Capsicum. 845 # 846 set(HAVE_CAPSICUM TRUE) 847 848 # 849 # OK, can we use Casper? 850 # 851 check_library_exists(casper cap_init "" HAVE_CAP_INIT) 852 if(HAVE_CAP_INIT) 853 cmake_push_check_state() 854 set(CMAKE_REQUIRED_LIBRARIES casper) 855 check_library_exists(cap_dns cap_gethostbyaddr "" HAVE_CAP_GETHOSTBYADDR) 856 cmake_pop_check_state() 857 if(HAVE_CAP_GETHOSTBYADDR) 858 set(HAVE_CASPER TRUE) 859 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} casper cap_dns) 860 endif(HAVE_CAP_GETHOSTBYADDR) 861 endif(HAVE_CAP_INIT) 862 endif(HAVE_CAP_ENTER AND HAVE_CAP_RIGHTS_LIMIT AND 863 HAVE_CAP_IOCTLS_LIMIT AND HAVE_OPENAT) 864 endif(HAVE_SYS_CAPSICUM_H) 865endif(WITH_CAPSICUM) 866 867# 868# libcap-ng. 869# 870if(WITH_CAP_NG) 871 check_include_file(cap-ng.h HAVE_CAP_NG_H) 872 check_library_exists(cap-ng capng_change_id "" HAVE_LIBCAP_NG) 873 if(HAVE_LIBCAP_NG) 874 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} cap-ng) 875 endif(HAVE_LIBCAP_NG) 876endif(WITH_CAP_NG) 877 878################################################################### 879# Warning options 880################################################################### 881 882# 883# Check and add warning options if we have a .devel file. 884# 885if(EXISTS ${CMAKE_SOURCE_DIR}/.devel OR EXISTS ${CMAKE_BINARY_DIR}/.devel) 886 # 887 # Warning options. 888 # 889 if(MSVC AND NOT ${CMAKE_C_COMPILER} MATCHES "clang*") 890 # 891 # MSVC, with Microsoft's front end and code generator. 892 # "MSVC" is also set for Microsoft's compiler with a Clang 893 # front end and their code generator ("Clang/C2"), so we 894 # check for clang.exe and treat that differently. 895 # 896 check_and_add_compiler_option(-Wall) 897 # 898 # Disable some pointless warnings that /Wall turns on. 899 # 900 # Unfortunately, MSVC does not appear to have an equivalent 901 # to "__attribute__((unused))" to mark a particular function 902 # parameter as being known to be unused, so that the compiler 903 # won't warn about it (for example, the function might have 904 # that parameter because a pointer to it is being used, and 905 # the signature of that function includes that parameter). 906 # C++ lets you give a parameter a type but no name, but C 907 # doesn't have that. 908 # 909 check_and_add_compiler_option(-wd4100) 910 # 911 # In theory, we care whether somebody uses f() rather than 912 # f(void) to declare a function with no arguments, but, in 913 # practice, there are places in the Windows header files 914 # that appear to do that, so we squelch that warning. 915 # 916 check_and_add_compiler_option(-wd4255) 917 # 918 # Windows FD_SET() generates this, so we suppress it. 919 # 920 check_and_add_compiler_option(-wd4548) 921 # 922 # Perhaps testing something #defined to be 0 with #ifdef is an 923 # error, and it should be tested with #if, but perhaps it's 924 # not, and Microsoft does that in its headers, so we squelch 925 # that warning. 926 # 927 check_and_add_compiler_option(-wd4574) 928 # 929 # The Windows headers also test not-defined values in #if, so 930 # we don't want warnings about that, either. 931 # 932 check_and_add_compiler_option(-wd4668) 933 # 934 # We do *not* care whether some function is, or isn't, going to be 935 # expanded inline. 936 # 937 check_and_add_compiler_option(-wd4710) 938 check_and_add_compiler_option(-wd4711) 939 # 940 # We do *not* care whether we're adding padding bytes after 941 # structure members. 942 # 943 check_and_add_compiler_option(-wd4820) 944 # 945 # We do *not* care about every single place the compiler would 946 # have inserted Spectre mitigation if only we had told it to 947 # do so with /Qspectre. I guess the theory is that it's seeing 948 # bounds checks that would prevent out-of-bounds loads and that 949 # those out-of-bounds loads could be done speculatively and that 950 # the Spectre attack could detect the value of the out-of-bounds 951 # data *if* it's within our address space, but unless I'm 952 # missing something I don't see that as being any form of 953 # security hole. 954 # 955 # XXX - add /Qspectre if that is really worth doing. 956 # 957 check_and_add_compiler_option(-wd5045) 958 # 959 # We do *not* care whether a structure had padding added at 960 # the end because of __declspec(align) - *we* don't use 961 # __declspec(align), because the only structures whose layout 962 # we precisely specify are those that get overlayed on packet 963 # data, and in those every element is an array of octets so 964 # that we have full control over the size and aligmnet, and, 965 # apparently, jmp_buf has such a declaration on x86, meaning 966 # that everything that includes netdissect.h, i.e. almost every 967 # file in tcpdump, gets a warning. 968 # 969 check_and_add_compiler_option(-wd4324) 970 else() 971 # 972 # Other compilers, including MSVC with a Clang front end and 973 # Microsoft's code generator. We currently treat them as if 974 # they might support GCC-style -W options. 975 # 976 check_and_add_compiler_option(-W) 977 check_and_add_compiler_option(-Wall) 978 check_and_add_compiler_option(-Wassign-enum) 979 check_and_add_compiler_option(-Wcast-qual) 980 check_and_add_compiler_option(-Wmissing-prototypes) 981 check_and_add_compiler_option(-Wmissing-variable-declarations) 982 check_and_add_compiler_option(-Wold-style-definition) 983 check_and_add_compiler_option(-Wpedantic) 984 check_and_add_compiler_option(-Wpointer-arith) 985 check_and_add_compiler_option(-Wpointer-sign) 986 check_and_add_compiler_option(-Wshadow) 987 check_and_add_compiler_option(-Wsign-compare) 988 check_and_add_compiler_option(-Wstrict-prototypes) 989 check_and_add_compiler_option(-Wunreachable-code-return) 990 check_and_add_compiler_option(-Wused-but-marked-unused) 991 check_and_add_compiler_option(-Wwrite-strings) 992 endif() 993endif() 994 995# 996# Extra compiler options for the build matrix scripts to request -Werror or 997# its equivalent if required. The CMake variable name cannot be CFLAGS 998# because that is already used for a different purpose in CMake. Example 999# usage: cmake -DEXTRA_CFLAGS='-Wall -Wextra -Werror' ... 1000# 1001if(NOT "${EXTRA_CFLAGS}" STREQUAL "") 1002 foreach(_extra_cflag ${EXTRA_CFLAGS}) 1003 check_and_add_compiler_option("${_extra_cflag}") 1004 endforeach(_extra_cflag) 1005 message(STATUS "Added extra compile options (${EXTRA_CFLAGS})") 1006endif() 1007 1008###################################### 1009# Input files 1010###################################### 1011 1012if(ENABLE_SMB) 1013 # 1014 # We allow the SMB dissector to be omitted. 1015 # 1016 set(LOCALSRC ${LOCALSRC} 1017 print-smb.c 1018 smbutil.c) 1019endif(ENABLE_SMB) 1020 1021set(NETDISSECT_SOURCE_LIST_C 1022 addrtoname.c 1023 addrtostr.c 1024 af.c 1025 ascii_strcasecmp.c 1026 checksum.c 1027 cpack.c 1028 gmpls.c 1029 in_cksum.c 1030 ipproto.c 1031 l2vpn.c 1032 machdep.c 1033 netdissect.c 1034 netdissect-alloc.c 1035 nlpid.c 1036 oui.c 1037 ntp.c 1038 parsenfsfh.c 1039 print.c 1040 print-802_11.c 1041 print-802_15_4.c 1042 print-ah.c 1043 print-ahcp.c 1044 print-aodv.c 1045 print-aoe.c 1046 print-ap1394.c 1047 print-arcnet.c 1048 print-arista.c 1049 print-arp.c 1050 print-ascii.c 1051 print-atalk.c 1052 print-atm.c 1053 print-babel.c 1054 print-bcm-li.c 1055 print-beep.c 1056 print-bfd.c 1057 print-bgp.c 1058 print-bootp.c 1059 print-brcmtag.c 1060 print-bt.c 1061 print-calm-fast.c 1062 print-carp.c 1063 print-cdp.c 1064 print-cfm.c 1065 print-chdlc.c 1066 print-cip.c 1067 print-cnfp.c 1068 print-dccp.c 1069 print-decnet.c 1070 print-dhcp6.c 1071 print-domain.c 1072 print-dsa.c 1073 print-dtp.c 1074 print-dvmrp.c 1075 print-eap.c 1076 print-egp.c 1077 print-eigrp.c 1078 print-enc.c 1079 print-esp.c 1080 print-ether.c 1081 print-fddi.c 1082 print-forces.c 1083 print-fr.c 1084 print-frag6.c 1085 print-ftp.c 1086 print-geneve.c 1087 print-geonet.c 1088 print-gre.c 1089 print-hncp.c 1090 print-hsrp.c 1091 print-http.c 1092 print-icmp.c 1093 print-icmp6.c 1094 print-igmp.c 1095 print-igrp.c 1096 print-ip-demux.c 1097 print-ip.c 1098 print-ip6.c 1099 print-ip6opts.c 1100 print-ipcomp.c 1101 print-ipfc.c 1102 print-ipnet.c 1103 print-ipoib.c 1104 print-ipx.c 1105 print-isakmp.c 1106 print-isoclns.c 1107 print-juniper.c 1108 print-krb.c 1109 print-l2tp.c 1110 print-lane.c 1111 print-ldp.c 1112 print-lisp.c 1113 print-llc.c 1114 print-lldp.c 1115 print-lmp.c 1116 print-loopback.c 1117 print-lspping.c 1118 print-lwapp.c 1119 print-lwres.c 1120 print-m3ua.c 1121 print-macsec.c 1122 print-mobile.c 1123 print-mobility.c 1124 print-mpcp.c 1125 print-mpls.c 1126 print-mptcp.c 1127 print-msdp.c 1128 print-msnlb.c 1129 print-nflog.c 1130 print-nfs.c 1131 print-nsh.c 1132 print-ntp.c 1133 print-null.c 1134 print-olsr.c 1135 print-openflow-1.0.c 1136 print-openflow-1.3.c 1137 print-openflow.c 1138 print-ospf.c 1139 print-ospf6.c 1140 print-otv.c 1141 print-pflog.c 1142 print-pgm.c 1143 print-pim.c 1144 print-pktap.c 1145 print-ppi.c 1146 print-ppp.c 1147 print-pppoe.c 1148 print-pptp.c 1149 print-ptp.c 1150 print-radius.c 1151 print-raw.c 1152 print-realtek.c 1153 print-resp.c 1154 print-rip.c 1155 print-ripng.c 1156 print-rpki-rtr.c 1157 print-rsvp.c 1158 print-rt6.c 1159 print-rtsp.c 1160 print-rx.c 1161 print-sctp.c 1162 print-sflow.c 1163 print-sip.c 1164 print-sl.c 1165 print-sll.c 1166 print-slow.c 1167 print-smtp.c 1168 print-snmp.c 1169 print-someip.c 1170 print-ssh.c 1171 print-stp.c 1172 print-sunatm.c 1173 print-sunrpc.c 1174 print-symantec.c 1175 print-syslog.c 1176 print-tcp.c 1177 print-telnet.c 1178 print-tftp.c 1179 print-timed.c 1180 print-tipc.c 1181 print-token.c 1182 print-udld.c 1183 print-udp.c 1184 print-unsupported.c 1185 print-usb.c 1186 print-vjc.c 1187 print-vqp.c 1188 print-vrrp.c 1189 print-vsock.c 1190 print-vtp.c 1191 print-vxlan-gpe.c 1192 print-vxlan.c 1193 print-wb.c 1194 print-whois.c 1195 print-zep.c 1196 print-zephyr.c 1197 print-zeromq.c 1198 ${LOCALSRC} 1199 signature.c 1200 strtoaddr.c 1201 util-print.c 1202) 1203 1204# 1205# Replace missing functions 1206# 1207foreach(FUNC strlcat strlcpy strdup strsep getservent getopt_long) 1208 string(TOUPPER ${FUNC} FUNC_UPPERCASE) 1209 set(HAVE_FUNC_UPPERCASE HAVE_${FUNC_UPPERCASE}) 1210 if(NOT ${HAVE_FUNC_UPPERCASE}) 1211 set(NETDISSECT_SOURCE_LIST_C ${NETDISSECT_SOURCE_LIST_C} missing/${FUNC}.c) 1212 endif() 1213endforeach() 1214 1215add_library(netdissect STATIC 1216 ${NETDISSECT_SOURCE_LIST_C} 1217) 1218if(NOT C_ADDITIONAL_FLAGS STREQUAL "") 1219 set_target_properties(netdissect PROPERTIES COMPILE_FLAGS ${C_ADDITIONAL_FLAGS}) 1220endif() 1221 1222set(TCPDUMP_SOURCE_LIST_C fptype.c tcpdump.c) 1223 1224if(NOT HAVE_BPF_DUMP) 1225 set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} bpf_dump.c) 1226endif(NOT HAVE_BPF_DUMP) 1227if(NOT HAVE_PCAP_DUMP_FTELL) 1228 set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} missing/pcap_dump_ftell.c) 1229endif(NOT HAVE_PCAP_DUMP_FTELL) 1230 1231if(NOT HAVE_PCAP_LIST_DATALINKS) 1232 set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} missing/datalinks.c) 1233endif(NOT HAVE_PCAP_LIST_DATALINKS) 1234 1235if((NOT HAVE_PCAP_DATALINK_NAME_TO_VAL) OR (NOT HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION)) 1236 set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} missing/dlnames.c) 1237endif((NOT HAVE_PCAP_DATALINK_NAME_TO_VAL) OR (NOT HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION)) 1238 1239set(PROJECT_SOURCE_LIST_C ${NETDISSECT_SOURCE_LIST_C} ${TCPDUMP_SOURCE_LIST_C}) 1240 1241file(GLOB PROJECT_SOURCE_LIST_H 1242 *.h 1243) 1244 1245# 1246# Assume, by default, no support for shared libraries and V7/BSD 1247# convention for man pages (devices in section 4, file formats in 1248# section 5, miscellaneous info in section 7, administrative commands 1249# and daemons in section 8). Individual cases can override this. 1250# Individual cases can override this. 1251# 1252set(MAN_FILE_FORMATS 5) 1253set(MAN_MISC_INFO 7) 1254if(CMAKE_SYSTEM_NAME STREQUAL "AIX") 1255 # Workaround to enable certain features 1256 set(_SUN TRUE) 1257elseif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX") 1258 # 1259 # Use System V conventions for man pages. 1260 # 1261 set(MAN_FILE_FORMATS 4) 1262 set(MAN_MISC_INFO 5) 1263elseif(CMAKE_SYSTEM_NAME STREQUAL "IRIX" OR CMAKE_SYSTEM_NAME STREQUAL "IRIX64") 1264 # 1265 # Use IRIX conventions for man pages; they're the same as the 1266 # System V conventions, except that they use section 8 for 1267 # administrative commands and daemons. 1268 # 1269 set(MAN_FILE_FORMATS 4) 1270 set(MAN_MISC_INFO 5) 1271elseif(CMAKE_SYSTEM_NAME STREQUAL "OSF1") 1272 # 1273 # DEC OSF/1, a/k/a Digital UNIX, a/k/a Tru64 UNIX. 1274 # Use Tru64 UNIX conventions for man pages; they're the same as the 1275 # System V conventions except that they use section 8 for 1276 # administrative commands and daemons. 1277 # 1278 set(MAN_FILE_FORMATS 4) 1279 set(MAN_MISC_INFO 5) 1280elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_VERSION MATCHES "5[.][0-9.]*") 1281 # 1282 # SunOS 5.x. 1283 # 1284 if(CMAKE_SYSTEM_VERSION STREQUAL "5.12") 1285 else() 1286 # 1287 # Use System V conventions for man pages. 1288 # 1289 set(MAN_FILE_FORMATS 4) 1290 set(MAN_MISC_INFO 5) 1291 endif() 1292endif() 1293 1294source_group("Source Files" FILES ${PROJECT_SOURCE_LIST_C}) 1295source_group("Header Files" FILES ${PROJECT_SOURCE_LIST_H}) 1296 1297###################################### 1298# Register targets 1299###################################### 1300 1301add_executable(tcpdump ${TCPDUMP_SOURCE_LIST_C}) 1302if(NOT C_ADDITIONAL_FLAGS STREQUAL "") 1303 set_target_properties(tcpdump PROPERTIES COMPILE_FLAGS ${C_ADDITIONAL_FLAGS}) 1304endif() 1305target_link_libraries(tcpdump netdissect ${TCPDUMP_LINK_LIBRARIES}) 1306 1307###################################### 1308# Write out the config.h file 1309###################################### 1310 1311configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h) 1312 1313###################################### 1314# Install tcpdump and man pages 1315###################################### 1316 1317# 1318# "Define GNU standard installation directories", which actually 1319# are also defined, to some degree, by autotools, and at least 1320# some of which are general UN*X conventions. 1321# 1322include(GNUInstallDirs) 1323 1324set(MAN1_EXPAND tcpdump.1.in) 1325 1326if(WIN32) 1327 # XXX TODO where to install on Windows? 1328else(WIN32) 1329 install(TARGETS tcpdump DESTINATION bin) 1330endif(WIN32) 1331 1332# On UN*X, and on Windows when not using MSVC, process man pages and 1333# arrange that they be installed. 1334if(NOT MSVC) 1335 # 1336 # Man pages. 1337 # 1338 # For each section of the manual for which we have man pages 1339 # that require macro expansion, do the expansion. 1340 # 1341 set(MAN1 "") 1342 foreach(TEMPLATE_MANPAGE ${MAN1_EXPAND}) 1343 string(REPLACE ".in" "" MANPAGE ${TEMPLATE_MANPAGE}) 1344 configure_file(${CMAKE_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY) 1345 set(MAN1 ${MAN1} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE}) 1346 endforeach(TEMPLATE_MANPAGE) 1347 install(FILES ${MAN1} DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) 1348endif(NOT MSVC) 1349 1350# uninstall target 1351configure_file( 1352 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" 1353 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" 1354 IMMEDIATE @ONLY) 1355 1356add_custom_target(uninstall 1357 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) 1358 1359# 1360# Tcpdump tests 1361# We try to find the Perl interpreter and, if we do, we have the check 1362# rule run tests/TESTrun with it, because just trying to run the TESTrun 1363# script as a command won't work on Windows. 1364# 1365find_program(PERL perl) 1366if(PERL) 1367 message(STATUS "Found perl at ${PERL}") 1368 add_custom_target(check 1369 COMMAND ${PERL} ${CMAKE_SOURCE_DIR}/tests/TESTrun) 1370else() 1371 message(STATUS "Didn't find perl") 1372endif() 1373