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