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