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