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