]> The Tcpdump Group git mirrors - tcpdump/blob - CMakeLists.txt
Add a malloc/free process with garbage collector
[tcpdump] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8.6)
2
3 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
4
5 project(tcpdump)
6
7 #
8 # Try to enable as many C99 features as we can.
9 # At minimum, we want C++/C99-style // comments.
10 # (Sadly, this won't work with CMake prior to 3.1.)
11 #
12 set(CMAKE_C_STANDARD 99)
13
14 set(LIBRARY_NAME netdissect)
15
16 ###################################################################
17 # Parameters
18 ###################################################################
19
20 option(WITH_SMI "Build with libsmi, if available" ON)
21 option(WITH_CRYPTO "Build with OpenSSL/libressl libcrypto, if available" ON)
22 option(WITH_CAPSICUM "Build with Capsicum security functions, if available" ON)
23 option(WITH_CAP_NG "Use libcap-ng, if available" ON)
24 option(ENABLE_SMB "Build with the SMB dissector" ON)
25
26 #
27 # String parameters. Neither of them are set, initially; only if the
28 # user explicitly configures them are they set.
29 #
30 # WITH_CHROOT is STRING, not PATH, as the directory need not exist
31 # when CMake is run.
32 #
33 set(WITH_CHROOT CACHE STRING
34 "Directory to which to chroot when dropping privileges")
35 set(WITH_USER CACHE STRING
36 "User to whom to set the UID when dropping privileges")
37
38 #
39 # By default, build universal with the appropriate set of architectures
40 # for the OS on which we're doing the build.
41 #
42 if(APPLE AND "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "")
43 #
44 # Get the major version of Darwin.
45 #
46 string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MAJOR "${CMAKE_SYSTEM_VERSION}")
47
48 if(SYSTEM_VERSION_MAJOR EQUAL 9)
49 #
50 # Leopard. Build for x86 and 32-bit PowerPC, with
51 # x86 first. (That's what Apple does.)
52 #
53 set(CMAKE_OSX_ARCHITECTURES "i386;ppc")
54 elseif(SYSTEM_VERSION_MAJOR EQUAL 10)
55 #
56 # Snow Leopard. Build for x86-64 and x86, with
57 # x86-64 first. (That's what Apple does.)
58 #
59 set(CMAKE_OSX_ARCHITECTURES "x86_64;i386")
60 endif()
61 endif()
62
63 ###################################################################
64 # Versioning
65 ###################################################################
66
67 # Get, parse, format and set tcpdump's version string from
68 # [tcpdump_root]/VERSION for later use.
69
70 # Get MAJOR, MINOR, PATCH & SUFFIX
71 file(STRINGS ${tcpdump_SOURCE_DIR}/VERSION
72 PACKAGE_VERSION
73 LIMIT_COUNT 1 # Read only the first line
74 )
75
76 ######################################
77 # Project settings
78 ######################################
79
80 add_definitions(-DHAVE_CONFIG_H)
81
82 include_directories(
83 ${CMAKE_CURRENT_BINARY_DIR}
84 ${tcpdump_SOURCE_DIR}
85 )
86
87 if(MSVC)
88 add_definitions(-D__STDC__)
89 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
90 endif(MSVC)
91
92 if(MSVC)
93 if (USE_STATIC_RT)
94 MESSAGE(STATUS "Use STATIC runtime")
95 set(NAME_RT MT)
96 set (CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /MT")
97 set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MT")
98 set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
99 set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
100
101 set (CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} /MT")
102 set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /MT")
103 set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
104 set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
105 else (USE_STATIC_RT)
106 MESSAGE(STATUS "Use DYNAMIC runtime")
107 set(NAME_RT MD)
108 set (CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /MD")
109 set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MD")
110 set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD")
111 set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd")
112
113 set (CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} /MD")
114 set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /MD")
115 set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MD")
116 set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MDd")
117 endif (USE_STATIC_RT)
118 endif(MSVC)
119
120 ###################################################################
121 # Detect available platform features
122 ###################################################################
123
124 include(CMakePushCheckState)
125 include(CheckIncludeFile)
126 include(CheckIncludeFiles)
127 include(CheckFunctionExists)
128 include(CheckLibraryExists)
129 include(CheckSymbolExists)
130 include(CheckStructHasMember)
131 include(CheckVariableExists)
132 include(CheckTypeSize)
133
134 #
135 # Header files.
136 #
137 check_include_file(fcntl.h HAVE_FCNTL_H)
138 check_include_file(rpc/rpc.h HAVE_RPC_RPC_H)
139 if(HAVE_RPC_RPC_H)
140 check_include_files("rpc/rpc.h;rpc/rpcent.h" HAVE_RPC_RPCENT_H)
141 endif(HAVE_RPC_RPC_H)
142 if(NOT WIN32)
143 check_include_files("sys/types.h;sys/socket.h;net/if.h;net/pfvar.h" HAVE_NET_PFVAR_H)
144 if(HAVE_NET_PFVAR_H)
145 check_include_files("sys/types.h;sys/socket.h;net/if.h;net/pfvar.h;net/if_pflog.h" HAVE_NET_IF_PFLOG_H)
146 if(HAVE_NET_IF_PFLOG_H)
147 set(LOCALSRC print-pflog.c ${LOCALSRC})
148 endif(HAVE_NET_IF_PFLOG_H)
149 endif(HAVE_NET_PFVAR_H)
150 endif(NOT WIN32)
151
152 #
153 # Functions.
154 #
155 check_function_exists(strlcat HAVE_STRLCAT)
156 check_function_exists(strlcpy HAVE_STRLCPY)
157 check_function_exists(strdup HAVE_STRDUP)
158 check_function_exists(strsep HAVE_STRSEP)
159
160 #
161 # Find library needed for gethostbyaddr.
162 # NOTE: if you hand check_library_exists as its last argument a variable
163 # that's been set, it skips the test, so we need different variables.
164 #
165 set(TCPDUMP_LINK_LIBRARIES "")
166 if(WIN32)
167 #
168 # We need winsock2.h and ws2tcpip.h.
169 #
170 cmake_push_check_state()
171 set(CMAKE_REQUIRED_LIBRARIES ws2_32)
172 check_symbol_exists(gethostbyaddr "winsock2.h;ws2tcpip.h" LIBWS2_32_HAS_GETHOSTBYADDR)
173 cmake_pop_check_state()
174 if(LIBWS2_32_HAS_GETHOSTBYADDR)
175 set(TCPDUMP_LINK_LIBRARIES ws2_32 ${TCPDUMP_LINK_LIBRARIES})
176 else(LIBWS2_32_HAS_GETHOSTBYADDR)
177 message(FATAL_ERROR "gethostbyaddr is required, but wasn't found")
178 endif(LIBWS2_32_HAS_GETHOSTBYADDR)
179 else(WIN32)
180 check_function_exists(gethostbyaddr STDLIBS_HAVE_GETHOSTBYADDR)
181 if(NOT STDLIBS_HAVE_GETHOSTBYADDR)
182 check_library_exists(socket gethostbyaddr "" LIBSOCKET_HAS_GETHOSTBYADDR)
183 if(LIBSOCKET_HAS_GETHOSTBYADDR)
184 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} socket)
185 else(LIBSOCKET_HAS_GETHOSTBYADDR)
186 check_library_exists(nsl gethostbyaddr "" LIBNSL_HAS_GETHOSTBYADDR)
187 if(LIBNSL_HAS_GETHOSTBYADDR)
188 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} nsl)
189 else(LIBNSL_HAS_GETHOSTBYADDR)
190 message(FATAL_ERROR "gethostbyaddr is required, but wasn't found")
191 endif(LIBNSL_HAS_GETHOSTBYADDR)
192 endif(LIBSOCKET_HAS_GETHOSTBYADDR)
193 endif(NOT STDLIBS_HAVE_GETHOSTBYADDR)
194 endif(WIN32)
195
196 #
197 # This may require additional libraries.
198 #
199 cmake_push_check_state()
200 set(CMAKE_REQUIRED_LIBRARIES ${TCPDUMP_LINK_LIBRARIES})
201 check_function_exists(getservent STDLIBS_HAVE_GETSERVENT)
202 if(STDLIBS_HAVE_GETSERVENT)
203 set(HAVE_GETSERVENT TRUE)
204 else(STDLIBS_HAVE_GETSERVENT)
205 #
206 # Some platforms may need -lsocket for getservent.
207 #
208 set(CMAKE_REQUIRED_LIBRARIES socket ${TCPDUMP_LINK_LIBRARIES})
209 check_function_exists(getservent LIBSOCKET_HAS_GETSERVENT)
210 if(LIBSOCKET_HAS_GETSERVENT)
211 set(HAVE_GETSERVENT TRUE)
212 set(TCPDUMP_LINK_LIBRARIES socket ${TCPDUMP_LINK_LIBRARIES})
213 endif(LIBSOCKET_HAS_GETSERVENT)
214 endif(STDLIBS_HAVE_GETSERVENT)
215 cmake_pop_check_state()
216
217 check_function_exists(getopt_long HAVE_GETOPT_LONG)
218 #
219 # For Windows, either
220 #
221 # 1) we're using VS 2015, in which case we have both snprintf()
222 # and vsnprintf(), and they behave in a C99-compliant fashion,
223 # so we use them
224 #
225 # or
226 #
227 # 2) we're not, and we don't have snprintf(), and we either don't
228 # have vsnprintf() or we have one that *doesn't* behave in a
229 # C99-compliant fashion, but we *do* have _snprintf_s() and
230 # _vsnprintf_s(), so we wrap them with #defines
231 #
232 # and we test for both of them at compile time, so we don't need to
233 # check for snprintf() or vsnprintf() here.
234 #
235 # XXX - do we need to care about UN*Xes that don't have snprintf()
236 # or vsnprintf() any more?
237 #
238 # We also don't need to waste time checking for fork() or vfork().
239 #
240 if(NOT WIN32)
241 check_function_exists(vsnprintf HAVE_VSNPRINTF)
242 check_function_exists(snprintf HAVE_SNPRINTF)
243 check_function_exists(fork HAVE_FORK)
244 check_function_exists(vfork HAVE_VFORK)
245 endif(NOT WIN32)
246 check_function_exists(strftime HAVE_STRFTIME)
247 check_function_exists(setlinebuf HAVE_SETLINEBUF)
248
249 #
250 # Some platforms may need -lnsl for getrpcbynumber.
251 #
252 cmake_push_check_state()
253 set(CMAKE_REQUIRED_LIBRARIES ${TCPDUMP_LINK_LIBRARIES})
254 check_function_exists(getrpcbynumber STDLIBS_HAVE_GETRPCBYNUMBER)
255 if(STDLIBS_HAVE_GETRPCBYNUMBER)
256 set(HAVE_GETRPCBYNUMBER TRUE)
257 else(STDLIBS_HAVE_GETRPCBYNUMBER)
258 set(CMAKE_REQUIRED_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} nsl)
259 check_function_exists(getrpcbynumber LIBNSL_HAS_GETRPCBYNUMBER)
260 if(LIBNSL_HAS_GETRPCBYNUMBER)
261 set(HAVE_GETRPCBYNUMBER TRUE)
262 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} nsl)
263 endif(LIBNSL_HAS_GETRPCBYNUMBER)
264 endif(STDLIBS_HAVE_GETRPCBYNUMBER)
265 cmake_pop_check_state()
266
267 #
268 # This requires the libraries we require, as ether_ntohost might be
269 # in one of those libraries. That means we have to do this after
270 # we check for those libraries.
271 #
272 # You are in a twisty little maze of UN*Xes, all different.
273 # Some might not have ether_ntohost().
274 # Some might have it and declare it in <net/ethernet.h>.
275 # Some might have it and declare it in <netinet/ether.h>
276 # Some might have it and declare it in <sys/ethernet.h>.
277 # Some might have it and declare it in <arpa/inet.h>.
278 # Some might have it and declare it in <netinet/if_ether.h>.
279 # Some might have it and not declare it in any header file.
280 #
281 # Before you is a C compiler.
282 #
283 cmake_push_check_state()
284 set(CMAKE_REQUIRED_LIBRARIES ${TCPDUMP_LINK_LIBRARIES})
285 check_function_exists(ether_ntohost HAVE_ETHER_NTOHOST)
286 if(HAVE_ETHER_NTOHOST)
287 #
288 # OK, we have ether_ntohost(). We don't check whether it's buggy,
289 # as we assume any system that has CMake is likely to be new enough
290 # that, if it has ether_ntohost(), whatever bug is checked for in
291 # autotools is fixed; we just decide to use it.
292 #
293 set(USE_ETHER_NTOHOST TRUE)
294
295 #
296 # Is it declared in <net/ethernet.h>?
297 #
298 # This test fails if we don't have <net/ethernet.h> or if we do
299 # but it doesn't declare ether_ntohost().
300 #
301 check_symbol_exists(ether_ntohost net/ethernet.h NET_ETHERNET_H_DECLARES_ETHER_NTOHOST)
302 if(NET_ETHERNET_H_DECLARES_ETHER_NTOHOST)
303 #
304 # Yes - we have it declared.
305 #
306 set(HAVE_DECL_ETHER_NTOHOST TRUE)
307 endif()
308 #
309 # Did that succeed?
310 #
311 if(NOT HAVE_DECL_ETHER_NTOHOST)
312 #
313 # No - how about <netinet/ether.h>, as on Linux?
314 #
315 # This test fails if we don't have <netinet/ether.h>
316 # or if we do but it doesn't declare ether_ntohost().
317 #
318 check_symbol_exists(ether_ntohost netinet/ether.h NETINET_ETHER_H_DECLARES_ETHER_NTOHOST)
319 if(NETINET_ETHER_H_DECLARES_ETHER_NTOHOST)
320 #
321 # Yes - we have it declared.
322 #
323 set(HAVE_DECL_ETHER_NTOHOST TRUE)
324 endif()
325 endif()
326 #
327 # Did that succeed?
328 #
329 if(NOT HAVE_DECL_ETHER_NTOHOST)
330 #
331 # No - how about <sys/ethernet.h>, as on Solaris 10 and later?
332 #
333 # This test fails if we don't have <sys/ethernet.h>
334 # or if we do but it doesn't declare ether_ntohost().
335 #
336 check_symbol_exists(ether_ntohost sys/ethernet.h SYS_ETHERNET_H_DECLARES_ETHER_NTOHOST)
337 if(SYS_ETHERNET_H_DECLARES_ETHER_NTOHOST)
338 #
339 # Yes - we have it declared.
340 #
341 set(HAVE_DECL_ETHER_NTOHOST TRUE)
342 endif()
343 endif()
344 #
345 # Did that succeed?
346 #
347 if(NOT HAVE_DECL_ETHER_NTOHOST)
348 #
349 # No, how about <arpa/inet.h>, as on AIX?
350 #
351 # This test fails if we don't have <arpa/inet.h>
352 # or if we do but it doesn't declare ether_ntohost().
353 #
354 check_symbol_exists(ether_ntohost arpa/inet.h ARPA_INET_H_DECLARES_ETHER_NTOHOST)
355 if(ARPA_INET_H_DECLARES_ETHER_NTOHOST)
356 #
357 # Yes - we have it declared.
358 #
359 set(HAVE_DECL_ETHER_NTOHOST TRUE)
360 endif()
361 endif()
362 #
363 # Did that succeed?
364 #
365 if(NOT HAVE_DECL_ETHER_NTOHOST)
366 #
367 # No, how about <netinet/if_ether.h>?
368 # On some platforms, it requires <net/if.h> and
369 # <netinet/in.h>, and we always include it with
370 # both of them, so test it with both of them.
371 #
372 # This test fails if we don't have <netinet/if_ether.h>
373 # and the headers we include before it, or if we do but
374 # <netinet/if_ether.h> doesn't declare ether_ntohost().
375 #
376 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)
377 if(NETINET_IF_ETHER_H_DECLARES_ETHER_NTOHOST)
378 #
379 # Yes - we have it declared.
380 #
381 set(HAVE_DECL_ETHER_NTOHOST TRUE)
382 endif()
383 endif()
384 #
385 # After all that, is ether_ntohost() declared?
386 #
387 if(NOT HAVE_DECL_ETHER_NTOHOST)
388 #
389 # No, we'll have to declare it ourselves.
390 # Do we have "struct ether_addr" if we include<netinet/if_ether.h>?
391 #
392 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)
393 endif()
394 endif()
395 cmake_pop_check_state()
396
397 check_function_exists(dnet_htoa STDLIBS_HAVE_DNET_HTOA)
398 if(STDLIBS_HAVE_DNET_HTOA)
399 set(HAVE_DNET_HTOA TRUE)
400 else(STDLIBS_HAVE_DNET_HTOA)
401 check_library_exists(dnet dnet_htoa "" HAVE_DNET_HTOA)
402 if(HAVE_DNET_HTOA)
403 set(TCPDUMP_LINK_LIBRARIES dnet ${TCPDUMP_LINK_LIBRARIES})
404 endif(HAVE_DNET_HTOA)
405 endif(STDLIBS_HAVE_DNET_HTOA)
406 if(HAVE_DNET_HTOA)
407 #
408 # OK, we have dnet_htoa(). Do we have netdnet/dnetdb.h?
409 #
410 check_include_files("sys/types.h;netdnet/dnetdb.h" HAVE_NETDNET_DNETDB_H)
411 if(HAVE_NETDNET_DNETDB_H)
412 #
413 # Yes. Does it declare dnet_htoa()?
414 #
415 cmake_push_check_state()
416 set(CMAKE_REQUIRED_LIBRARIES dnet)
417 check_symbol_exists(dnet_htoa "sys/types.h;netdnet/dnetdb.h" NETDNET_DNETDB_H_DECLARES_DNET_HTOA)
418 cmake_pop_check_state()
419 endif(HAVE_NETDNET_DNETDB_H)
420
421 #
422 # Do we have netdnet/dn.h?
423 #
424 check_include_file(netdnet/dn.h HAVE_NETDNET_DN_H)
425 if(HAVE_NETDNET_DN_H)
426 #
427 # Yes. Does it declare struct dn_naddr?
428 #
429 cmake_push_check_state()
430 set(CMAKE_EXTRA_INCLUDE_FILES netdnet/dn.h)
431 check_type_size("struct dn_naddr" STRUCT_DN_NADDR)
432 cmake_pop_check_state()
433 endif(HAVE_NETDNET_DN_H)
434 endif(HAVE_DNET_HTOA)
435
436 #
437 # Data types.
438 #
439 # XXX - there's no check_struct() macro that's like check_struct_has_member()
440 # except that it only checks for the existence of the structure type,
441 # so we use check_struct_has_member() and look for ss_family.
442 #
443
444 #
445 # Check for IPv6 support.
446 # We just check for AF_INET6 and struct in6_addr.
447 #
448 cmake_push_check_state()
449 if(WIN32)
450 set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h ws2tcpip.h)
451 check_symbol_exists(AF_INET6 "sys/types.h;ws2tcpip.h" HAVE_AF_INET6)
452 else(WIN32)
453 set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h sys/socket.h netinet/in.h)
454 check_symbol_exists(AF_INET6 "sys/types.h;sys/socket.h;netinet/in.h" HAVE_AF_INET6)
455 endif(WIN32)
456 check_type_size("struct in6_addr" HAVE_STRUCT_IN6_ADDR)
457 cmake_pop_check_state()
458 if(HAVE_AF_INET6 AND HAVE_STRUCT_IN6_ADDR)
459 set(HAVE_OS_IPV6_SUPPORT TRUE)
460 endif(HAVE_AF_INET6 AND HAVE_STRUCT_IN6_ADDR)
461
462 ######################################
463 # External dependencies
464 ######################################
465
466 #
467 # libpcap/WinPcap.
468 # First, find it.
469 #
470 find_package(PCAP REQUIRED)
471 include_directories(${PCAP_INCLUDE_DIRS})
472
473 cmake_push_check_state()
474
475 #
476 # Now check headers.
477 #
478 set(CMAKE_REQUIRED_INCLUDES ${PCAP_INCLUDE_DIRS})
479
480 #
481 # Check whether we have pcap/pcap-inttypes.h.
482 # If we do, we use that to get the C99 types defined.
483 #
484 check_include_file(pcap/pcap-inttypes.h HAVE_PCAP_PCAP_INTTYPES_H)
485
486 #
487 # Check for some headers introduced in later versions of libpcap
488 # and used by some printers.
489 #
490 # Those headers might use the {u_}intN_t types, so we must include
491 # netdissect-stdinc.h first.
492 #
493 set(CMAKE_EXTRA_INCLUDE_FILES netdissect-stdinc.h)
494 check_include_file(pcap/bluetooth.h HAVE_PCAP_BLUETOOTH_H)
495 check_include_file(pcap/nflog.h HAVE_PCAP_NFLOG_H)
496 cmake_pop_check_state()
497
498 #
499 # Check for various functions in libpcap/WinPcap.
500 #
501 cmake_push_check_state()
502 set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARIES})
503
504 #
505 # Check for "pcap_list_datalinks()" and use a substitute version if
506 # it's not present. If it is present, check for "pcap_free_datalinks()";
507 # if it's not present, we don't replace it for now. (We could do so
508 # on UN*X, but not on Windows, where hilarity ensues if a program
509 # built with one version of the MSVC support library tries to free
510 # something allocated by a library built with another version of
511 # the MSVC support library.)
512 #
513 check_function_exists(pcap_list_datalinks HAVE_PCAP_LIST_DATALINKS)
514 if(HAVE_PCAP_LIST_DATALINKS)
515 check_function_exists(pcap_free_datalinks HAVE_PCAP_FREE_DATALINKS)
516 endif(HAVE_PCAP_LIST_DATALINKS)
517
518 #
519 # Check for "pcap_datalink_name_to_val()", and use a substitute
520 # version if it's not present. If it is present, check for
521 # "pcap_datalink_val_to_description()", and if we don't have it,
522 # use a substitute version.
523 #
524 check_function_exists(pcap_datalink_name_to_val HAVE_PCAP_DATALINK_NAME_TO_VAL)
525 if(HAVE_PCAP_DATALINK_NAME_TO_VAL)
526 check_function_exists(pcap_datalink_val_to_description HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION)
527 endif(HAVE_PCAP_DATALINK_NAME_TO_VAL)
528
529 #
530 # Check for "pcap_set_datalink()"; you can't substitute for it if
531 # it's absent (it has hooks into libpcap), so just define the
532 # HAVE_ value if it's there.
533 #
534 check_function_exists(pcap_set_datalink HAVE_PCAP_SET_DATALINK)
535
536 #
537 # Check for "pcap_breakloop()"; you can't substitute for it if
538 # it's absent (it has hooks into the live capture routines),
539 # so just define the HAVE_ value if it's there.
540 #
541 check_function_exists(pcap_breakloop HAVE_PCAP_BREAKLOOP)
542
543 #
544 # Check for "pcap_dump_ftell()"; we use a substitute version
545 # if it's not present.
546 #
547 check_function_exists(pcap_dump_ftell HAVE_PCAP_DUMP_FTELL)
548
549 #
550 # Do we have the new open API? Check for pcap_create() and for
551 # pcap_statustostr(), and assume that, if we have both of them,
552 # we also have pcap_activate() and the other new routines
553 # introduced in libpcap 1.0.0. (We check for pcap_statustostr()
554 # as well, because WinPcap 4.1.3 screwed up and exported pcap_create()
555 # but not other routines such as pcap_statustostr(), even though it
556 # defined them and even though you really want pcap_statustostr() to
557 # get strings corresponding to some of the status returns from the
558 # new routines.)
559 #
560 check_function_exists(pcap_statustostr HAVE_PCAP_STATUSTOSTR)
561 #
562 # If we don't have pcap_statustostr(), don't check for pcap_create(),
563 # so we pretend we don't have it.
564 #
565 if(HAVE_PCAP_STATUSTOSTR)
566 check_function_exists(pcap_create HAVE_PCAP_CREATE)
567 endif(HAVE_PCAP_STATUSTOSTR)
568 if(HAVE_PCAP_CREATE)
569 #
570 # OK, do we have pcap_set_tstamp_type? If so, assume we have
571 # pcap_list_tstamp_types and pcap_free_tstamp_types as well.
572 #
573 check_function_exists(pcap_set_tstamp_type HAVE_PCAP_SET_TSTAMP_TYPE)
574
575 #
576 # And do we have pcap_set_tstamp_precision? If so, we assume
577 # we also have pcap_open_offline_with_tstamp_precision.
578 #
579 check_function_exists(pcap_set_tstamp_precision HAVE_PCAP_SET_TSTAMP_PRECISION)
580 endif(HAVE_PCAP_CREATE)
581
582 #
583 # Check for a miscellaneous collection of functions which we use
584 # if we have them.
585 #
586 check_function_exists(pcap_findalldevs HAVE_PCAP_FINDALLDEVS)
587 if(HAVE_PCAP_FINDALLDEVS)
588 #
589 # Check for libpcap having pcap_findalldevs() but the pcap.h header
590 # not having pcap_if_t; some versions of Mac OS X shipped with pcap.h
591 # from 0.6 and libpcap 0.8, so that libpcap had pcap_findalldevs but
592 # pcap.h didn't have pcap_if_t.
593 #
594 cmake_push_check_state()
595 set(CMAKE_REQUIRED_INCLUDES ${PCAP_INCLUDE_DIRS})
596 set(CMAKE_EXTRA_INCLUDE_FILES pcap.h)
597 check_type_size(pcap_if_t PCAP_IF_T)
598 cmake_pop_check_state()
599 endif(HAVE_PCAP_FINDALLDEVS)
600 check_function_exists(pcap_dump_flush HAVE_PCAP_DUMP_FLUSH)
601 check_function_exists(pcap_lib_version HAVE_PCAP_LIB_VERSION)
602 if(NOT HAVE_PCAP_LIB_VERSION)
603 # Check for the pcap_version string variable and set HAVE_PCAP_VERSION
604 endif(NOT HAVE_PCAP_LIB_VERSION)
605 check_function_exists(pcap_setdirection HAVE_PCAP_SETDIRECTION)
606 check_function_exists(pcap_set_immediate_mode HAVE_PCAP_SET_IMMEDIATE_MODE)
607 check_function_exists(pcap_dump_ftell64 HAVE_PCAP_DUMP_FTELL64)
608 check_function_exists(pcap_open HAVE_PCAP_OPEN)
609 check_function_exists(pcap_findalldevs_ex HAVE_PCAP_FINDALLDEVS_EX)
610
611 #
612 # On Windows, check for pcap_wsockinit(); if we don't have it, check for
613 # wsockinit().
614 #
615 if(WIN32)
616 check_function_exists(pcap_wsockinit HAVE_PCAP_WSOCKINIT)
617 if(NOT HAVE_PCAP_WSOCKINIT)
618 check_function_exists(wsockinit HAVE_WSOCKINIT)
619 endif(NOT HAVE_PCAP_WSOCKINIT)
620 endif(WIN32)
621
622 #
623 # Check for special debugging functions
624 #
625 check_function_exists(pcap_set_parser_debug HAVE_PCAP_SET_PARSER_DEBUG)
626 if(NOT HAVE_PCAP_SET_PARSER_DEBUG)
627 # Check whether libpcap defines pcap_debug or yydebug
628 check_variable_exists(pcap_debug HAVE_PCAP_DEBUG)
629 if(NOT HAVE_PCAP_DEBUG)
630 check_variable_exists(yydebug HAVE_YYDEBUG)
631 endif(NOT HAVE_PCAP_DEBUG)
632 endif(NOT HAVE_PCAP_SET_PARSER_DEBUG)
633
634 check_function_exists(pcap_set_optimizer_debug HAVE_PCAP_SET_OPTIMIZER_DEBUG)
635 check_function_exists(bpf_dump HAVE_BPF_DUMP)
636
637 cmake_pop_check_state()
638
639 #
640 # We have libpcap.
641 #
642 include_directories(SYSTEM ${PCAP_INCLUDE_DIRS})
643 set(TCPDUMP_LINK_LIBRARIES ${PCAP_LIBRARIES} ${TCPDUMP_LINK_LIBRARIES})
644
645 #
646 # Optional libraries.
647 #
648 #
649 # libsmi.
650 #
651 if(WITH_SMI)
652 find_package(SMI)
653 if(SMI_FOUND)
654 include_directories(SYSTEM ${SMI_INCLUDE_DIRS})
655 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} ${SMI_LIBRARIES})
656 set(USE_LIBSMI ON)
657 endif(SMI_FOUND)
658 endif(WITH_SMI)
659
660 #
661 # OpenSSL/libressl libcrypto.
662 #
663 if(WITH_CRYPTO)
664 find_package(CRYPTO)
665 if(CRYPTO_FOUND)
666 #
667 # Check for some functions.
668 #
669 cmake_push_check_state()
670 set(CMAKE_REQUIRED_LIBRARIES crypto)
671
672 #
673 # 1) do we have EVP_CIPHER_CTX_new?
674 # If so, we use it to allocate an EVP_CIPHER_CTX, as
675 # EVP_CIPHER_CTX may be opaque; otherwise, we allocate
676 # it ourselves.
677 #
678 check_function_exists(EVP_CIPHER_CTX_new HAVE_EVP_CIPHER_CTX_NEW)
679
680 #
681 # 2) do we have EVP_CipherInit_ex()?
682 # If so, we use it, because we need to be able to make two
683 # "initialize the cipher" calls, one with the cipher and key,
684 # and one with the IV, and, as of OpenSSL 1.1, You Can't Do That
685 # with EVP_CipherInit(), because a call to EVP_CipherInit() will
686 # unconditionally clear the context, and if you don't supply a
687 # cipher, it'll clear the cipher, rendering the context unusable
688 # and causing a crash.
689 #
690 check_function_exists(EVP_CipherInit_ex HAVE_EVP_CIPHERINIT_EX)
691
692 cmake_pop_check_state()
693
694 #
695 # We have libcrypto.
696 #
697 include_directories(SYSTEM ${CRYPTO_INCLUDE_DIRS})
698 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} ${CRYPTO_LIBRARIES})
699 set(HAVE_LIBCRYPTO ON)
700 endif(CRYPTO_FOUND)
701 endif(WITH_CRYPTO)
702
703 #
704 # Capsicum sandboxing.
705 # Some of this is in the system library, some of it is in other libraries.
706 #
707 if(WITH_CAPSICUM)
708 check_function_exists(cap_enter HAVE_CAP_ENTER)
709 check_function_exists(cap_rights_limit HAVE_CAP_RIGHTS_LIMIT)
710 check_function_exists(cap_ioctls_limit HAVE_CAP_IOCTLS_LIMIT)
711 check_function_exists(openat HAVE_OPENAT)
712 if(HAVE_CAP_ENTER AND HAVE_CAP_RIGHTS_LIMIT AND
713 HAVE_CAP_IOCTLS_LIMIT AND HAVE_OPENAT)
714 #
715 # OK, we have the functions we need to support Capsicum.
716 #
717 set(HAVE_CAPSICUM TRUE)
718
719 #
720 # OK, can we use Casper?
721 #
722 check_library_exists(casper cap_init "" HAVE_CAP_INIT)
723 if(HAVE_CAP_INIT)
724 cmake_push_check_state()
725 set(CMAKE_REQUIRED_LIBRARIES casper)
726 check_library_exists(cap_dns cap_gethostbyaddr "" HAVE_CAP_GETHOSTBYADDR)
727 cmake_pop_check_state()
728 if(HAVE_CAP_GETHOSTBYADDR)
729 set(HAVE_CASPER TRUE)
730 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} casper cap_dns)
731 endif(HAVE_CAP_GETHOSTBYADDR)
732 endif(HAVE_CAP_INIT)
733 endif(HAVE_CAP_ENTER AND HAVE_CAP_RIGHTS_LIMIT AND
734 HAVE_CAP_IOCTLS_LIMIT AND HAVE_OPENAT)
735 endif(WITH_CAPSICUM)
736
737 #
738 # libcap-ng.
739 #
740 if(WITH_CAP_NG)
741 check_include_file(cap-ng.h HAVE_CAP_NG_H)
742 check_library_exists(cap-ng capng_change_id "" HAVE_LIBCAP_NG)
743 if(HAVE_LIBCAP_NG)
744 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} cap-ng)
745 endif(HAVE_LIBCAP_NG)
746 endif(WITH_CAP_NG)
747
748 ######################################
749 # Input files
750 ######################################
751
752 if(ENABLE_SMB)
753 #
754 # We allow the SMB dissector to be omitted.
755 #
756 set(LOCALSRC ${LOCALSRC}
757 print-smb.c
758 smbutil.c)
759 endif(ENABLE_SMB)
760
761 set(NETDISSECT_SOURCE_LIST_C
762 addrtoname.c
763 addrtostr.c
764 af.c
765 ascii_strcasecmp.c
766 checksum.c
767 cpack.c
768 gmpls.c
769 gmt2local.c
770 in_cksum.c
771 ipproto.c
772 l2vpn.c
773 machdep.c
774 netdissect.c
775 netdissect-alloc.c
776 nlpid.c
777 oui.c
778 parsenfsfh.c
779 print.c
780 print-802_11.c
781 print-802_15_4.c
782 print-ah.c
783 print-ahcp.c
784 print-aodv.c
785 print-aoe.c
786 print-ap1394.c
787 print-arcnet.c
788 print-arp.c
789 print-ascii.c
790 print-atalk.c
791 print-atm.c
792 print-babel.c
793 print-beep.c
794 print-bfd.c
795 print-bgp.c
796 print-bootp.c
797 print-bt.c
798 print-calm-fast.c
799 print-carp.c
800 print-cdp.c
801 print-cfm.c
802 print-chdlc.c
803 print-cip.c
804 print-cnfp.c
805 print-dccp.c
806 print-decnet.c
807 print-dhcp6.c
808 print-domain.c
809 print-dtp.c
810 print-dvmrp.c
811 print-eap.c
812 print-egp.c
813 print-eigrp.c
814 print-enc.c
815 print-esp.c
816 print-ether.c
817 print-fddi.c
818 print-forces.c
819 print-fr.c
820 print-frag6.c
821 print-ftp.c
822 print-geneve.c
823 print-geonet.c
824 print-gre.c
825 print-hncp.c
826 print-hsrp.c
827 print-http.c
828 print-icmp.c
829 print-icmp6.c
830 print-igmp.c
831 print-igrp.c
832 print-ip.c
833 print-ip6.c
834 print-ip6opts.c
835 print-ipcomp.c
836 print-ipfc.c
837 print-ipnet.c
838 print-ipx.c
839 print-isakmp.c
840 print-isoclns.c
841 print-juniper.c
842 print-krb.c
843 print-l2tp.c
844 print-lane.c
845 print-ldp.c
846 print-lisp.c
847 print-llc.c
848 print-lldp.c
849 print-lmp.c
850 print-loopback.c
851 print-lspping.c
852 print-lwapp.c
853 print-lwres.c
854 print-m3ua.c
855 print-medsa.c
856 print-mobile.c
857 print-mobility.c
858 print-mpcp.c
859 print-mpls.c
860 print-mptcp.c
861 print-msdp.c
862 print-msnlb.c
863 print-nflog.c
864 print-nfs.c
865 print-nsh.c
866 print-ntp.c
867 print-null.c
868 print-olsr.c
869 print-openflow-1.0.c
870 print-openflow.c
871 print-ospf.c
872 print-ospf6.c
873 print-otv.c
874 print-pgm.c
875 print-pim.c
876 print-pktap.c
877 print-ppi.c
878 print-ppp.c
879 print-pppoe.c
880 print-pptp.c
881 print-radius.c
882 print-raw.c
883 print-resp.c
884 print-rip.c
885 print-ripng.c
886 print-rpki-rtr.c
887 print-rrcp.c
888 print-rsvp.c
889 print-rt6.c
890 print-rtsp.c
891 print-rx.c
892 print-sctp.c
893 print-sflow.c
894 print-sip.c
895 print-sl.c
896 print-sll.c
897 print-slow.c
898 print-smtp.c
899 print-snmp.c
900 print-stp.c
901 print-sunatm.c
902 print-sunrpc.c
903 print-symantec.c
904 print-syslog.c
905 print-tcp.c
906 print-telnet.c
907 print-tftp.c
908 print-timed.c
909 print-tipc.c
910 print-token.c
911 print-udld.c
912 print-udp.c
913 print-usb.c
914 print-vjc.c
915 print-vqp.c
916 print-vrrp.c
917 print-vtp.c
918 print-vxlan.c
919 print-vxlan-gpe.c
920 print-wb.c
921 print-zephyr.c
922 print-zeromq.c
923 ${LOCALSRC}
924 signature.c
925 strtoaddr.c
926 util-print.c
927 )
928
929 #
930 # Replace missing functions
931 #
932 foreach(FUNC strlcat strlcpy strdup strsep getservent getopt_long)
933 string(TOUPPER ${FUNC} FUNC_UPPERCASE)
934 set(HAVE_FUNC_UPPERCASE HAVE_${FUNC_UPPERCASE})
935 if(NOT ${HAVE_FUNC_UPPERCASE})
936 set(NETDISSECT_SOURCE_LIST_C ${NETDISSECT_SOURCE_LIST_C} missing/${FUNC}.c)
937 endif()
938 endforeach()
939 if(NOT WIN32)
940 if(NOT HAVE_VSNPRINTF OR NOT HAVE_SNPRINTF)
941 set(NETDISSECT_SOURCE_LIST_C ${NETDISSECT_SOURCE_LIST_C} missing/snprintf.c)
942 endif(NOT HAVE_VSNPRINTF OR NOT HAVE_SNPRINTF)
943 endif(NOT WIN32)
944
945 add_library(netdissect STATIC
946 ${NETDISSECT_SOURCE_LIST_C}
947 )
948
949 set(TCPDUMP_SOURCE_LIST_C tcpdump.c)
950
951 if(NOT HAVE_BPF_DUMP)
952 set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} bpf_dump.c)
953 endif(NOT HAVE_BPF_DUMP)
954 if(NOT HAVE_PCAP_DUMP_FTELL)
955 set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} missing/pcap_dump_ftell.c)
956 endif(NOT HAVE_PCAP_DUMP_FTELL)
957
958 if(NOT HAVE_PCAP_LIST_DATALINKS)
959 set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} missing/datalinks.c)
960 endif(NOT HAVE_PCAP_LIST_DATALINKS)
961
962 if((NOT HAVE_PCAP_DATALINK_NAME_TO_VAL) OR (NOT HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION))
963 set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} missing/dlnames.c)
964 endif((NOT HAVE_PCAP_DATALINK_NAME_TO_VAL) OR (NOT HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION))
965
966 set(PROJECT_SOURCE_LIST_C ${NETDISSECT_SOURCE_LIST_C} ${TCPDUMP_SOURCE_LIST_C})
967
968 file(GLOB PROJECT_SOURCE_LIST_H
969 *.h
970 )
971
972 source_group("Source Files" FILES ${PROJECT_SOURCE_LIST_C})
973 source_group("Header Files" FILES ${PROJECT_SOURCE_LIST_H})
974
975 ######################################
976 # Register targets
977 ######################################
978
979 add_executable(tcpdump ${TCPDUMP_SOURCE_LIST_C})
980 target_link_libraries(tcpdump netdissect ${TCPDUMP_LINK_LIBRARIES})
981
982 ######################################
983 # Write out the config.h file
984 ######################################
985
986 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
987
988 ######################################
989 # Install tcpdump and man pages
990 ######################################
991
992 #
993 # "Define GNU standard installation directories", which actually
994 # are also defined, to some degree, by autotools, and at least
995 # some of which are general UN*X conventions.
996 #
997 include(GNUInstallDirs)
998
999 set(MAN1_EXPAND tcpdump.1.in)
1000
1001 if(WIN32)
1002 # XXX TODO where to install on Windows?
1003 else(WIN32)
1004 install(TARGETS tcpdump DESTINATION sbin)
1005 endif(WIN32)
1006
1007 # On UN*X, and on Windows when not using MSVC, process man pages and
1008 # arrange that they be installed.
1009 if(NOT MSVC)
1010 #
1011 # Man pages.
1012 #
1013 # For each section of the manual for which we have man pages
1014 # that require macro expansion, do the expansion.
1015 #
1016 set(MAN1 "")
1017 foreach(TEMPLATE_MANPAGE ${MAN1_EXPAND})
1018 string(REPLACE ".in" "" MANPAGE ${TEMPLATE_MANPAGE})
1019 configure_file(${CMAKE_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY)
1020 set(MAN1 ${MAN1} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE})
1021 endforeach(TEMPLATE_MANPAGE)
1022 install(FILES ${MAN1} DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
1023 endif(NOT MSVC)
1024
1025 # uninstall target
1026 configure_file(
1027 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
1028 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
1029 IMMEDIATE @ONLY)
1030
1031 add_custom_target(uninstall
1032 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
1033
1034 #
1035 # Tcpdump tests
1036 #
1037 add_custom_target(check
1038 COMMAND ./TESTrun.sh
1039 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests)