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