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