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