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