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