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