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