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