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