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