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