1 cmake_minimum_required(VERSION 2.8.6)
3 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
8 # Try to enable as many C99 features as we can.
9 # At minimum, we want C++/C99-style // comments.
10 # (Sadly, this won't work with CMake prior to 3.1.)
12 set(CMAKE_C_STANDARD 99)
14 set(LIBRARY_NAME netdissect)
16 ###################################################################
18 ###################################################################
20 option(WITH_SMI "Build with libsmi, if available" ON)
21 option(WITH_CRYPTO "Build with OpenSSL/libressl libcrypto, if available" ON)
22 option(WITH_CAPSICUM "Build with Capsicum security functions, if available" ON)
23 option(WITH_CAP_NG "Use libcap-ng, if available" ON)
24 option(ENABLE_SMB "Build with the SMB dissector" ON)
27 # String parameters. Neither of them are set, initially; only if the
28 # user explicitly configures them are they set.
30 # WITH_CHROOT is STRING, not PATH, as the directory need not exist
33 set(WITH_CHROOT CACHE STRING
34 "Directory to which to chroot when dropping privileges")
35 set(WITH_USER CACHE STRING
36 "User to whom to set the UID when dropping privileges")
39 # By default, build universal with the appropriate set of architectures
40 # for the OS on which we're doing the build.
42 if(APPLE AND "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "")
44 # Get the major version of Darwin.
46 string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MAJOR "${CMAKE_SYSTEM_VERSION}")
48 if(SYSTEM_VERSION_MAJOR EQUAL 9)
50 # Leopard. Build for x86 and 32-bit PowerPC, with
51 # x86 first. (That's what Apple does.)
53 set(CMAKE_OSX_ARCHITECTURES "i386;ppc")
54 elseif(SYSTEM_VERSION_MAJOR EQUAL 10)
56 # Snow Leopard. Build for x86-64 and x86, with
57 # x86-64 first. (That's what Apple does.)
59 set(CMAKE_OSX_ARCHITECTURES "x86_64;i386")
63 ###################################################################
65 ###################################################################
67 # Get, parse, format and set tcpdump's version string from
68 # [tcpdump_root]/VERSION for later use.
70 # Get MAJOR, MINOR, PATCH & SUFFIX
71 file(STRINGS ${tcpdump_SOURCE_DIR}/VERSION
73 LIMIT_COUNT 1 # Read only the first line
76 ######################################
78 ######################################
80 add_definitions(-DHAVE_CONFIG_H)
83 ${CMAKE_CURRENT_BINARY_DIR}
88 add_definitions(-D__STDC__)
89 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
94 MESSAGE(STATUS "Use STATIC runtime")
96 set (CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /MT")
97 set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MT")
98 set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
99 set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
101 set (CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} /MT")
102 set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /MT")
103 set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
104 set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
106 MESSAGE(STATUS "Use DYNAMIC runtime")
108 set (CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /MD")
109 set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MD")
110 set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD")
111 set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd")
113 set (CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} /MD")
114 set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /MD")
115 set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MD")
116 set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MDd")
117 endif (USE_STATIC_RT)
120 ###################################################################
121 # Detect available platform features
122 ###################################################################
124 include(CMakePushCheckState)
125 include(CheckIncludeFile)
126 include(CheckIncludeFiles)
127 include(CheckFunctionExists)
128 include(CheckLibraryExists)
129 include(CheckSymbolExists)
130 include(CheckStructHasMember)
131 include(CheckVariableExists)
132 include(CheckTypeSize)
137 check_include_file(fcntl.h HAVE_FCNTL_H)
138 check_include_file(rpc/rpc.h HAVE_RPC_RPC_H)
140 check_include_files("rpc/rpc.h;rpc/rpcent.h" HAVE_RPC_RPCENT_H)
141 endif(HAVE_RPC_RPC_H)
142 check_include_files("sys/types.h;sys/socket.h;net/if.h;net/pfvar.h" HAVE_NET_PFVAR_H)
144 check_include_files("sys/types.h;sys/socket.h;net/if.h;net/pfvar.h;net/if_pflog.h" HAVE_NET_IF_PFLOG_H)
145 if(HAVE_NET_IF_PFLOG_H)
146 set(LOCALSRC print-pflog.c ${LOCALSRC})
147 endif(HAVE_NET_IF_PFLOG_H)
148 endif(HAVE_NET_PFVAR_H)
151 # As the autoconf manual says, AC_HEADER_TIME is obsolete, as all UN*Xes
152 # let you include both time.h and sys/time.h, so just say we can.
154 check_include_file(bitypes.h HAVE_SYS_BITYPES_H)
155 check_include_file(limits.h HAVE_LIMITS_H)
160 check_function_exists(strlcat HAVE_STRLCAT)
161 check_function_exists(strlcpy HAVE_STRLCPY)
162 check_function_exists(strdup HAVE_STRDUP)
163 check_function_exists(strsep HAVE_STRSEP)
166 # Find library needed for gethostbyaddr.
167 # NOTE: if you hand check_library_exists as its last argument a variable
168 # that's been set, it skips the test, so we need different variables.
170 set(TCPDUMP_LINK_LIBRARIES "")
171 check_function_exists(gethostbyaddr STDLIBS_HAVE_GETHOSTBYADDR)
172 if(NOT STDLIBS_HAVE_GETHOSTBYADDR)
173 check_library_exists(socket gethostbyaddr "" LIBSOCKET_HAS_GETHOSTBYADDR)
174 if(LIBSOCKET_HAS_GETHOSTBYADDR)
175 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} socket)
177 check_library_exists(nsl gethostbyaddr "" LIBNSL_HAS_GETHOSTBYADDR)
178 if(LIBNSL_HAS_GETHOSTBYADDR)
179 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} nsl)
185 # This may require additional libraries.
187 cmake_push_check_state()
188 set(CMAKE_REQUIRED_LIBRARIES ${TCPDUMP_LINK_LIBRARIES})
189 check_function_exists(getservent STDLIBS_HAVE_GETSERVENT)
190 if(STDLIBS_HAVE_GETSERVENT)
191 set(HAVE_GETSERVENT TRUE)
192 else(STDLIBS_HAVE_GETSERVENT)
194 # Some platforms may need -lsocket for getservent.
196 set(CMAKE_REQUIRED_LIBRARIES socket ${TCPDUMP_LINK_LIBRARIES})
197 check_function_exists(getservent LIBSOCKET_HAS_GETSERVENT)
198 if(LIBSOCKET_HAS_GETSERVENT)
199 set(HAVE_GETSERVENT TRUE)
200 set(TCPDUMP_LINK_LIBRARIES socket ${TCPDUMP_LINK_LIBRARIES})
201 endif(LIBSOCKET_HAS_GETSERVENT)
202 endif(STDLIBS_HAVE_GETSERVENT)
203 cmake_pop_check_state()
205 check_function_exists(getopt_long HAVE_GETOPT_LONG)
207 # With MSVC 2015, stdio.h defines snprintf() and vsnprintf() as inline
208 # functions, so you need to include stdio.h when testing for them -
209 # check_function_exists() won't do it, you need check_symbol_exists().
211 check_symbol_exists(vsnprintf stdio.h HAVE_VSNPRINTF)
212 check_symbol_exists(snprintf stdio.h HAVE_SNPRINTF)
213 check_function_exists(fork HAVE_FORK)
214 check_function_exists(vfork HAVE_VFORK)
215 check_function_exists(strftime HAVE_STRFTIME)
216 check_function_exists(setlinebuf HAVE_SETLINEBUF)
219 # Some platforms may need -lnsl for getrpcbynumber.
221 cmake_push_check_state()
222 set(CMAKE_REQUIRED_LIBRARIES ${TCPDUMP_LINK_LIBRARIES})
223 check_function_exists(getrpcbynumber STDLIBS_HAVE_GETRPCBYNUMBER)
224 if(STDLIBS_HAVE_GETRPCBYNUMBER)
225 set(HAVE_GETRPCBYNUMBER TRUE)
226 else(STDLIBS_HAVE_GETRPCBYNUMBER)
227 set(CMAKE_REQUIRED_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} nsl)
228 check_function_exists(getrpcbynumber LIBNSL_HAS_GETRPCBYNUMBER)
229 if(LIBNSL_HAS_GETRPCBYNUMBER)
230 set(HAVE_GETRPCBYNUMBER TRUE)
231 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} nsl)
232 endif(LIBNSL_HAS_GETRPCBYNUMBER)
233 endif(STDLIBS_HAVE_GETRPCBYNUMBER)
234 cmake_pop_check_state()
237 # This requires the libraries we require, as ether_ntohost might be
238 # in one of those libraries. That means we have to do this after
239 # we check for those libraries.
241 # You are in a twisty little maze of UN*Xes, all different.
242 # Some might not have ether_ntohost().
243 # Some might have it and declare it in <net/ethernet.h>.
244 # Some might have it and declare it in <netinet/ether.h>
245 # Some might have it and declare it in <sys/ethernet.h>.
246 # Some might have it and declare it in <arpa/inet.h>.
247 # Some might have it and declare it in <netinet/if_ether.h>.
248 # Some might have it and not declare it in any header file.
250 # Before you is a C compiler.
252 cmake_push_check_state()
253 set(CMAKE_REQUIRED_LIBRARIES ${TCPDUMP_LINK_LIBRARIES})
254 check_function_exists(ether_ntohost HAVE_ETHER_NTOHOST)
255 if(HAVE_ETHER_NTOHOST)
257 # OK, we have ether_ntohost(). We don't check whether it's buggy,
258 # as we assume any system that has CMake is likely to be new enough
259 # that, if it has ether_ntohost(), whatever bug is checked for in
260 # autotools is fixed; we just decide to use it.
262 set(USE_ETHER_NTOHOST TRUE)
265 # Is it declared in <net/ethernet.h>?
267 # This test fails if we don't have <net/ethernet.h> or if we do
268 # but it doesn't declare ether_ntohost().
270 check_symbol_exists(ether_ntohost net/ethernet.h NET_ETHERNET_H_DECLARES_ETHER_NTOHOST)
271 if(NET_ETHERNET_H_DECLARES_ETHER_NTOHOST)
273 # Yes - we have it declared.
275 set(HAVE_DECL_ETHER_NTOHOST TRUE)
280 if(NOT HAVE_DECL_ETHER_NTOHOST)
282 # No - how about <netinet/ether.h>, as on Linux?
284 # This test fails if we don't have <netinet/ether.h>
285 # or if we do but it doesn't declare ether_ntohost().
287 check_symbol_exists(ether_ntohost netinet/ether.h NETINET_ETHER_H_DECLARES_ETHER_NTOHOST)
288 if(NETINET_ETHER_H_DECLARES_ETHER_NTOHOST)
290 # Yes - we have it declared.
292 set(HAVE_DECL_ETHER_NTOHOST TRUE)
298 if(NOT HAVE_DECL_ETHER_NTOHOST)
300 # No - how about <sys/ethernet.h>, as on Solaris 10 and later?
302 # This test fails if we don't have <sys/ethernet.h>
303 # or if we do but it doesn't declare ether_ntohost().
305 check_symbol_exists(ether_ntohost sys/ethernet.h SYS_ETHERNET_H_DECLARES_ETHER_NTOHOST)
306 if(SYS_ETHERNET_H_DECLARES_ETHER_NTOHOST)
308 # Yes - we have it declared.
310 set(HAVE_DECL_ETHER_NTOHOST TRUE)
316 if(NOT HAVE_DECL_ETHER_NTOHOST)
318 # No, how about <arpa/inet.h>, as on AIX?
320 # This test fails if we don't have <arpa/inet.h>
321 # or if we do but it doesn't declare ether_ntohost().
323 check_symbol_exists(ether_ntohost arpa/inet.h ARPA_INET_H_DECLARES_ETHER_NTOHOST)
324 if(ARPA_INET_H_DECLARES_ETHER_NTOHOST)
326 # Yes - we have it declared.
328 set(HAVE_DECL_ETHER_NTOHOST TRUE)
334 if(NOT HAVE_DECL_ETHER_NTOHOST)
336 # No, how about <netinet/if_ether.h>?
337 # On some platforms, it requires <net/if.h> and
338 # <netinet/in.h>, and we always include it with
339 # both of them, so test it with both of them.
341 # This test fails if we don't have <netinet/if_ether.h>
342 # and the headers we include before it, or if we do but
343 # <netinet/if_ether.h> doesn't declare ether_ntohost().
345 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)
346 if(NETINET_IF_ETHER_H_DECLARES_ETHER_NTOHOST)
348 # Yes - we have it declared.
350 set(HAVE_DECL_ETHER_NTOHOST TRUE)
354 # After all that, is ether_ntohost() declared?
356 if(NOT HAVE_DECL_ETHER_NTOHOST)
358 # No, we'll have to declare it ourselves.
359 # Do we have "struct ether_addr" if we include<netinet/if_ether.h>?
361 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)
364 cmake_pop_check_state()
366 check_function_exists(dnet_htoa STDLIBS_HAVE_DNET_HTOA)
367 if(STDLIBS_HAVE_DNET_HTOA)
368 set(HAVE_DNET_HTOA TRUE)
369 else(STDLIBS_HAVE_DNET_HTOA)
370 check_library_exists(dnet dnet_htoa "" HAVE_DNET_HTOA)
372 set(TCPDUMP_LINK_LIBRARIES dnet ${TCPDUMP_LINK_LIBRARIES})
373 endif(HAVE_DNET_HTOA)
374 endif(STDLIBS_HAVE_DNET_HTOA)
377 # OK, we have dnet_htoa(). Do we have netdnet/dnetdb.h?
379 check_include_files("sys/types.h;netdnet/dnetdb.h" HAVE_NETDNET_DNETDB_H)
380 if(HAVE_NETDNET_DNETDB_H)
382 # Yes. Does it declare dnet_htoa()?
384 cmake_push_check_state()
385 set(CMAKE_REQUIRED_LIBRARIES dnet)
386 check_symbol_exists(dnet_htoa "sys/types.h;netdnet/dnetdb.h" NETDNET_DNETDB_H_DECLARES_DNET_HTOA)
387 cmake_pop_check_state()
388 endif(HAVE_NETDNET_DNETDB_H)
391 # Do we have netdnet/dn.h?
393 check_include_file(netdnet/dn.h HAVE_NETDNET_DN_H)
394 if(HAVE_NETDNET_DN_H)
396 # Yes. Does it declare struct dn_naddr?
398 cmake_push_check_state()
399 set(CMAKE_EXTRA_INCLUDE_FILES netdnet/dn.h)
400 check_type_size("struct dn_naddr" STRUCT_DN_NADDR)
401 cmake_pop_check_state()
402 endif(HAVE_NETDNET_DN_H)
403 endif(HAVE_DNET_HTOA)
408 # XXX - there's no check_struct() macro that's like check_struct_has_member()
409 # except that it only checks for the existence of the structure type,
410 # so we use check_struct_has_member() and look for ss_family.
412 check_struct_has_member("struct sockaddr_storage" ss_family sys/socket.h HAVE_SOCKADDR_STORAGE)
413 set(CMAKE_EXTRA_INCLUDE_FILES unistd.h sys/socket.h)
414 check_type_size("socklen_t" SOCKLEN_T)
415 set(CMAKE_EXTRA_INCLUDE_FILES unistd.h)
418 # Check for IPv6 support.
419 # We just check for AF_INET6 and struct in6_addr.
421 cmake_push_check_state()
423 set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h ws2tcpip.h)
424 check_symbol_exists(AF_INET6 "sys/types.h;ws2tcpip.h" HAVE_AF_INET6)
426 set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h sys/socket.h netinet/in.h)
427 check_symbol_exists(AF_INET6 "sys/types.h;sys/socket.h;netinet/in.h" HAVE_AF_INET6)
429 check_type_size("struct in6_addr" HAVE_STRUCT_IN6_ADDR)
430 cmake_pop_check_state()
431 if(HAVE_AF_INET6 AND HAVE_STRUCT_IN6_ADDR)
432 set(HAVE_OS_IPV6_SUPPORT TRUE)
433 endif(HAVE_AF_INET6 AND HAVE_STRUCT_IN6_ADDR)
438 check_struct_has_member("struct sockaddr" sa_len sys/socket.h HAVE_SOCKADDR_SA_LEN)
440 ######################################
441 # External dependencies
442 ######################################
448 find_package(PCAP REQUIRED)
449 include_directories(${PCAP_INCLUDE_DIRS})
451 cmake_push_check_state()
456 set(CMAKE_REQUIRED_INCLUDES ${PCAP_INCLUDE_DIRS})
459 # Check whether we have pcap/pcap-inttypes.h.
460 # If we do, we use that to get the C99 types defined.
462 check_include_file(pcap/pcap-inttypes.h HAVE_PCAP_PCAP_INTTYPES_H)
465 # Check for some headers introduced in later versions of libpcap
466 # and used by some printers.
468 # Those headers might use the {u_}intN_t types, so we must include
469 # netdissect-stdinc.h first.
471 set(CMAKE_EXTRA_INCLUDE_FILES netdissect-stdinc.h)
472 check_include_file(pcap/bluetooth.h HAVE_PCAP_BLUETOOTH_H)
473 check_include_file(pcap/nflog.h HAVE_PCAP_NFLOG_H)
474 cmake_pop_check_state()
477 # Check for various functions in libpcap/WinPcap.
479 cmake_push_check_state()
480 set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARIES})
483 # Check for "pcap_list_datalinks()" and use a substitute version if
484 # it's not present. If it is present, check for "pcap_free_datalinks()";
485 # if it's not present, we don't replace it for now. (We could do so
486 # on UN*X, but not on Windows, where hilarity ensues if a program
487 # built with one version of the MSVC support library tries to free
488 # something allocated by a library built with another version of
489 # the MSVC support library.)
491 check_function_exists(pcap_list_datalinks HAVE_PCAP_LIST_DATALINKS)
492 if(HAVE_PCAP_LIST_DATALINKS)
493 check_function_exists(pcap_free_datalinks HAVE_PCAP_FREE_DATALINKS)
494 endif(HAVE_PCAP_LIST_DATALINKS)
497 # Check for "pcap_datalink_name_to_val()", and use a substitute
498 # version if it's not present. If it is present, check for
499 # "pcap_datalink_val_to_description()", and if we don't have it,
500 # use a substitute version.
502 check_function_exists(pcap_datalink_name_to_val HAVE_PCAP_DATALINK_NAME_TO_VAL)
503 if(HAVE_PCAP_DATALINK_NAME_TO_VAL)
504 check_function_exists(pcap_datalink_val_to_description HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION)
505 endif(HAVE_PCAP_DATALINK_NAME_TO_VAL)
508 # Check for "pcap_set_datalink()"; you can't substitute for it if
509 # it's absent (it has hooks into libpcap), so just define the
510 # HAVE_ value if it's there.
512 check_function_exists(pcap_set_datalink HAVE_PCAP_SET_DATALINK)
515 # Check for "pcap_breakloop()"; you can't substitute for it if
516 # it's absent (it has hooks into the live capture routines),
517 # so just define the HAVE_ value if it's there.
519 check_function_exists(pcap_breakloop HAVE_PCAP_BREAKLOOP)
522 # Check for "pcap_dump_ftell()"; we use a substitute version
523 # if it's not present.
525 check_function_exists(pcap_dump_ftell HAVE_PCAP_DUMP_FTELL)
528 # Do we have the new open API? Check for pcap_create, and assume that,
529 # if we do, we also have pcap_activate() and the other new routines
530 # introduced in libpcap 1.0.0.
532 check_function_exists(pcap_create HAVE_PCAP_CREATE)
535 # OK, do we have pcap_set_tstamp_type? If so, assume we have
536 # pcap_list_tstamp_types and pcap_free_tstamp_types as well.
538 check_function_exists(pcap_set_tstamp_type HAVE_PCAP_SET_TSTAMP_TYPE)
541 # And do we have pcap_set_tstamp_precision? If so, we assume
542 # we also have pcap_open_offline_with_tstamp_precision.
544 check_function_exists(pcap_set_tstamp_precision HAVE_PCAP_SET_TSTAMP_PRECISION)
545 endif(HAVE_PCAP_CREATE)
548 # Check for a miscellaneous collection of functions which we use
551 check_function_exists(pcap_findalldevs HAVE_PCAP_FINDALLDEVS)
552 if(HAVE_PCAP_FINDALLDEVS)
554 # Check for libpcap having pcap_findalldevs() but the pcap.h header
555 # not having pcap_if_t; some versions of Mac OS X shipped with pcap.h
556 # from 0.6 and libpcap 0.8, so that libpcap had pcap_findalldevs but
557 # pcap.h didn't have pcap_if_t.
559 cmake_push_check_state()
560 set(CMAKE_REQUIRED_INCLUDES ${PCAP_INCLUDE_DIRS})
561 set(CMAKE_EXTRA_INCLUDE_FILES pcap.h)
562 check_type_size(pcap_if_t PCAP_IF_T)
563 cmake_pop_check_state()
564 endif(HAVE_PCAP_FINDALLDEVS)
565 check_function_exists(pcap_dump_flush HAVE_PCAP_DUMP_FLUSH)
566 check_function_exists(pcap_lib_version HAVE_PCAP_LIB_VERSION)
567 if(NOT HAVE_PCAP_LIB_VERSION)
568 # Check for the pcap_version string variable and set HAVE_PCAP_VERSION
569 endif(NOT HAVE_PCAP_LIB_VERSION)
570 check_function_exists(pcap_setdirection HAVE_PCAP_SETDIRECTION)
571 check_function_exists(pcap_set_immediate_mode HAVE_PCAP_SET_IMMEDIATE_MODE)
572 check_function_exists(pcap_dump_ftell64 HAVE_PCAP_DUMP_FTELL64)
573 check_function_exists(pcap_open HAVE_PCAP_OPEN)
574 check_function_exists(pcap_findalldevs_ex HAVE_PCAP_FINDALLDEVS_EX)
577 # Check for special debugging functions
579 check_function_exists(pcap_set_parser_debug HAVE_PCAP_SET_PARSER_DEBUG)
580 if(NOT HAVE_PCAP_SET_PARSER_DEBUG)
581 # Check whether libpcap defines pcap_debug or yydebug
582 check_variable_exists(pcap_debug HAVE_PCAP_DEBUG)
583 if(NOT HAVE_PCAP_DEBUG)
584 check_variable_exists(yydebug HAVE_YYDEBUG)
585 endif(NOT HAVE_PCAP_DEBUG)
586 endif(NOT HAVE_PCAP_SET_PARSER_DEBUG)
588 check_function_exists(pcap_set_optimizer_debug HAVE_PCAP_SET_OPTIMIZER_DEBUG)
589 check_function_exists(bpf_dump HAVE_BPF_DUMP)
591 cmake_pop_check_state()
596 include_directories(SYSTEM ${PCAP_INCLUDE_DIRS})
597 set(TCPDUMP_LINK_LIBRARIES ${PCAP_LIBRARIES} ${TCPDUMP_LINK_LIBRARIES})
600 # Optional libraries.
608 include_directories(SYSTEM ${SMI_INCLUDE_DIRS})
609 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} ${SMI_LIBRARIES})
615 # OpenSSL/libressl libcrypto.
621 # Check for some functions.
623 cmake_push_check_state()
624 set(CMAKE_REQUIRED_LIBRARIES crypto)
627 # 1) do we have EVP_CIPHER_CTX_new?
628 # If so, we use it to allocate an EVP_CIPHER_CTX, as
629 # EVP_CIPHER_CTX may be opaque; otherwise, we allocate
632 check_function_exists(EVP_CIPHER_CTX_new HAVE_EVP_CIPHER_CTX_NEW)
635 # 2) do we have EVP_CipherInit_ex()?
636 # If so, we use it, because we need to be able to make two
637 # "initialize the cipher" calls, one with the cipher and key,
638 # and one with the IV, and, as of OpenSSL 1.1, You Can't Do That
639 # with EVP_CipherInit(), because a call to EVP_CipherInit() will
640 # unconditionally clear the context, and if you don't supply a
641 # cipher, it'll clear the cipher, rendering the context unusable
642 # and causing a crash.
644 check_function_exists(EVP_CipherInit_ex HAVE_EVP_CIPHERINIT_EX)
646 cmake_pop_check_state()
651 include_directories(SYSTEM ${CRYPTO_INCLUDE_DIRS})
652 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} ${CRYPTO_LIBRARIES})
653 set(HAVE_LIBCRYPTO ON)
658 # Capsicum sandboxing.
659 # Some of this is in the system library, some of it is in other libraries.
662 check_function_exists(cap_enter HAVE_CAP_ENTER)
663 check_function_exists(cap_rights_limit HAVE_CAP_RIGHTS_LIMIT)
664 check_function_exists(cap_ioctls_limit HAVE_CAP_IOCTLS_LIMIT)
665 check_function_exists(openat HAVE_OPENAT)
666 if(HAVE_CAP_ENTER AND HAVE_CAP_RIGHTS_LIMIT AND
667 HAVE_CAP_IOCTLS_LIMIT AND HAVE_OPENAT)
669 # OK, we have the functions we need to support Capsicum.
671 set(HAVE_CAPSICUM TRUE)
674 # OK, can we use Casper?
676 check_library_exists(casper cap_init "" HAVE_CAP_INIT)
678 cmake_push_check_state()
679 set(CMAKE_REQUIRED_LIBRARIES casper)
680 check_library_exists(cap_dns cap_gethostbyaddr "" HAVE_CAP_GETHOSTBYADDR)
681 cmake_pop_check_state()
682 if(HAVE_CAP_GETHOSTBYADDR)
683 set(HAVE_CASPER TRUE)
684 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} casper cap_dns)
685 endif(HAVE_CAP_GETHOSTBYADDR)
687 endif(HAVE_CAP_ENTER AND HAVE_CAP_RIGHTS_LIMIT AND
688 HAVE_CAP_IOCTLS_LIMIT AND HAVE_OPENAT)
695 check_include_file(cap-ng.h HAVE_CAP_NG_H)
696 check_library_exists(cap-ng capng_change_id "" HAVE_LIBCAP_NG)
698 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} cap-ng)
699 endif(HAVE_LIBCAP_NG)
702 ######################################
704 ######################################
708 # We allow the SMB dissector to be omitted.
710 set(LOCALSRC ${LOCALSRC}
715 set(NETDISSECT_SOURCE_LIST_C
883 # Replace missing functions
885 foreach(FUNC strlcat strlcpy strdup strsep getservent getopt_long)
886 string(TOUPPER ${FUNC} FUNC_UPPERCASE)
887 set(HAVE_FUNC_UPPERCASE HAVE_${FUNC_UPPERCASE})
888 if(NOT ${HAVE_FUNC_UPPERCASE})
889 set(NETDISSECT_SOURCE_LIST_C ${NETDISSECT_SOURCE_LIST_C} missing/${FUNC}.c)
892 if(NOT HAVE_VSNPRINTF OR NOT HAVE_SNPRINTF)
894 set(NETDISSECT_SOURCE_LIST_C ${NETDISSECT_SOURCE_LIST_C} missing/win_snprintf.c)
896 set(NETDISSECT_SOURCE_LIST_C ${NETDISSECT_SOURCE_LIST_C} missing/snprintf.c)
898 endif(NOT HAVE_VSNPRINTF OR NOT HAVE_SNPRINTF)
900 add_library(netdissect STATIC
901 ${NETDISSECT_SOURCE_LIST_C}
904 set(TCPDUMP_SOURCE_LIST_C tcpdump.c)
906 if(NOT HAVE_BPF_DUMP)
907 set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} bpf_dump.c)
908 endif(NOT HAVE_BPF_DUMP)
909 if(NOT HAVE_PCAP_DUMP_FTELL)
910 set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} missing/pcap_dump_ftell.c)
911 endif(NOT HAVE_PCAP_DUMP_FTELL)
913 if(NOT HAVE_PCAP_LIST_DATALINKS)
914 set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} missing/datalinks.c)
915 endif(NOT HAVE_PCAP_LIST_DATALINKS)
917 if((NOT HAVE_PCAP_DATALINK_NAME_TO_VAL) OR (NOT HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION))
918 set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} missing/dlnames.c)
919 endif((NOT HAVE_PCAP_DATALINK_NAME_TO_VAL) OR (NOT HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION))
921 set(PROJECT_SOURCE_LIST_C ${NETDISSECT_SOURCE_LIST_C} ${TCPDUMP_SOURCE_LIST_C})
923 file(GLOB PROJECT_SOURCE_LIST_H
927 source_group("Source Files" FILES ${PROJECT_SOURCE_LIST_C})
928 source_group("Header Files" FILES ${PROJECT_SOURCE_LIST_H})
930 ######################################
932 ######################################
934 add_executable(tcpdump ${TCPDUMP_SOURCE_LIST_C})
935 target_link_libraries(tcpdump netdissect ${TCPDUMP_LINK_LIBRARIES})
937 ######################################
938 # Write out the config.h file
939 ######################################
941 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
943 ######################################
944 # Install tcpdump and man pages
945 ######################################
948 # "Define GNU standard installation directories", which actually
949 # are also defined, to some degree, by autotools, and at least
950 # some of which are general UN*X conventions.
952 include(GNUInstallDirs)
954 set(MAN1_EXPAND tcpdump.1.in)
957 # XXX TODO where to install on Windows?
959 install(TARGETS tcpdump DESTINATION sbin)
962 # On UN*X, and on Windows when not using MSVC, process man pages and
963 # arrange that they be installed.
968 # For each section of the manual for which we have man pages
969 # that require macro expansion, do the expansion.
972 foreach(TEMPLATE_MANPAGE ${MAN1_EXPAND})
973 string(REPLACE ".in" "" MANPAGE ${TEMPLATE_MANPAGE})
974 configure_file(${CMAKE_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY)
975 set(MAN1 ${MAN1} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE})
976 endforeach(TEMPLATE_MANPAGE)
977 install(FILES ${MAN1} DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
982 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
983 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
986 add_custom_target(uninstall
987 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)