]> The Tcpdump Group git mirrors - tcpdump/blob - CMakeLists.txt
Fixtypo.
[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 check_include_files("sys/types.h;sys/socket.h;net/if.h;net/pfvar.h" HAVE_NET_PFVAR_H)
143 if(HAVE_NET_PFVAR_H)
144 check_include_files("sys/types.h;sys/socket.h;net/if.h;net/pfvar.h;net/if_pflog.h" HAVE_NET_IF_PFLOG_H)
145 if(HAVE_NET_IF_PFLOG_H)
146 set(LOCALSRC print-pflog.c ${LOCALSRC})
147 endif(HAVE_NET_IF_PFLOG_H)
148 endif(HAVE_NET_PFVAR_H)
149
150 #
151 # As the autoconf manual says, AC_HEADER_TIME is obsolete, as all UN*Xes
152 # let you include both time.h and sys/time.h, so just say we can.
153 #
154 check_include_file(bitypes.h HAVE_SYS_BITYPES_H)
155 check_include_file(limits.h HAVE_LIMITS_H)
156
157 #
158 # Functions.
159 #
160 check_function_exists(strlcat HAVE_STRLCAT)
161 check_function_exists(strlcpy HAVE_STRLCPY)
162 check_function_exists(strdup HAVE_STRDUP)
163 check_function_exists(strsep HAVE_STRSEP)
164
165 #
166 # Find library needed for gethostbyaddr.
167 # NOTE: if you hand check_library_exists as its last argument a variable
168 # that's been set, it skips the test, so we need different variables.
169 #
170 set(TCPDUMP_LINK_LIBRARIES "")
171 check_function_exists(gethostbyaddr STDLIBS_HAVE_GETHOSTBYADDR)
172 if(NOT STDLIBS_HAVE_GETHOSTBYADDR)
173 check_library_exists(socket gethostbyaddr "" LIBSOCKET_HAS_GETHOSTBYADDR)
174 if(LIBSOCKET_HAS_GETHOSTBYADDR)
175 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} socket)
176 else()
177 check_library_exists(nsl gethostbyaddr "" LIBNSL_HAS_GETHOSTBYADDR)
178 if(LIBNSL_HAS_GETHOSTBYADDR)
179 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} nsl)
180 endif()
181 endif()
182 endif()
183
184 #
185 # This may require additional libraries.
186 #
187 cmake_push_check_state()
188 set(CMAKE_REQUIRED_LIBRARIES ${TCPDUMP_LINK_LIBRARIES})
189 check_function_exists(getservent STDLIBS_HAVE_GETSERVENT)
190 if(STDLIBS_HAVE_GETSERVENT)
191 set(HAVE_GETSERVENT TRUE)
192 else(STDLIBS_HAVE_GETSERVENT)
193 #
194 # Some platforms may need -lsocket for getservent.
195 #
196 set(CMAKE_REQUIRED_LIBRARIES socket ${TCPDUMP_LINK_LIBRARIES})
197 check_function_exists(getservent LIBSOCKET_HAS_GETSERVENT)
198 if(LIBSOCKET_HAS_GETSERVENT)
199 set(HAVE_GETSERVENT TRUE)
200 set(TCPDUMP_LINK_LIBRARIES socket ${TCPDUMP_LINK_LIBRARIES})
201 endif(LIBSOCKET_HAS_GETSERVENT)
202 endif(STDLIBS_HAVE_GETSERVENT)
203 cmake_pop_check_state()
204
205 check_function_exists(getopt_long HAVE_GETOPT_LONG)
206 check_function_exists(vsnprintf HAVE_VSNPRINTF)
207 check_function_exists(snprintf HAVE_SNPRINTF)
208 check_function_exists(fork HAVE_FORK)
209 check_function_exists(vfork HAVE_VFORK)
210 check_function_exists(strftime HAVE_STRFTIME)
211 check_function_exists(setlinebuf HAVE_SETLINEBUF)
212
213 #
214 # Some platforms may need -lnsl for getrpcbynumber.
215 #
216 cmake_push_check_state()
217 set(CMAKE_REQUIRED_LIBRARIES ${TCPDUMP_LINK_LIBRARIES})
218 check_function_exists(getrpcbynumber STDLIBS_HAVE_GETRPCBYNUMBER)
219 if(STDLIBS_HAVE_GETRPCBYNUMBER)
220 set(HAVE_GETRPCBYNUMBER TRUE)
221 else(STDLIBS_HAVE_GETRPCBYNUMBER)
222 set(CMAKE_REQUIRED_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} nsl)
223 check_function_exists(getrpcbynumber LIBNSL_HAS_GETRPCBYNUMBER)
224 if(LIBNSL_HAS_GETRPCBYNUMBER)
225 set(HAVE_GETRPCBYNUMBER TRUE)
226 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} nsl)
227 endif(LIBNSL_HAS_GETRPCBYNUMBER)
228 endif(STDLIBS_HAVE_GETRPCBYNUMBER)
229 cmake_pop_check_state()
230
231 #
232 # This requires the libraries we require, as ether_ntohost might be
233 # in one of those libraries. That means we have to do this after
234 # we check for those libraries.
235 #
236 # You are in a twisty little maze of UN*Xes, all different.
237 # Some might not have ether_ntohost().
238 # Some might have it and declare it in <net/ethernet.h>.
239 # Some might have it and declare it in <netinet/ether.h>
240 # Some might have it and declare it in <sys/ethernet.h>.
241 # Some might have it and declare it in <arpa/inet.h>.
242 # Some might have it and declare it in <netinet/if_ether.h>.
243 # Some might have it and not declare it in any header file.
244 #
245 # Before you is a C compiler.
246 #
247 cmake_push_check_state()
248 set(CMAKE_REQUIRED_LIBRARIES ${TCPDUMP_LINK_LIBRARIES})
249 check_function_exists(ether_ntohost HAVE_ETHER_NTOHOST)
250 if(HAVE_ETHER_NTOHOST)
251 #
252 # OK, we have ether_ntohost(). We don't check whether it's buggy,
253 # as we assume any system that has CMake is likely to be new enough
254 # that, if it has ether_ntohost(), whatever bug is checked for in
255 # autotools is fixed; we just decide to use it.
256 #
257 set(USE_ETHER_NTOHOST TRUE)
258
259 #
260 # Is it declared in <net/ethernet.h>?
261 #
262 # This test fails if we don't have <net/ethernet.h> or if we do
263 # but it doesn't declare ether_ntohost().
264 #
265 check_symbol_exists(ether_ntohost net/ethernet.h NET_ETHERNET_H_DECLARES_ETHER_NTOHOST)
266 if(NET_ETHERNET_H_DECLARES_ETHER_NTOHOST)
267 #
268 # Yes - we have it declared.
269 #
270 set(HAVE_DECL_ETHER_NTOHOST TRUE)
271 endif()
272 #
273 # Did that succeed?
274 #
275 if(NOT HAVE_DECL_ETHER_NTOHOST)
276 #
277 # No - how about <netinet/ether.h>, as on Linux?
278 #
279 # This test fails if we don't have <netinet/ether.h>
280 # or if we do but it doesn't declare ether_ntohost().
281 #
282 check_symbol_exists(ether_ntohost netinet/ether.h NETINET_ETHER_H_DECLARES_ETHER_NTOHOST)
283 if(NETINET_ETHER_H_DECLARES_ETHER_NTOHOST)
284 #
285 # Yes - we have it declared.
286 #
287 set(HAVE_DECL_ETHER_NTOHOST TRUE)
288 endif()
289 endif()
290 #
291 # Did that succeed?
292 #
293 if(NOT HAVE_DECL_ETHER_NTOHOST)
294 #
295 # No - how about <sys/ethernet.h>, as on Solaris 10 and later?
296 #
297 # This test fails if we don't have <sys/ethernet.h>
298 # or if we do but it doesn't declare ether_ntohost().
299 #
300 check_symbol_exists(ether_ntohost sys/ethernet.h SYS_ETHERNET_H_DECLARES_ETHER_NTOHOST)
301 if(SYS_ETHERNET_H_DECLARES_ETHER_NTOHOST)
302 #
303 # Yes - we have it declared.
304 #
305 set(HAVE_DECL_ETHER_NTOHOST TRUE)
306 endif()
307 endif()
308 #
309 # Did that succeed?
310 #
311 if(NOT HAVE_DECL_ETHER_NTOHOST)
312 #
313 # No, how about <arpa/inet.h>, as on AIX?
314 #
315 # This test fails if we don't have <arpa/inet.h>
316 # or if we do but it doesn't declare ether_ntohost().
317 #
318 check_symbol_exists(ether_ntohost arpa/inet.h ARPA_INET_H_DECLARES_ETHER_NTOHOST)
319 if(ARPA_INET_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 <netinet/if_ether.h>?
332 # On some platforms, it requires <net/if.h> and
333 # <netinet/in.h>, and we always include it with
334 # both of them, so test it with both of them.
335 #
336 # This test fails if we don't have <netinet/if_ether.h>
337 # and the headers we include before it, or if we do but
338 # <netinet/if_ether.h> doesn't declare ether_ntohost().
339 #
340 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)
341 if(NETINET_IF_ETHER_H_DECLARES_ETHER_NTOHOST)
342 #
343 # Yes - we have it declared.
344 #
345 set(HAVE_DECL_ETHER_NTOHOST TRUE)
346 endif()
347 endif()
348 #
349 # After all that, is ether_ntohost() declared?
350 #
351 if(NOT HAVE_DECL_ETHER_NTOHOST)
352 #
353 # No, we'll have to declare it ourselves.
354 # Do we have "struct ether_addr" if we include<netinet/if_ether.h>?
355 #
356 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)
357 endif()
358 endif()
359 cmake_pop_check_state()
360
361 check_function_exists(dnet_htoa STDLIBS_HAVE_DNET_HTOA)
362 if(STDLIBS_HAVE_DNET_HTOA)
363 set(HAVE_DNET_HTOA TRUE)
364 else(STDLIBS_HAVE_DNET_HTOA)
365 check_library_exists(dnet dnet_htoa "" HAVE_DNET_HTOA)
366 if(HAVE_DNET_HTOA)
367 set(TCPDUMP_LINK_LIBRARIES dnet ${TCPDUMP_LINK_LIBRARIES})
368 endif(HAVE_DNET_HTOA)
369 endif(STDLIBS_HAVE_DNET_HTOA)
370 if(HAVE_DNET_HTOA)
371 #
372 # OK, we have dnet_htoa(). Do we have netdnet/dnetdb.h?
373 #
374 check_include_files("sys/types.h;netdnet/dnetdb.h" HAVE_NETDNET_DNETDB_H)
375 if(HAVE_NETDNET_DNETDB_H)
376 #
377 # Yes. Does it declare dnet_htoa()?
378 #
379 cmake_push_check_state()
380 set(CMAKE_REQUIRED_LIBRARIES dnet)
381 check_symbol_exists(dnet_htoa "sys/types.h;netdnet/dnetdb.h" NETDNET_DNETDB_H_DECLARES_DNET_HTOA)
382 cmake_pop_check_state()
383 endif(HAVE_NETDNET_DNETDB_H)
384
385 #
386 # Do we have netdnet/dn.h?
387 #
388 check_include_file(netdnet/dn.h HAVE_NETDNET_DN_H)
389 if(HAVE_NETDNET_DN_H)
390 #
391 # Yes. Does it declare struct dn_naddr?
392 #
393 cmake_push_check_state()
394 set(CMAKE_EXTRA_INCLUDE_FILES netdnet/dn.h)
395 check_type_size("struct dn_naddr" STRUCT_DN_NADDR)
396 cmake_pop_check_state()
397 endif(HAVE_NETDNET_DN_H)
398 endif(HAVE_DNET_HTOA)
399
400 #
401 # Data types.
402 #
403 # XXX - there's no check_struct() macro that's like check_struct_has_member()
404 # except that it only checks for the existence of the structure type,
405 # so we use check_struct_has_member() and look for ss_family.
406 #
407 check_struct_has_member("struct sockaddr_storage" ss_family sys/socket.h HAVE_SOCKADDR_STORAGE)
408 set(CMAKE_EXTRA_INCLUDE_FILES unistd.h sys/socket.h)
409 check_type_size("socklen_t" SOCKLEN_T)
410 set(CMAKE_EXTRA_INCLUDE_FILES unistd.h)
411
412 #
413 # Check for IPv6 support.
414 # We just check for AF_INET6 and struct in6_addr.
415 #
416 cmake_push_check_state()
417 if(WIN32)
418 set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h ws2tcpip.h)
419 check_symbol_exists(AF_INET6 "sys/types.h;ws2tcpip.h" HAVE_AF_INET6)
420 else(WIN32)
421 set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h sys/socket.h netinet/in.h)
422 check_symbol_exists(AF_INET6 "sys/types.h;sys/socket.h;netinet/in.h" HAVE_AF_INET6)
423 endif(WIN32)
424 check_type_size("struct in6_addr" HAVE_STRUCT_IN6_ADDR)
425 cmake_pop_check_state()
426 if(HAVE_AF_INET6 AND HAVE_STRUCT_IN6_ADDR)
427 set(HAVE_OS_IPV6_SUPPORT TRUE)
428 endif(HAVE_AF_INET6 AND HAVE_STRUCT_IN6_ADDR)
429
430 #
431 # Structure fields.
432 #
433 check_struct_has_member("struct sockaddr" sa_len sys/socket.h HAVE_SOCKADDR_SA_LEN)
434
435 ######################################
436 # External dependencies
437 ######################################
438
439 #
440 # libpcap/WinPcap.
441 # First, find it.
442 #
443 find_package(PCAP REQUIRED)
444 include_directories(${PCAP_INCLUDE_DIRS})
445
446 cmake_push_check_state()
447
448 #
449 # Now check headers.
450 #
451 set(CMAKE_REQUIRED_INCLUDES ${PCAP_INCLUDE_DIRS})
452
453 #
454 # Check whether we have pcap/pcap-inttypes.h.
455 # If we do, we use that to get the C99 types defined.
456 #
457 check_include_file(pcap/pcap-inttypes.h HAVE_PCAP_PCAP_INTTYPES_H)
458
459 #
460 # Check for some headers introduced in later versions of libpcap
461 # and used by some printers.
462 #
463 # Those headers might use the {u_}intN_t types, so we must include
464 # netdissect-stdinc.h first.
465 #
466 set(CMAKE_EXTRA_INCLUDE_FILES netdissect-stdinc.h)
467 check_include_file(pcap/bluetooth.h HAVE_PCAP_BLUETOOTH_H)
468 check_include_file(pcap/nflog.h HAVE_PCAP_NFLOG_H)
469 cmake_pop_check_state()
470
471 #
472 # Check for various functions in libpcap/WinPcap.
473 #
474 cmake_push_check_state()
475 set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARIES})
476
477 #
478 # Check for "pcap_list_datalinks()" and use a substitute version if
479 # it's not present. If it is present, check for "pcap_free_datalinks()";
480 # if it's not present, we don't replace it for now. (We could do so
481 # on UN*X, but not on Windows, where hilarity ensues if a program
482 # built with one version of the MSVC support library tries to free
483 # something allocated by a library built with another version of
484 # the MSVC support library.)
485 #
486 check_function_exists(pcap_list_datalinks HAVE_PCAP_LIST_DATALINKS)
487 if(HAVE_PCAP_LIST_DATALINKS)
488 check_function_exists(pcap_free_datalinks HAVE_PCAP_FREE_DATALINKS)
489 endif(HAVE_PCAP_LIST_DATALINKS)
490
491 #
492 # Check for "pcap_datalink_name_to_val()", and use a substitute
493 # version if it's not present. If it is present, check for
494 # "pcap_datalink_val_to_description()", and if we don't have it,
495 # use a substitute version.
496 #
497 check_function_exists(pcap_datalink_name_to_val HAVE_PCAP_DATALINK_NAME_TO_VAL)
498 if(HAVE_PCAP_DATALINK_NAME_TO_VAL)
499 check_function_exists(pcap_datalink_val_to_description HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION)
500 endif(HAVE_PCAP_DATALINK_NAME_TO_VAL)
501
502 #
503 # Check for "pcap_set_datalink()"; you can't substitute for it if
504 # it's absent (it has hooks into libpcap), so just define the
505 # HAVE_ value if it's there.
506 #
507 check_function_exists(pcap_set_datalink HAVE_PCAP_SET_DATALINK)
508
509 #
510 # Check for "pcap_breakloop()"; you can't substitute for it if
511 # it's absent (it has hooks into the live capture routines),
512 # so just define the HAVE_ value if it's there.
513 #
514 check_function_exists(pcap_breakloop HAVE_PCAP_BREAKLOOP)
515
516 #
517 # Check for "pcap_dump_ftell()"; we use a substitute version
518 # if it's not present.
519 #
520 check_function_exists(pcap_dump_ftell HAVE_PCAP_DUMP_FTELL)
521
522 #
523 # Do we have the new open API? Check for pcap_create, and assume that,
524 # if we do, we also have pcap_activate() and the other new routines
525 # introduced in libpcap 1.0.0.
526 #
527 check_function_exists(pcap_create HAVE_PCAP_CREATE)
528 if(HAVE_PCAP_CREATE)
529 #
530 # OK, do we have pcap_set_tstamp_type? If so, assume we have
531 # pcap_list_tstamp_types and pcap_free_tstamp_types as well.
532 #
533 check_function_exists(pcap_set_tstamp_type HAVE_PCAP_SET_TSTAMP_TYPE)
534
535 #
536 # And do we have pcap_set_tstamp_precision? If so, we assume
537 # we also have pcap_open_offline_with_tstamp_precision.
538 #
539 check_function_exists(pcap_set_tstamp_precision HAVE_PCAP_SET_TSTAMP_PRECISION)
540 endif(HAVE_PCAP_CREATE)
541
542 #
543 # Check for a miscellaneous collection of functions which we use
544 # if we have them.
545 #
546 check_function_exists(pcap_findalldevs HAVE_PCAP_FINDALLDEVS)
547 if(HAVE_PCAP_FINDALLDEVS)
548 #
549 # Check for libpcap having pcap_findalldevs() but the pcap.h header
550 # not having pcap_if_t; some versions of Mac OS X shipped with pcap.h
551 # from 0.6 and libpcap 0.8, so that libpcap had pcap_findalldevs but
552 # pcap.h didn't have pcap_if_t.
553 #
554 cmake_push_check_state()
555 set(CMAKE_EXTRA_INCLUDE_FILES pcap.h)
556 check_type_size(pcap_if_t PCAP_IF_T)
557 cmake_pop_check_state()
558 endif(HAVE_PCAP_FINDALLDEVS)
559 check_function_exists(pcap_dump_flush HAVE_PCAP_DUMP_FLUSH)
560 check_function_exists(pcap_lib_version HAVE_PCAP_LIB_VERSION)
561 if(NOT HAVE_PCAP_LIB_VERSION)
562 # Check for the pcap_version string variable and set HAVE_PCAP_VERSION
563 endif(NOT HAVE_PCAP_LIB_VERSION)
564 check_function_exists(pcap_setdirection HAVE_PCAP_SETDIRECTION)
565 check_function_exists(pcap_set_immediate_mode HAVE_PCAP_SET_IMMEDIATE_MODE)
566 check_function_exists(pcap_dump_ftell64 HAVE_PCAP_DUMP_FTELL64)
567 check_function_exists(pcap_open HAVE_PCAP_OPEN)
568 check_function_exists(pcap_findalldevs_ex HAVE_PCAP_FINDALLDEVS_EX)
569
570 #
571 # Check for special debugging functions
572 #
573 check_function_exists(pcap_set_parser_debug HAVE_PCAP_SET_PARSER_DEBUG)
574 if(NOT HAVE_PCAP_SET_PARSER_DEBUG)
575 # Check whether libpcap defines pcap_debug or yydebug
576 check_variable_exists(pcap_debug HAVE_PCAP_DEBUG)
577 if(NOT HAVE_PCAP_DEBUG)
578 check_variable_exists(yydebug HAVE_YYDEBUG)
579 endif(NOT HAVE_PCAP_DEBUG)
580 endif(NOT HAVE_PCAP_SET_PARSER_DEBUG)
581
582 check_function_exists(pcap_set_optimizer_debug HAVE_PCAP_SET_OPTIMIZER_DEBUG)
583 check_function_exists(bpf_dump HAVE_BPF_DUMP)
584
585 cmake_pop_check_state()
586
587 #
588 # We have libpcap.
589 #
590 include_directories(SYSTEM ${PCAP_INCLUDE_DIRS})
591 set(TCPDUMP_LINK_LIBRARIES ${PCAP_LIBRARIES} ${TCPDUMP_LINK_LIBRARIES})
592
593 #
594 # Optional libraries.
595 #
596 #
597 # libsmi.
598 #
599 if(WITH_SMI)
600 find_package(SMI)
601 if(SMI_FOUND)
602 include_directories(SYSTEM ${SMI_INCLUDE_DIRS})
603 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} ${SMI_LIBRARIES})
604 set(USE_LIBSMI ON)
605 endif(SMI_FOUND)
606 endif(WITH_SMI)
607
608 #
609 # OpenSSL/libressl libcrypto.
610 #
611 if(WITH_CRYPTO)
612 find_package(CRYPTO)
613 if(CRYPTO_FOUND)
614 #
615 # Check for some functions.
616 #
617 cmake_push_check_state()
618 set(CMAKE_REQUIRED_LIBRARIES crypto)
619
620 #
621 # 1) do we have EVP_CIPHER_CTX_new?
622 # If so, we use it to allocate an EVP_CIPHER_CTX, as
623 # EVP_CIPHER_CTX may be opaque; otherwise, we allocate
624 # it ourselves.
625 #
626 check_function_exists(EVP_CIPHER_CTX_new HAVE_EVP_CIPHER_CTX_NEW)
627
628 #
629 # 2) do we have EVP_CipherInit_ex()?
630 # If so, we use it, because we need to be able to make two
631 # "initialize the cipher" calls, one with the cipher and key,
632 # and one with the IV, and, as of OpenSSL 1.1, You Can't Do That
633 # with EVP_CipherInit(), because a call to EVP_CipherInit() will
634 # unconditionally clear the context, and if you don't supply a
635 # cipher, it'll clear the cipher, rendering the context unusable
636 # and causing a crash.
637 #
638 check_function_exists(EVP_CipherInit_ex HAVE_EVP_CIPHERINIT_EX)
639
640 cmake_pop_check_state()
641
642 #
643 # We have libcrypto.
644 #
645 include_directories(SYSTEM ${CRYPTO_INCLUDE_DIRS})
646 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} ${CRYPTO_LIBRARIES})
647 set(HAVE_LIBCRYPTO ON)
648 endif(CRYPTO_FOUND)
649 endif(WITH_CRYPTO)
650
651 #
652 # Capsicum sandboxing.
653 # Some of this is in the system library, some of it is in other libraries.
654 #
655 if(WITH_CAPSICUM)
656 check_function_exists(cap_enter HAVE_CAP_ENTER)
657 check_function_exists(cap_rights_limit HAVE_CAP_RIGHTS_LIMIT)
658 check_function_exists(cap_ioctls_limit HAVE_CAP_IOCTLS_LIMIT)
659 check_function_exists(openat HAVE_OPENAT)
660 if(HAVE_CAP_ENTER AND HAVE_CAP_RIGHTS_LIMIT AND
661 HAVE_CAP_IOCTLS_LIMIT AND HAVE_OPENAT)
662 #
663 # OK, we have the functions we need to support Capsicum.
664 #
665 set(HAVE_CAPSICUM TRUE)
666
667 #
668 # OK, can we use Casper?
669 #
670 check_library_exists(casper cap_init "" HAVE_CAP_INIT)
671 if(HAVE_CAP_INIT)
672 cmake_push_check_state()
673 set(CMAKE_REQUIRED_LIBRARIES casper)
674 check_library_exists(cap_dns cap_gethostbyaddr "" HAVE_CAP_GETHOSTBYADDR)
675 cmake_pop_check_state()
676 if(HAVE_CAP_GETHOSTBYADDR)
677 set(HAVE_CASPER TRUE)
678 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} casper cap_dns)
679 endif(HAVE_CAP_GETHOSTBYADDR)
680 endif(HAVE_CAP_INIT)
681 endif(HAVE_CAP_ENTER AND HAVE_CAP_RIGHTS_LIMIT AND
682 HAVE_CAP_IOCTLS_LIMIT AND HAVE_OPENAT)
683 endif(WITH_CAPSICUM)
684
685 #
686 # libcap-ng.
687 #
688 if(WITH_CAP_NG)
689 check_include_file(cap-ng.h HAVE_CAP_NG_H)
690 check_library_exists(cap-ng capng_change_id "" HAVE_LIBCAP_NG)
691 if(HAVE_LIBCAP_NG)
692 set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} cap-ng)
693 endif(HAVE_LIBCAP_NG)
694 endif(WITH_CAP_NG)
695
696 ######################################
697 # Input files
698 ######################################
699
700 if(ENABLE_SMB)
701 #
702 # We allow the SMB dissector to be omitted.
703 #
704 set(LOCALSRC ${LOCALSRC}
705 print-smb.c
706 smbutil.c)
707 endif(ENABLE_SMB)
708
709 set(NETDISSECT_SOURCE_LIST_C
710 addrtoname.c
711 addrtostr.c
712 af.c
713 ascii_strcasecmp.c
714 checksum.c
715 cpack.c
716 gmpls.c
717 gmt2local.c
718 in_cksum.c
719 ipproto.c
720 l2vpn.c
721 machdep.c
722 nlpid.c
723 oui.c
724 parsenfsfh.c
725 print.c
726 print-802_11.c
727 print-802_15_4.c
728 print-ah.c
729 print-ahcp.c
730 print-aodv.c
731 print-aoe.c
732 print-ap1394.c
733 print-arcnet.c
734 print-arp.c
735 print-ascii.c
736 print-atalk.c
737 print-atm.c
738 print-babel.c
739 print-beep.c
740 print-bfd.c
741 print-bgp.c
742 print-bootp.c
743 print-bt.c
744 print-calm-fast.c
745 print-carp.c
746 print-cdp.c
747 print-cfm.c
748 print-chdlc.c
749 print-cip.c
750 print-cnfp.c
751 print-dccp.c
752 print-decnet.c
753 print-dhcp6.c
754 print-domain.c
755 print-dtp.c
756 print-dvmrp.c
757 print-eap.c
758 print-egp.c
759 print-eigrp.c
760 print-enc.c
761 print-esp.c
762 print-ether.c
763 print-fddi.c
764 print-forces.c
765 print-fr.c
766 print-frag6.c
767 print-ftp.c
768 print-geneve.c
769 print-geonet.c
770 print-gre.c
771 print-hncp.c
772 print-hsrp.c
773 print-http.c
774 print-icmp.c
775 print-icmp6.c
776 print-igmp.c
777 print-igrp.c
778 print-ip.c
779 print-ip6.c
780 print-ip6opts.c
781 print-ipcomp.c
782 print-ipfc.c
783 print-ipnet.c
784 print-ipx.c
785 print-isakmp.c
786 print-isoclns.c
787 print-juniper.c
788 print-krb.c
789 print-l2tp.c
790 print-lane.c
791 print-ldp.c
792 print-lisp.c
793 print-llc.c
794 print-lldp.c
795 print-lmp.c
796 print-loopback.c
797 print-lspping.c
798 print-lwapp.c
799 print-lwres.c
800 print-m3ua.c
801 print-medsa.c
802 print-mobile.c
803 print-mobility.c
804 print-mpcp.c
805 print-mpls.c
806 print-mptcp.c
807 print-msdp.c
808 print-msnlb.c
809 print-nflog.c
810 print-nfs.c
811 print-nsh.c
812 print-ntp.c
813 print-null.c
814 print-olsr.c
815 print-openflow-1.0.c
816 print-openflow.c
817 print-ospf.c
818 print-ospf6.c
819 print-otv.c
820 print-pgm.c
821 print-pim.c
822 print-pktap.c
823 print-ppi.c
824 print-ppp.c
825 print-pppoe.c
826 print-pptp.c
827 print-radius.c
828 print-raw.c
829 print-resp.c
830 print-rip.c
831 print-ripng.c
832 print-rpki-rtr.c
833 print-rrcp.c
834 print-rsvp.c
835 print-rt6.c
836 print-rtsp.c
837 print-rx.c
838 print-sctp.c
839 print-sflow.c
840 print-sip.c
841 print-sl.c
842 print-sll.c
843 print-slow.c
844 print-smtp.c
845 print-snmp.c
846 print-stp.c
847 print-sunatm.c
848 print-sunrpc.c
849 print-symantec.c
850 print-syslog.c
851 print-tcp.c
852 print-telnet.c
853 print-tftp.c
854 print-timed.c
855 print-tipc.c
856 print-token.c
857 print-udld.c
858 print-udp.c
859 print-usb.c
860 print-vjc.c
861 print-vqp.c
862 print-vrrp.c
863 print-vtp.c
864 print-vxlan.c
865 print-vxlan-gpe.c
866 print-wb.c
867 print-zephyr.c
868 print-zeromq.c
869 ${LOCALSRC}
870 netdissect.c
871 signature.c
872 strtoaddr.c
873 util-print.c
874 )
875
876 #
877 # Replace missing functions
878 #
879 foreach(FUNC strlcat strlcpy strdup strsep getservent getopt_long)
880 string(TOUPPER ${FUNC} FUNC_UPPERCASE)
881 set(HAVE_FUNC_UPPERCASE HAVE_${FUNC_UPPERCASE})
882 if(NOT ${HAVE_FUNC_UPPERCASE})
883 set(NETDISSECT_SOURCE_LIST_C ${NETDISSECT_SOURCE_LIST_C} missing/${FUNC}.c)
884 endif()
885 endforeach()
886 if(NOT HAVE_VSNPRINTF OR NOT HAVE_SNPRINTF)
887 if(WIN32)
888 set(NETDISSECT_SOURCE_LIST_C ${NETDISSECT_SOURCE_LIST_C} missing/win_snprintf.c)
889 else(WIN32)
890 set(NETDISSECT_SOURCE_LIST_C ${NETDISSECT_SOURCE_LIST_C} missing/snprintf.c)
891 endif(WIN32)
892 endif(NOT HAVE_VSNPRINTF OR NOT HAVE_SNPRINTF)
893
894 add_library(netdissect STATIC
895 ${NETDISSECT_SOURCE_LIST_C}
896 )
897
898 set(TCPDUMP_SOURCE_LIST_C tcpdump.c)
899
900 if(NOT HAVE_BPF_DUMP)
901 set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} bpf_dump.c)
902 endif(NOT HAVE_BPF_DUMP)
903 if(NOT HAVE_PCAP_DUMP_FTELL)
904 set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} missing/pcap_dump_ftell.c)
905 endif(NOT HAVE_PCAP_DUMP_FTELL)
906
907 if(NOT HAVE_PCAP_LIST_DATALINKS)
908 set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} missing/datalinks.c)
909 endif(NOT HAVE_PCAP_LIST_DATALINKS)
910
911 if((NOT HAVE_PCAP_DATALINK_NAME_TO_VAL) OR (NOT HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION))
912 set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} missing/dlnames.c)
913 endif((NOT HAVE_PCAP_DATALINK_NAME_TO_VAL) OR (NOT HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION))
914
915 set(PROJECT_SOURCE_LIST_C ${NETDISSECT_SOURCE_LIST_C} ${TCPDUMP_SOURCE_LIST_C})
916
917 file(GLOB PROJECT_SOURCE_LIST_H
918 *.h
919 )
920
921 source_group("Source Files" FILES ${PROJECT_SOURCE_LIST_C})
922 source_group("Header Files" FILES ${PROJECT_SOURCE_LIST_H})
923
924 ######################################
925 # Register targets
926 ######################################
927
928 add_executable(tcpdump ${TCPDUMP_SOURCE_LIST_C})
929 target_link_libraries(tcpdump netdissect ${TCPDUMP_LINK_LIBRARIES})
930
931 ######################################
932 # Write out the config.h file
933 ######################################
934
935 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
936
937 ######################################
938 # Install tcpdump and man pages
939 ######################################
940
941 #
942 # "Define GNU standard installation directories", which actually
943 # are also defined, to some degree, by autotools, and at least
944 # some of which are general UN*X conventions.
945 #
946 include(GNUInstallDirs)
947
948 set(MAN1_EXPAND tcpdump.1.in)
949
950 if(WIN32)
951 # XXX TODO where to install on Windows?
952 else(WIN32)
953 install(TARGETS tcpdump DESTINATION sbin)
954 endif(WIN32)
955
956 # On UN*X, and on Windows when not using MSVC, process man pages and
957 # arrange that they be installed.
958 if(NOT MSVC)
959 #
960 # Man pages.
961 #
962 # For each section of the manual for which we have man pages
963 # that require macro expansion, do the expansion.
964 #
965 set(MAN1 "")
966 foreach(TEMPLATE_MANPAGE ${MAN1_EXPAND})
967 string(REPLACE ".in" "" MANPAGE ${TEMPLATE_MANPAGE})
968 configure_file(${CMAKE_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY)
969 set(MAN1 ${MAN1} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE})
970 endforeach(TEMPLATE_MANPAGE)
971 install(FILES ${MAN1} DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
972 endif(NOT MSVC)
973
974 # uninstall target
975 configure_file(
976 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
977 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
978 IMMEDIATE @ONLY)
979
980 add_custom_target(uninstall
981 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)