]> The Tcpdump Group git mirrors - libpcap/blob - CMakeLists.txt
In the open request, reject capture sources that are URLs.
[libpcap] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8.6)
2
3 #
4 # Apple doesn't build with an install_name starting with @rpath, and
5 # neither do we with autotools; don't do so with CMake, either, and
6 # suppress warnings about that.
7 #
8 if(POLICY CMP0042)
9 cmake_policy(SET CMP0042 OLD)
10 endif()
11
12 #
13 # Squelch noise about quoted strings in if() statements.
14 # WE KNOW WHAT WE'RE DOING, WE'RE DOING EVERYTHING THE WAY THAT NEWER
15 # VERSIONS OF CMAKE EXPECT BY DEFAULT, DON'T WASTE OUR TIME WITH NOISE.
16 #
17 cmake_policy(SET CMP0054 NEW)
18
19 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)
20
21 project(pcap)
22
23 include(CheckCCompilerFlag)
24
25 #
26 # For checking if a compiler flag works and adding it if it does.
27 #
28 macro(check_and_add_compiler_option _option)
29 message(STATUS "Checking C compiler flag ${_option}")
30 string(REPLACE "=" "-" _temp_option_variable ${_option})
31 string(REGEX REPLACE "^-" "" _option_variable ${_temp_option_variable})
32 check_c_compiler_flag("${_option}" ${_option_variable})
33 if(${${_option_variable}})
34 set(C_ADDITIONAL_FLAGS "${C_ADDITIONAL_FLAGS} ${_option}")
35 endif()
36 endmacro()
37
38 #
39 # If we're building with Visual Studio, we require Visual Studio 2015,
40 # in order to get sufficient C99 compatibility. Check for that.
41 #
42 # If not, try the appropriate flag for the compiler to enable C99
43 # features.
44 #
45 set(C_ADDITIONAL_FLAGS "")
46 if(MSVC)
47 if(MSVC_VERSION LESS 1900)
48 message(FATAL_ERROR "Visual Studio 2015 or later is required")
49 endif()
50
51 #
52 # Treat source files as being in UTF-8 with MSVC if it's not using
53 # the Clang front end.
54 # We assume that UTF-8 source is OK with other compilers and with
55 # MSVC if it's using the Clang front end.
56 #
57 if(NOT ${CMAKE_C_COMPILER} MATCHES "clang*")
58 set(C_ADDITIONAL_FLAGS "${C_ADDITIONAL_FLAGS} /utf-8")
59 endif(NOT ${CMAKE_C_COMPILER} MATCHES "clang*")
60 else(MSVC)
61 #
62 # For checking if a compiler flag works, failing if it doesn't,
63 # and adding it otherwise.
64 #
65 macro(require_and_add_compiler_option _option)
66 message(STATUS "Checking C compiler flag ${_option}")
67 string(REPLACE "=" "-" _temp_option_variable ${_option})
68 string(REGEX REPLACE "^-" "" _option_variable ${_temp_option_variable})
69 check_c_compiler_flag("${_option}" ${_option_variable})
70 if(${${_option_variable}})
71 set(C_ADDITIONAL_FLAGS "${C_ADDITIONAL_FLAGS} ${_option}")
72 else()
73 message(FATAL_ERROR "C99 support is required, but the compiler doesn't support a compiler flag to enable it")
74 endif()
75 endmacro()
76
77 #
78 # Try to enable as many C99 features as we can.
79 # At minimum, we want C++/C99-style // comments.
80 #
81 # Newer versions of compilers might default to supporting C99, but
82 # older versions may require a special flag.
83 #
84 # Prior to CMake 3.1, setting CMAKE_C_STANDARD will not have any effect,
85 # so, unless and until we require CMake 3.1 or later, we have to do it
86 # ourselves on pre-3.1 CMake, so we just do it ourselves on all versions
87 # of CMake.
88 #
89 # Note: with CMake 3.1 through 3.5, the only compilers for which CMake
90 # handles CMAKE_C_STANDARD are GCC and Clang. 3.6 adds support only
91 # for Intel C; 3.9 adds support for PGI C, Sun C, and IBM XL C, and
92 # 3.10 adds support for Cray C and IAR C, but no version of CMake has
93 # support for HP C. Therefore, even if we use CMAKE_C_STANDARD with
94 # compilers for which CMake supports it, we may still have to do it
95 # ourselves on other compilers.
96 #
97 # See the CMake documentation for the CMAKE_<LANG>_COMPILER_ID variables
98 # for a list of compiler IDs.
99 #
100 # XXX - this just tests whether the option works, fails if it doesn't,
101 # and adds it if it does. We don't test whether it's necessary in order
102 # to get the C99 features that we use, or whether, if it's used, it
103 # enables all the features that we require.
104 #
105 if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR
106 CMAKE_C_COMPILER_ID MATCHES "Clang")
107 require_and_add_compiler_option("-std=gnu99")
108 elseif(CMAKE_C_COMPILER_ID MATCHES "XL")
109 #
110 # We want support for extensions picked up for GNU C compatibility,
111 # so we use -qlanglvl=extc99.
112 #
113 require_and_add_compiler_option("-qlanglvl=extc99")
114 elseif(CMAKE_C_COMPILER_ID MATCHES "HP")
115 require_and_add_compiler_option("-AC99")
116 elseif(CMAKE_C_COMPILER_ID MATCHES "Sun")
117 require_and_add_compiler_option("-xc99")
118 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
119 require_and_add_compiler_option("-c99")
120 endif()
121 endif(MSVC)
122
123 #
124 # Build all runtimes in the top-level binary directory; that way,
125 # on Windows, the executables will be in the same directory as
126 # the DLLs, so the system will find pcap.dll when any of the
127 # executables are run.
128 #
129 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run)
130
131 ###################################################################
132 # Parameters
133 ###################################################################
134
135 if(WIN32)
136 #
137 # On Windows, allow the library name to be overridden, for the
138 # benefit of projects that combine libpcap with their own
139 # kernel-mode code to support capturing.
140 #
141 set(LIBRARY_NAME pcap CACHE STRING "Library name")
142 else()
143 #
144 # On UN*X, it's always been libpcap.
145 #
146 set(LIBRARY_NAME pcap)
147 endif()
148
149 option(INET6 "Enable IPv6" ON)
150 if(WIN32)
151 option(USE_STATIC_RT "Use static Runtime" ON)
152 endif(WIN32)
153 option(BUILD_SHARED_LIBS "Build shared libraries" ON)
154 if(WIN32)
155 set(PACKET_DLL_DIR "" CACHE PATH "Path to directory with include and lib subdirectories for packet.dll")
156 endif(WIN32)
157
158 # To pacify those who hate the protochain instruction
159 option(NO_PROTOCHAIN "Disable protochain instruction" OFF)
160
161 #
162 # Start out with the capture mechanism type unspecified; the user
163 # can explicitly specify it and, if they don't, we'll pick an
164 # appropriate one.
165 #
166 set(PCAP_TYPE "" CACHE STRING "Packet capture type")
167
168 #
169 # Default to having remote capture support on Windows and, for now, to
170 # not having it on UN*X.
171 #
172 if(WIN32)
173 option(ENABLE_REMOTE "Enable remote capture" ON)
174 else()
175 option(ENABLE_REMOTE "Enable remote capture" OFF)
176 endif(WIN32)
177
178 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
179 option(PCAP_SUPPORT_PACKET_RING "Enable Linux packet ring support" ON)
180 option(BUILD_WITH_LIBNL "Build with libnl" ON)
181 endif()
182
183 #
184 # Additional capture modules.
185 #
186 option(DISABLE_USB "Disable USB sniffing support" OFF)
187 option(DISABLE_BLUETOOTH "Disable Bluetooth sniffing support" OFF)
188 option(DISABLE_NETMAP "Disable netmap support" OFF)
189 option(DISABLE_DPDK "Disable DPDK support" OFF)
190
191 #
192 # We don't support D-Bus sniffing on macOS; see
193 #
194 # https://bugs.freedesktop.org/show_bug.cgi?id=74029
195 #
196 if(APPLE)
197 option(DISABLE_DBUS "Disable D-Bus sniffing support" ON)
198 else(APPLE)
199 option(DISABLE_DBUS "Disable D-Bus sniffing support" OFF)
200 endif(APPLE)
201 option(DISABLE_RDMA "Disable RDMA sniffing support" OFF)
202
203 option(DISABLE_DAG "Disable Endace DAG card support" OFF)
204
205 option(DISABLE_SEPTEL "Disable Septel card support" OFF)
206 set(SEPTEL_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../septel" CACHE PATH "Path to directory with include and lib subdirectories for Septel API")
207
208 option(DISABLE_SNF "Disable Myricom SNF support" OFF)
209
210 option(DISABLE_TC "Disable Riverbed TurboCap support" OFF)
211
212 #
213 # Debugging options.
214 #
215 option(BDEBUG "Build optimizer debugging code" OFF)
216 option(YYDEBUG "Build parser debugging code" OFF)
217
218 ###################################################################
219 # Versioning
220 ###################################################################
221
222 # Get, parse, format and set pcap's version string from [pcap_root]/VERSION
223 # for later use.
224
225 # Get MAJOR, MINOR, PATCH & SUFFIX
226 file(STRINGS ${pcap_SOURCE_DIR}/VERSION
227 PACKAGE_VERSION
228 LIMIT_COUNT 1 # Read only the first line
229 )
230
231 # Get "just" MAJOR
232 string(REGEX MATCH "^([0-9]+)" PACKAGE_VERSION_MAJOR "${PACKAGE_VERSION}")
233
234 # Get MAJOR, MINOR & PATCH
235 string(REGEX MATCH "^([0-9]+.)?([0-9]+.)?([0-9]+)" PACKAGE_VERSION_NOSUFFIX "${PACKAGE_VERSION}")
236
237 if(WIN32)
238 # Convert PCAP_VERSION_NOSUFFIX to Windows preferred version format
239 string(REPLACE "." "," PACKAGE_VERSION_PREDLL ${PACKAGE_VERSION_NOSUFFIX})
240
241 # Append NANO (used for Windows internal versioning) to PCAP_VERSION_PREDLL
242 # 0 means unused.
243 set(PACKAGE_VERSION_DLL ${PACKAGE_VERSION_PREDLL},0)
244 endif(WIN32)
245
246 set(PACKAGE_NAME "${LIBRARY_NAME}")
247 set(PACKAGE_STRING "${LIBRARY_NAME} ${PACKAGE_VERSION}")
248
249 ######################################
250 # Project settings
251 ######################################
252
253 add_definitions(-DHAVE_CONFIG_H)
254
255 include_directories(
256 ${CMAKE_CURRENT_BINARY_DIR}
257 ${pcap_SOURCE_DIR}
258 )
259
260 include(CheckFunctionExists)
261 include(CMakePushCheckState)
262 include(CheckSymbolExists)
263
264 if(WIN32)
265
266 if(IS_DIRECTORY ${CMAKE_HOME_DIRECTORY}/../../Common)
267 include_directories(${CMAKE_HOME_DIRECTORY}/../../Common)
268 endif(IS_DIRECTORY ${CMAKE_HOME_DIRECTORY}/../../Common)
269
270 find_package(Packet)
271 if(PACKET_FOUND)
272 set(HAVE_PACKET32 TRUE)
273 include_directories(${PACKET_INCLUDE_DIRS})
274 #
275 # Check whether we have the NPcap PacketIsLoopbackAdapter()
276 # function.
277 #
278 cmake_push_check_state()
279 set(CMAKE_REQUIRED_LIBRARIES ${PACKET_LIBRARIES})
280 check_function_exists(PacketIsLoopbackAdapter HAVE_PACKET_IS_LOOPBACK_ADAPTER)
281 cmake_pop_check_state()
282 endif(PACKET_FOUND)
283
284 message(STATUS "checking for Npcap's version.h")
285 check_symbol_exists(WINPCAP_PRODUCT_NAME "../../version.h" HAVE_VERSION_H)
286 if(HAVE_VERSION_H)
287 message(STATUS "HAVE version.h")
288 else(HAVE_VERSION_H)
289 message(STATUS "MISSING version.h")
290 endif(HAVE_VERSION_H)
291
292 endif(WIN32)
293
294 if(MSVC)
295 add_definitions(-D__STDC__)
296 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
297 endif(MSVC)
298
299 if(USE_STATIC_RT)
300 message(STATUS "Use STATIC runtime")
301 if(MSVC)
302 foreach(RT_FLAG
303 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
304 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
305 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
306 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
307 string(REGEX REPLACE "/MD" "/MT" ${RT_FLAG} "${${RT_FLAG}}")
308 endforeach(RT_FLAG)
309 elseif(MINGW)
310 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc")
311 endif()
312 else (USE_STATIC_RT)
313 message(STATUS "Use DYNAMIC runtime")
314 endif(USE_STATIC_RT)
315
316 ###################################################################
317 # Detect available platform features
318 ###################################################################
319
320 include(CheckIncludeFile)
321 include(CheckIncludeFiles)
322 include(CheckStructHasMember)
323 include(CheckTypeSize)
324
325 #
326 # Tests are a bit expensive with Visual Studio on Windows, so, on
327 # Windows, we skip tests for UN*X-only headers and functions.
328 #
329
330 #
331 # Header files.
332 #
333 check_include_file(inttypes.h HAVE_INTTYPES_H)
334 check_include_file(stdint.h HAVE_STDINT_H)
335 check_include_file(unistd.h HAVE_UNISTD_H)
336 if(NOT HAVE_UNISTD_H)
337 add_definitions(-DYY_NO_UNISTD_H)
338 endif(NOT HAVE_UNISTD_H)
339 check_include_file(bitypes.h HAVE_SYS_BITYPES_H)
340 if(NOT WIN32)
341 check_include_file(sys/ioccom.h HAVE_SYS_IOCCOM_H)
342 check_include_file(sys/sockio.h HAVE_SYS_SOCKIO_H)
343 check_include_file(sys/select.h HAVE_SYS_SELECT_H)
344
345 check_include_file(netpacket/packet.h HAVE_NETPACKET_PACKET_H)
346 check_include_files("sys/types.h;sys/socket.h;net/if.h;net/pfvar.h" HAVE_NET_PFVAR_H)
347 if(HAVE_NET_PFVAR_H)
348 #
349 # Check for various PF actions.
350 #
351 check_c_source_compiles(
352 "#include <sys/types.h>
353 #include <sys/socket.h>
354 #include <net/if.h>
355 #include <net/pfvar.h>
356
357 int
358 main(void)
359 {
360 return PF_NAT+PF_NONAT+PF_BINAT+PF_NOBINAT+PF_RDR+PF_NORDR;
361 }
362 "
363 HAVE_PF_NAT_THROUGH_PF_NORDR)
364 endif(HAVE_NET_PFVAR_H)
365 check_include_file(netinet/if_ether.h HAVE_NETINET_IF_ETHER_H)
366 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
367 check_include_file(linux/sockios.h HAVE_LINUX_SOCKIOS_H)
368 #
369 # linux/if_bonding.h requires sys/socket.h.
370 #
371 check_include_files("sys/socket.h;linux/if_bonding.h" HAVE_LINUX_IF_BONDING_H)
372
373 #
374 # Check for the eventfd header.
375 #
376 check_include_files("sys/eventfd.h" HAVE_SYS_EVENTFD_H)
377 endif()
378 endif(NOT WIN32)
379
380 #
381 # Functions.
382 #
383 check_function_exists(strerror HAVE_STRERROR)
384 check_function_exists(strerror_r HAVE_STRERROR_R)
385 if(HAVE_STRERROR_R)
386 #
387 # We have strerror_r; if we define _GNU_SOURCE, is it a
388 # POSIX-compliant strerror_r() or a GNU strerror_r()?
389 #
390 check_c_source_compiles(
391 "#define _GNU_SOURCE
392 #include <string.h>
393
394 /* Define it GNU-style; that will cause an error if it's not GNU-style */
395 extern char *strerror_r(int, char *, size_t);
396
397 int
398 main(void)
399 {
400 return 0;
401 }
402 "
403 HAVE_GNU_STRERROR_R)
404 if(NOT HAVE_GNU_STRERROR_R)
405 set(HAVE_POSIX_STRERROR_R YES)
406 endif(NOT HAVE_GNU_STRERROR_R)
407 else(HAVE_STRERROR_R)
408 #
409 # We don't have strerror_r; do we have strerror_s?
410 #
411 check_function_exists(strerror_s HAVE_STRERROR_S)
412 endif(HAVE_STRERROR_R)
413
414 #
415 # Make sure we have vsnprintf() and snprintf(); we require them.
416 # We use check_symbol_exists(), as they aren't necessarily external
417 # functions - in Visual Studio, for example, they're inline functions
418 # calling a common external function.
419 #
420 check_symbol_exists(vsnprintf "stdio.h" HAVE_VSNPRINTF)
421 if(NOT HAVE_VSNPRINTF)
422 message(FATAL_ERROR "vsnprintf() is required but wasn't found")
423 endif(NOT HAVE_VSNPRINTF)
424 check_symbol_exists(snprintf "stdio.h" HAVE_SNPRINTF)
425 if(NOT HAVE_SNPRINTF)
426 message(FATAL_ERROR "snprintf() is required but wasn't found")
427 endif()
428
429 check_function_exists(strlcpy HAVE_STRLCPY)
430 check_function_exists(strlcat HAVE_STRLCAT)
431 check_function_exists(asprintf HAVE_ASPRINTF)
432 check_function_exists(vasprintf HAVE_VASPRINTF)
433 check_function_exists(strtok_r HAVE_STRTOK_R)
434 if(NOT WIN32)
435 check_function_exists(vsyslog HAVE_VSYSLOG)
436 endif()
437
438 #
439 # These tests are for network applications that need socket functions
440 # and getaddrinfo()/getnameinfo()-ish functions. We now require
441 # getaddrinfo() and getnameinfo(). On UN*X systems, we also prefer
442 # versions of recvmsg() that conform to the Single UNIX Specification,
443 # so that we can check whether a datagram received with recvmsg() was
444 # truncated when received due to the buffer being too small.
445 #
446 # On Windows, getaddrinfo() is in the ws2_32 library.
447
448 # On most UN*X systems, they're available in the system library.
449 #
450 # Under Solaris, we need to link with libsocket and libnsl to get
451 # getaddrinfo() and getnameinfo() and, if we have libxnet, we need to
452 # link with libxnet before libsocket to get a version of recvmsg()
453 # that conforms to the Single UNIX Specification.
454 #
455 # We use getaddrinfo() because we want a portable thread-safe way
456 # of getting information for a host name or port; there exist _r
457 # versions of gethostbyname() and getservbyname() on some platforms,
458 # but not on all platforms.
459 #
460 # NOTE: if you hand check_library_exists as its last argument a variable
461 # that's been set, it skips the test, so we need different variables.
462 #
463 set(PCAP_LINK_LIBRARIES "")
464 include(CheckLibraryExists)
465 if(WIN32)
466 #
467 # We need winsock2.h and ws2tcpip.h.
468 #
469 cmake_push_check_state()
470 set(CMAKE_REQUIRED_LIBRARIES ws2_32)
471 check_symbol_exists(getaddrinfo "winsock2.h;ws2tcpip.h" LIBWS2_32_HAS_GETADDRINFO)
472 cmake_pop_check_state()
473 if(LIBWS2_32_HAS_GETADDRINFO)
474 set(PCAP_LINK_LIBRARIES ws2_32 ${PCAP_LINK_LIBRARIES})
475 else(LIBWS2_32_HAS_GETADDRINFO)
476 message(FATAL_ERROR "getaddrinfo is required, but wasn't found")
477 endif(LIBWS2_32_HAS_GETADDRINFO)
478 else(WIN32)
479 #
480 # UN*X. First try the system libraries, then try the libraries
481 # for Solaris and possibly other systems that picked up the
482 # System V library split.
483 #
484 check_function_exists(getaddrinfo STDLIBS_HAVE_GETADDRINFO)
485 if(NOT STDLIBS_HAVE_GETADDRINFO)
486 #
487 # Not found in the standard system libraries.
488 # Try libsocket, which requires libnsl.
489 #
490 cmake_push_check_state()
491 set(CMAKE_REQUIRED_LIBRARIES nsl)
492 check_library_exists(socket getaddrinfo "" LIBSOCKET_HAS_GETADDRINFO)
493 cmake_pop_check_state()
494 if(LIBSOCKET_HAS_GETADDRINFO)
495 #
496 # OK, we found it in libsocket.
497 #
498 set(PCAP_LINK_LIBRARIES socket nsl ${PCAP_LINK_LIBRARIES})
499 else(LIBSOCKET_HAS_GETADDRINFO)
500 check_library_exists(network getaddrinfo "" LIBNETWORK_HAS_GETADDRINFO)
501 if(LIBNETWORK_HAS_GETADDRINFO)
502 #
503 # OK, we found it in libnetwork (Haiku).
504 #
505 set(PCAP_LINK_LIBRARIES network ${PCAP_LINK_LIBRARIES})
506 else(LIBNETWORK_HAS_GETADDRINFO)
507 #
508 # We didn't find it.
509 #
510 message(FATAL_ERROR "getaddrinfo is required, but wasn't found")
511 endif(LIBNETWORK_HAS_GETADDRINFO)
512 endif(LIBSOCKET_HAS_GETADDRINFO)
513
514 #
515 # OK, do we have recvmsg() in libxnet?
516 # We also link with libsocket and libnsl.
517 #
518 cmake_push_check_state()
519 set(CMAKE_REQUIRED_LIBRARIES socket nsl)
520 check_library_exists(xnet recvmsg "" LIBXNET_HAS_RECVMSG)
521 cmake_pop_check_state()
522 if(LIBXNET_HAS_RECVMSG)
523 #
524 # Yes - link with it as well.
525 #
526 set(PCAP_LINK_LIBRARIES xnet ${PCAP_LINK_LIBRARIES})
527 endif(LIBXNET_HAS_RECVMSG)
528 endif(NOT STDLIBS_HAVE_GETADDRINFO)
529
530 # DLPI needs putmsg under HPUX so test for -lstr while we're at it
531 check_function_exists(putmsg STDLIBS_HAVE_PUTMSG)
532 if(NOT STDLIBS_HAVE_PUTMSG)
533 check_library_exists(str putmsg "" LIBSTR_HAS_PUTMSG)
534 if(LIBSTR_HAS_PUTMSG)
535 set(PCAP_LINK_LIBRARIES str ${PCAP_LINK_LIBRARIES})
536 endif(LIBSTR_HAS_PUTMSG)
537 endif(NOT STDLIBS_HAVE_PUTMSG)
538 endif(WIN32)
539
540 #
541 # Check for reentrant versions of getnetbyname_r(), as provided by
542 # Linux (glibc), Solaris/IRIX, and AIX (with three different APIs!).
543 # If we don't find one, we just use getnetbyname(), which uses
544 # thread-specific data on many platforms, but doesn't use it on
545 # NetBSD or OpenBSD, and may not use it on older versions of other
546 # platforms.
547 #
548 # Only do the check if we have a declaration of getnetbyname_r();
549 # without it, we can't check which API it has. (We assume that
550 # if there's a declaration, it has a prototype, so that the API
551 # can be checked.)
552 #
553 cmake_push_check_state()
554 set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LINK_LIBRARIES})
555 check_symbol_exists(getnetbyname_r netdb.h NETDB_H_DECLARES_GETNETBYNAME_R)
556 if(NETDB_H_DECLARES_GETNETBYNAME_R)
557 check_c_source_compiles(
558 "#include <netdb.h>
559
560 int
561 main(void)
562 {
563 struct netent netent_buf;
564 char buf[1024];
565 struct netent *resultp;
566 int h_errnoval;
567
568 return getnetbyname_r((const char *)0, &netent_buf, buf, sizeof buf, &resultp, &h_errnoval);
569 }
570 "
571 HAVE_LINUX_GETNETBYNAME_R)
572 if(NOT HAVE_LINUX_GETNETBYNAME_R)
573 check_c_source_compiles(
574 "#include <netdb.h>
575
576 int
577 main(void)
578 {
579 struct netent netent_buf;
580 char buf[1024];
581
582 return getnetbyname_r((const char *)0, &netent_buf, buf, (int)sizeof buf) != NULL;
583 }
584 "
585 HAVE_SOLARIS_IRIX_GETNETBYNAME_R)
586 if(NOT HAVE_SOLARIS_IRIX_GETNETBYNAME_R)
587 check_c_source_compiles(
588 "#include <netdb.h>
589
590 int
591 main(void)
592 {
593 struct netent netent_buf;
594 struct netent_data net_data;
595
596 return getnetbyname_r((const char *)0, &netent_buf, &net_data);
597 }
598 "
599 HAVE_AIX_GETNETBYNAME_R)
600 endif(NOT HAVE_SOLARIS_IRIX_GETNETBYNAME_R)
601 endif(NOT HAVE_LINUX_GETNETBYNAME_R)
602 endif(NETDB_H_DECLARES_GETNETBYNAME_R)
603 cmake_pop_check_state()
604
605 #
606 # Check for reentrant versions of getprotobyname_r(), as provided by
607 # Linux (glibc), Solaris/IRIX, and AIX (with three different APIs!).
608 # If we don't find one, we just use getprotobyname(), which uses
609 # thread-specific data on many platforms, but doesn't use it on
610 # NetBSD or OpenBSD, and may not use it on older versions of other
611 # platforms.
612 #
613 # Only do the check if we have a declaration of getprotobyname_r();
614 # without it, we can't check which API it has. (We assume that
615 # if there's a declaration, it has a prototype, so that the API
616 # can be checked.)
617 #
618 cmake_push_check_state()
619 set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LINK_LIBRARIES})
620 check_symbol_exists(getprotobyname_r netdb.h NETDB_H_DECLARES_GETPROTOBYNAME_R)
621 if(NETDB_H_DECLARES_GETPROTOBYNAME_R)
622 check_c_source_compiles(
623 "#include <netdb.h>
624
625 int
626 main(void)
627 {
628 struct protoent protoent_buf;
629 char buf[1024];
630 struct protoent *resultp;
631
632 return getprotobyname_r((const char *)0, &protoent_buf, buf, sizeof buf, &resultp);
633 }
634 "
635 HAVE_LINUX_GETPROTOBYNAME_R)
636 if(NOT HAVE_LINUX_GETPROTOBYNAME_R)
637 check_c_source_compiles(
638 "#include <netdb.h>
639
640 int
641 main(void)
642 {
643 struct protoent protoent_buf;
644 char buf[1024];
645
646 return getprotobyname_r((const char *)0, &protoent_buf, buf, (int)sizeof buf) != NULL;
647 }
648 "
649 HAVE_SOLARIS_IRIX_GETPROTOBYNAME_R)
650 if(NOT HAVE_SOLARIS_IRIX_GETPROTOBYNAME_R)
651 check_c_source_compiles(
652 "#include <netdb.h>
653
654 int
655 main(void)
656 {
657 struct protoent protoent_buf;
658 struct protoent_data proto_data;
659
660 return getprotobyname_r((const char *)0, &protoent_buf, &proto_data);
661 }
662 "
663 HAVE_AIX_GETPROTOBYNAME_R)
664 endif(NOT HAVE_SOLARIS_IRIX_GETPROTOBYNAME_R)
665 endif(NOT HAVE_LINUX_GETPROTOBYNAME_R)
666 endif(NETDB_H_DECLARES_GETPROTOBYNAME_R)
667 cmake_pop_check_state()
668
669 #
670 # Data types.
671 #
672 # XXX - there's no check_type() macro that's like check_type_size()
673 # except that it only checks for the existence of the structure type,
674 # so we use check_type_size() and ignore the size.
675 #
676 cmake_push_check_state()
677 if(WIN32)
678 set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h)
679 else(WIN32)
680 set(CMAKE_EXTRA_INCLUDE_FILES unistd.h sys/socket.h)
681 endif(WIN32)
682 check_type_size("struct sockaddr_storage" STRUCT_SOCKADDR_STORAGE)
683 check_type_size("socklen_t" SOCKLEN_T)
684 cmake_pop_check_state()
685
686 #
687 # Structure fields.
688 #
689 if(WIN32)
690 check_struct_has_member("struct sockaddr" sa_len winsock2.h HAVE_STRUCT_SOCKADDR_SA_LEN)
691 else(WIN32)
692 check_struct_has_member("struct sockaddr" sa_len sys/socket.h HAVE_STRUCT_SOCKADDR_SA_LEN)
693 endif(WIN32)
694
695 #
696 # Do we have ffs(), and is it declared in <strings.h>?
697 #
698 check_function_exists(ffs HAVE_FFS)
699 if(HAVE_FFS)
700 #
701 # OK, we have ffs(). Is it declared in <strings.h>?
702 #
703 # This test fails if we don't have <strings.h> or if we do
704 # but it doesn't declare ffs().
705 #
706 check_symbol_exists(ffs strings.h STRINGS_H_DECLARES_FFS)
707 endif()
708
709 #
710 # This requires the libraries that we require, as ether_hostton might be
711 # in one of those libraries. That means we have to do this after
712 # we check for those libraries.
713 #
714 # You are in a twisty little maze of UN*Xes, all different.
715 # Some might not have ether_hostton().
716 # Some might have it and declare it in <net/ethernet.h>.
717 # Some might have it and declare it in <netinet/ether.h>
718 # Some might have it and declare it in <sys/ethernet.h>.
719 # Some might have it and declare it in <arpa/inet.h>.
720 # Some might have it and declare it in <netinet/if_ether.h>.
721 # Some might have it and not declare it in any header file.
722 #
723 # Before you is a C compiler.
724 #
725 cmake_push_check_state()
726 set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LINK_LIBRARIES})
727 check_function_exists(ether_hostton HAVE_ETHER_HOSTTON)
728 if(HAVE_ETHER_HOSTTON)
729 #
730 # OK, we have ether_hostton(). Is it declared in <net/ethernet.h>?
731 #
732 # This test fails if we don't have <net/ethernet.h> or if we do
733 # but it doesn't declare ether_hostton().
734 #
735 check_symbol_exists(ether_hostton net/ethernet.h NET_ETHERNET_H_DECLARES_ETHER_HOSTTON)
736 if(NET_ETHERNET_H_DECLARES_ETHER_HOSTTON)
737 #
738 # Yes - we have it declared.
739 #
740 set(HAVE_DECL_ETHER_HOSTTON TRUE)
741 endif()
742 #
743 # Did that succeed?
744 #
745 if(NOT HAVE_DECL_ETHER_HOSTTON)
746 #
747 # No - how about <netinet/ether.h>, as on Linux?
748 #
749 # This test fails if we don't have <netinet/ether.h>
750 # or if we do but it doesn't declare ether_hostton().
751 #
752 check_symbol_exists(ether_hostton netinet/ether.h NETINET_ETHER_H_DECLARES_ETHER_HOSTTON)
753 if(NETINET_ETHER_H_DECLARES_ETHER_HOSTTON)
754 #
755 # Yes - we have it declared.
756 #
757 set(HAVE_DECL_ETHER_HOSTTON TRUE)
758 endif()
759 endif()
760 #
761 # Did that succeed?
762 #
763 if(NOT HAVE_DECL_ETHER_HOSTTON)
764 #
765 # No - how about <sys/ethernet.h>, as on Solaris 10 and later?
766 #
767 # This test fails if we don't have <sys/ethernet.h>
768 # or if we do but it doesn't declare ether_hostton().
769 #
770 check_symbol_exists(ether_hostton sys/ethernet.h SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON)
771 if(SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON)
772 #
773 # Yes - we have it declared.
774 #
775 set(HAVE_DECL_ETHER_HOSTTON TRUE)
776 endif()
777 endif()
778 #
779 # Did that succeed?
780 #
781 if(NOT HAVE_DECL_ETHER_HOSTTON)
782 #
783 # No, how about <arpa/inet.h>, as on AIX?
784 #
785 # This test fails if we don't have <arpa/inet.h>
786 # or if we do but it doesn't declare ether_hostton().
787 #
788 check_symbol_exists(ether_hostton arpa/inet.h ARPA_INET_H_DECLARES_ETHER_HOSTTON)
789 if(ARPA_INET_H_DECLARES_ETHER_HOSTTON)
790 #
791 # Yes - we have it declared.
792 #
793 set(HAVE_DECL_ETHER_HOSTTON TRUE)
794 endif()
795 endif()
796 #
797 # Did that succeed?
798 #
799 if(NOT HAVE_DECL_ETHER_HOSTTON)
800 #
801 # No, how about <netinet/if_ether.h>?
802 # On some platforms, it requires <net/if.h> and
803 # <netinet/in.h>, and we always include it with
804 # both of them, so test it with both of them.
805 #
806 # This test fails if we don't have <netinet/if_ether.h>
807 # and the headers we include before it, or if we do but
808 # <netinet/if_ether.h> doesn't declare ether_hostton().
809 #
810 check_symbol_exists(ether_hostton "sys/types.h;sys/socket.h;net/if.h;netinet/in.h;netinet/if_ether.h" NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON)
811 if(NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON)
812 #
813 # Yes - we have it declared.
814 #
815 set(HAVE_DECL_ETHER_HOSTTON TRUE)
816 endif()
817 endif()
818 #
819 # After all that, is ether_hostton() declared?
820 #
821 if(NOT HAVE_DECL_ETHER_HOSTTON)
822 #
823 # No, we'll have to declare it ourselves.
824 # Do we have "struct ether_addr" if we include <netinet/if_ether.h>?
825 #
826 # XXX - there's no check_type() macro that's like check_type_size()
827 # except that it only checks for the existence of the structure type,
828 # so we use check_type_size() and ignore the size.
829 #
830 cmake_push_check_state()
831 set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h sys/socket.h net/if.h netinet/in.h netinet/if_ether.h)
832 check_type_size("struct ether_addr" STRUCT_ETHER_ADDR)
833 cmake_pop_check_state()
834 endif()
835 endif()
836 cmake_pop_check_state()
837
838 #
839 # Large file support on UN*X, a/k/a LFS.
840 #
841 if(NOT WIN32)
842 include(FindLFS)
843 if(LFS_FOUND)
844 #
845 # Add the required #defines.
846 #
847 add_definitions(${LFS_DEFINITIONS})
848 endif()
849
850 #
851 # Check for fseeko as well.
852 #
853 include(FindFseeko)
854 if(FSEEKO_FOUND)
855 set(HAVE_FSEEKO ON)
856
857 #
858 # Add the required #defines.
859 #
860 add_definitions(${FSEEKO_DEFINITIONS})
861 endif()
862 endif()
863
864 if(INET6)
865 message(STATUS "Support IPv6")
866 endif(INET6)
867
868 #
869 # Pthreads.
870 # We might need them, because some libraries we use might use them,
871 # but we don't necessarily need them.
872 # That's only on UN*X; on Windows, if they use threads, we assume
873 # they're native Windows threads.
874 #
875 if(NOT WIN32)
876 set(CMAKE_THREAD_PREFER_PTHREAD ON)
877 find_package(Threads)
878 if(NOT CMAKE_USE_PTHREADS_INIT)
879 #
880 # If it's not pthreads, we won't use it; we use it for libraries
881 # that require it.
882 #
883 set(CMAKE_THREAD_LIBS_INIT "")
884 endif(NOT CMAKE_USE_PTHREADS_INIT)
885 endif(NOT WIN32)
886
887 #
888 # Based on
889 #
890 # https://github.com/commonmark/cmark/blob/master/FindAsan.cmake
891 #
892 # The MIT License (MIT)
893 #
894 # Copyright (c) 2013 Matthew Arsenault
895 #
896 # Permission is hereby granted, free of charge, to any person obtaining a copy
897 # of this software and associated documentation files (the "Software"), to deal
898 # in the Software without restriction, including without limitation the rights
899 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
900 # copies of the Software, and to permit persons to whom the Software is
901 # furnished to do so, subject to the following conditions:
902 #
903 # The above copyright notice and this permission notice shall be included in
904 # all copies or substantial portions of the Software.
905 #
906 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
907 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
908 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
909 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
910 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
911 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
912 # THE SOFTWARE.
913 #
914 # Test if the each of the sanitizers in the ENABLE_SANITIZERS list are
915 # supported by the compiler, and, if so, adds the appropriate flags to
916 # CMAKE_C_FLAGS, CMAKE_CXX_FLAGS, and SANITIZER_FLAGS. If not, it fails.
917 #
918 # Do this last, in the hope that it will prevent configuration on Linux
919 # from somehow deciding it doesn't need -lpthread when building rpcapd
920 # (it does require it, but somehow, in some mysterious fashion that no
921 # obvious CMake debugging flag reveals, it doesn't realize that if we
922 # turn sanitizer stuff on).
923 #
924 set(SANITIZER_FLAGS "")
925 foreach(sanitizer IN LISTS ENABLE_SANITIZERS)
926 # Set -Werror to catch "argument unused during compilation" warnings
927
928 message(STATUS "Checking sanitizer ${sanitizer}")
929 set(sanitizer_variable "sanitize_${sanitizer}")
930 set(CMAKE_REQUIRED_FLAGS "-Werror -fsanitize=${sanitizer}")
931 check_c_compiler_flag("-fsanitize=${sanitizer}" ${sanitizer_variable})
932 if(${${sanitizer_variable}})
933 set(SANITIZER_FLAGS "${SANITIZER_FLAGS} -fsanitize=${sanitizer}")
934 message(STATUS "${sanitizer} sanitizer supported using -fsanitizer=${sanitizer}")
935 else()
936 #
937 # Try the versions supported prior to Clang 3.2.
938 # If the sanitizer is "address", try -fsanitize-address.
939 # If it's "undefined", try -fcatch-undefined-behavior.
940 # Otherwise, give up.
941 #
942 set(sanitizer_variable "OLD_${sanitizer_variable}")
943 if ("${sanitizer}" STREQUAL "address")
944 set(CMAKE_REQUIRED_FLAGS "-Werror -fsanitize-address")
945 check_c_compiler_flag("-fsanitize-address" ${sanitizer_variable})
946 if(${${sanitizer_variable}})
947 set(SANITIZER_FLAGS "${SANITIZER_FLAGS} -fsanitize-address")
948 message(STATUS "${sanitizer} sanitizer supported using -fsanitize-address")
949 else()
950 message(FATAL_ERROR "${sanitizer} isn't a supported sanitizer")
951 endif()
952 elseif("${sanitizer}" STREQUAL "undefined")
953 set(CMAKE_REQUIRED_FLAGS "-Werror -fcatch-undefined-behavior")
954 check_c_compiler_flag("-fcatch-undefined-behavior" ${sanitizer_variable})
955 if(${${sanitizer_variable}})
956 set(SANITIZER_FLAGS "${SANITIZER_FLAGS} -fcatch-undefined-behavior")
957 message(STATUS "${sanitizer} sanitizer supported using catch-undefined-behavior")
958 else()
959 message(FATAL_ERROR "${sanitizer} isn't a supported sanitizer")
960 endif()
961 else()
962 message(FATAL_ERROR "${sanitizer} isn't a supported sanitizer")
963 endif()
964 endif()
965
966 unset(CMAKE_REQUIRED_FLAGS)
967 endforeach()
968
969 if(NOT "${SANITIZER_FLAGS}" STREQUAL "")
970 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O1 -g ${SANITIZER_FLAGS} -fno-omit-frame-pointer -fno-optimize-sibling-calls")
971 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1 -g ${SANITIZER_FLAGS} -fno-omit-frame-pointer -fno-optimize-sibling-calls")
972 endif()
973
974 #
975 # OpenSSL/libressl.
976 #
977 find_package(OpenSSL)
978 if(OPENSSL_FOUND)
979 #
980 # We have OpenSSL.
981 #
982 include_directories(SYSTEM ${OPENSSL_INCLUDE_DIR})
983 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${OPENSSL_LIBRARIES})
984 set(HAVE_OPENSSL YES)
985 endif(OPENSSL_FOUND)
986
987 ######################################
988 # Input files
989 ######################################
990
991 set(PROJECT_SOURCE_LIST_C
992 bpf_dump.c
993 bpf_filter.c
994 bpf_image.c
995 etherent.c
996 fmtutils.c
997 gencode.c
998 nametoaddr.c
999 optimize.c
1000 pcap-common.c
1001 pcap.c
1002 savefile.c
1003 sf-pcapng.c
1004 sf-pcap.c
1005 )
1006
1007 if(WIN32)
1008 #
1009 # We assume we don't have asprintf(), and provide an implementation
1010 # that uses _vscprintf() to determine how big the string needs to be.
1011 #
1012 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C}
1013 missing/win_asprintf.c)
1014 else()
1015 if(NOT HAVE_ASPRINTF)
1016 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/asprintf.c)
1017 endif()
1018 if(NOT HAVE_STRLCAT)
1019 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/strlcat.c)
1020 endif(NOT HAVE_STRLCAT)
1021 if(NOT HAVE_STRLCPY)
1022 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/strlcpy.c)
1023 endif(NOT HAVE_STRLCPY)
1024 if(NOT HAVE_STRTOK_R)
1025 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/strtok_r.c)
1026 endif(NOT HAVE_STRTOK_R)
1027 endif(WIN32)
1028
1029 #
1030 # Determine the main pcap-XXX.c file to use, and the libraries with
1031 # which we need to link libpcap, if any.
1032 #
1033 if(WIN32)
1034 #
1035 # Windows.
1036 #
1037 # Has the user explicitly specified a capture type?
1038 #
1039 if(PCAP_TYPE STREQUAL "")
1040 #
1041 # The user didn't explicitly specify a capture mechanism.
1042 # Check whether we have packet.dll.
1043 #
1044 if(HAVE_PACKET32)
1045 #
1046 # We have packet.dll.
1047 # Set the capture type to NPF.
1048 #
1049 set(PCAP_TYPE npf)
1050 else()
1051 #
1052 # We don't have any capture type we know about, so just use
1053 # the null capture type, and only support reading (and writing)
1054 # capture files.
1055 #
1056 set(PCAP_TYPE null)
1057 endif()
1058 endif()
1059 else()
1060 #
1061 # UN*X.
1062 #
1063 # Figure out what type of packet capture mechanism we have, and
1064 # what libraries we'd need to link libpcap with, if any.
1065 #
1066
1067 #
1068 # Has the user explicitly specified a capture type?
1069 #
1070 if(PCAP_TYPE STREQUAL "")
1071 #
1072 # Check for a bunch of headers for various packet capture mechanisms.
1073 #
1074 check_include_files("sys/types.h;net/bpf.h" HAVE_NET_BPF_H)
1075 if(HAVE_NET_BPF_H)
1076 #
1077 # Does it define BIOCSETIF?
1078 # I.e., is it a header for an LBL/BSD-style capture
1079 # mechanism, or is it just a header for a BPF filter
1080 # engine? Some versions of Arch Linux, for example,
1081 # have a net/bpf.h that doesn't define BIOCSETIF;
1082 # as it's a Linux, it should use packet sockets,
1083 # instead.
1084 #
1085 # We need:
1086 #
1087 # sys/types.h, because FreeBSD 10's net/bpf.h
1088 # requires that various BSD-style integer types
1089 # be defined;
1090 #
1091 # sys/time.h, because AIX 5.2 and 5.3's net/bpf.h
1092 # doesn't include it but does use struct timeval
1093 # in ioctl definitions;
1094 #
1095 # sys/ioctl.h and, if we have it, sys/ioccom.h,
1096 # because net/bpf.h defines ioctls;
1097 #
1098 # net/if.h, because it defines some structures
1099 # used in ioctls defined by net/bpf.h;
1100 #
1101 # sys/socket.h, because OpenBSD 5.9's net/bpf.h
1102 # defines some structure fields as being
1103 # struct sockaddrs;
1104 #
1105 # and net/bpf.h doesn't necessarily include all
1106 # of those headers itself.
1107 #
1108 if(HAVE_SYS_IOCCOM_H)
1109 check_symbol_exists(BIOCSETIF "sys/types.h;sys/time.h;sys/ioctl.h;sys/socket.h;sys/ioccom.h;net/bpf.h;net/if.h" BPF_H_DEFINES_BIOCSETIF)
1110 else(HAVE_SYS_IOCCOM_H)
1111 check_symbol_exists(BIOCSETIF "sys/types.h;sys/time.h;sys/ioctl.h;sys/socket.h;net/bpf.h;net/if.h" BPF_H_DEFINES_BIOCSETIF)
1112 endif(HAVE_SYS_IOCCOM_H)
1113 endif(HAVE_NET_BPF_H)
1114 check_include_file(net/pfilt.h HAVE_NET_PFILT_H)
1115 check_include_file(net/enet.h HAVE_NET_ENET_H)
1116 check_include_file(net/nit.h HAVE_NET_NIT_H)
1117 check_include_file(sys/net/nit.h HAVE_SYS_NET_NIT_H)
1118 check_include_file(linux/socket.h HAVE_LINUX_SOCKET_H)
1119 check_include_file(net/raw.h HAVE_NET_RAW_H)
1120 check_include_file(sys/dlpi.h HAVE_SYS_DLPI_H)
1121 check_include_file(config/HaikuConfig.h HAVE_CONFIG_HAIKUCONFIG_H)
1122
1123 if(BPF_H_DEFINES_BIOCSETIF)
1124 #
1125 # BPF.
1126 # Check this before DLPI, so that we pick BPF on
1127 # Solaris 11 and later.
1128 #
1129 set(PCAP_TYPE bpf)
1130 elseif(HAVE_LINUX_SOCKET_H)
1131 #
1132 # No prizes for guessing this one.
1133 #
1134 set(PCAP_TYPE linux)
1135 elseif(HAVE_NET_PFILT_H)
1136 #
1137 # DEC OSF/1, Digital UNIX, Tru64 UNIX
1138 #
1139 set(PCAP_TYPE pf)
1140 elseif(HAVE_NET_ENET_H)
1141 #
1142 # Stanford Enetfilter.
1143 #
1144 set(PCAP_TYPE enet)
1145 elseif(HAVE_NET_NIT_H)
1146 #
1147 # SunOS 4.x STREAMS NIT.
1148 #
1149 set(PCAP_TYPE snit)
1150 elseif(HAVE_SYS_NET_NIT_H)
1151 #
1152 # Pre-SunOS 4.x non-STREAMS NIT.
1153 #
1154 set(PCAP_TYPE nit)
1155 elseif(HAVE_NET_RAW_H)
1156 #
1157 # IRIX snoop.
1158 #
1159 set(PCAP_TYPE snoop)
1160 elseif(HAVE_SYS_DLPI_H)
1161 #
1162 # DLPI on pre-Solaris 11 SunOS 5, HP-UX, possibly others.
1163 #
1164 set(PCAP_TYPE dlpi)
1165 elseif(HAVE_CONFIG_HAIKUCONFIG_H)
1166 #
1167 # Haiku.
1168 #
1169 set(PCAP_TYPE haiku)
1170 else()
1171 #
1172 # Nothing we support.
1173 #
1174 set(PCAP_TYPE null)
1175 endif()
1176 endif()
1177 endif(WIN32)
1178 message(STATUS "Packet capture mechanism type: ${PCAP_TYPE}")
1179
1180 #
1181 # Do capture-mechanism-dependent tests.
1182 #
1183 if(WIN32)
1184 if(PCAP_TYPE STREQUAL "npf")
1185 #
1186 # Link with packet.dll before WinSock2.
1187 #
1188 set(PCAP_LINK_LIBRARIES ${PACKET_LIBRARIES} ${PCAP_LINK_LIBRARIES})
1189 elseif(PCAP_TYPE STREQUAL "null")
1190 else()
1191 message(FATAL_ERROR "${PCAP_TYPE} is not a valid pcap type")
1192 endif()
1193 else(WIN32)
1194 if(PCAP_TYPE STREQUAL "dlpi")
1195 #
1196 # Needed for common functions used by pcap-[dlpi,libdlpi].c
1197 #
1198 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} dlpisubs.c)
1199
1200 #
1201 # Checks for some header files.
1202 #
1203 check_include_file(sys/bufmod.h HAVE_SYS_BUFMOD_H)
1204 check_include_file(sys/dlpi_ext.h HAVE_SYS_DLPI_EXT_H)
1205
1206 #
1207 # Checks to see if Solaris has the public libdlpi(3LIB) library.
1208 # Note: The existence of /usr/include/libdlpi.h does not mean it is the
1209 # public libdlpi(3LIB) version. Before libdlpi was made public, a
1210 # private version also existed, which did not have the same APIs.
1211 # Due to a gcc bug, the default search path for 32-bit libraries does
1212 # not include /lib, we add it explicitly here.
1213 # [http://bugs.opensolaris.org/view_bug.do?bug_id=6619485].
1214 # Also, due to the bug above applications that link to libpcap with
1215 # libdlpi will have to add "-L/lib" option to "configure".
1216 #
1217 cmake_push_check_state()
1218 set(CMAKE_REQUIRED_FLAGS "-L/lib")
1219 set(CMAKE_REQUIRED_LIBRARIES dlpi)
1220 check_function_exists(dlpi_walk HAVE_LIBDLPI)
1221 cmake_pop_check_state()
1222 if(HAVE_LIBDLPI)
1223 #
1224 # XXX - add -L/lib
1225 #
1226 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} dlpi)
1227 set(PCAP_TYPE libdlpi)
1228 endif()
1229
1230 #
1231 # This check is for Solaris with DLPI support for passive modes.
1232 # See dlpi(7P) for more details.
1233 #
1234 # XXX - there's no check_type() macro that's like check_type_size()
1235 # except that it only checks for the existence of the structure type,
1236 # so we use check_type_size() and ignore the size.
1237 #
1238 cmake_push_check_state()
1239 set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h sys/dlpi.h)
1240 check_type_size(dl_passive_req_t DL_PASSIVE_REQ_T)
1241 cmake_pop_check_state()
1242 elseif(PCAP_TYPE STREQUAL "linux")
1243 #
1244 # Do we have the wireless extensions?
1245 # linux/wireless.h requires sys/socket.h.
1246 #
1247 check_include_files("sys/socket.h;linux/wireless.h" HAVE_LINUX_WIRELESS_H)
1248
1249 #
1250 # Do we have libnl?
1251 #
1252 if(BUILD_WITH_LIBNL)
1253 #
1254 # Try libnl 3.x first.
1255 #
1256 cmake_push_check_state()
1257 set(CMAKE_REQUIRED_LIBRARIES nl-3)
1258 check_function_exists(nl_socket_alloc HAVE_LIBNL)
1259 cmake_pop_check_state()
1260 if(HAVE_LIBNL)
1261 #
1262 # Yes, we have libnl 3.x.
1263 #
1264 set(PCAP_LINK_LIBRARIES nl-genl-3 nl-3 ${PCAP_LINK_LIBRARIES})
1265 set(HAVE_LIBNL_3_x ON)
1266 set(HAVE_LIBNL_NLE ON)
1267 set(HAVE_LIBNL_SOCKETS ON)
1268 include_directories("/usr/include/libnl3")
1269 else()
1270 #
1271 # Try libnl 2.x.
1272 #
1273 cmake_push_check_state()
1274 set(CMAKE_REQUIRED_LIBRARIES nl)
1275 check_function_exists(nl_socket_alloc HAVE_LIBNL)
1276 cmake_pop_check_state()
1277 if(HAVE_LIBNL)
1278 #
1279 # Yes, we have libnl 2.x.
1280 #
1281 set(PCAP_LINK_LIBRARIES nl-genl nl ${PCAP_LINK_LIBRARIES})
1282 set(HAVE_LIBNL_2_x ON)
1283 set(HAVE_LIBNL_NLE ON)
1284 set(HAVE_LIBNL_SOCKETS ON)
1285 else()
1286 #
1287 # No, we don't; do we have libnl 1.x?
1288 #
1289 cmake_push_check_state()
1290 set(CMAKE_REQUIRED_LIBRARIES nl)
1291 check_function_exists(nl_handle_alloc HAVE_LIBNL)
1292 cmake_pop_check_state()
1293 if(HAVE_LIBNL)
1294 set(PCAP_LINK_LIBRARIES nl ${PCAP_LINK_LIBRARIES})
1295 endif()
1296 endif()
1297 endif()
1298 endif()
1299
1300 check_include_file(linux/ethtool.h HAVE_LINUX_ETHTOOL_H)
1301
1302 #
1303 # Checks to see if tpacket_stats is defined in linux/if_packet.h
1304 # If so then pcap-linux.c can use this to report proper statistics.
1305 #
1306 # XXX - there's no check_type() macro that's like check_type_size()
1307 # except that it only checks for the existence of the structure type,
1308 # so we use check_type_size() and ignore the size.
1309 #
1310 cmake_push_check_state()
1311 set(CMAKE_EXTRA_INCLUDE_FILES linux/if_packet.h)
1312 check_type_size("struct tpacket_stats" STRUCT_TPACKET_STATS)
1313 cmake_pop_check_state()
1314
1315 check_struct_has_member("struct tpacket_auxdata" tp_vlan_tci linux/if_packet.h HAVE_STRUCT_TPACKET_AUXDATA_TP_VLAN_TCI)
1316 elseif(PCAP_TYPE STREQUAL "bpf")
1317 #
1318 # Check whether we have the *BSD-style ioctls.
1319 #
1320 check_include_files("sys/types.h;net/if_media.h" HAVE_NET_IF_MEDIA_H)
1321
1322 #
1323 # Check whether we have struct BPF_TIMEVAL.
1324 #
1325 # XXX - there's no check_type() macro that's like check_type_size()
1326 # except that it only checks for the existence of the structure type,
1327 # so we use check_type_size() and ignore the size.
1328 #
1329 cmake_push_check_state()
1330 if(HAVE_SYS_IOCCOM_H)
1331 set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h sys/ioccom.h net/bpf.h)
1332 check_type_size("struct BPF_TIMEVAL" STRUCT_BPF_TIMEVAL)
1333 else()
1334 set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h net/bpf.h)
1335 check_type_size("struct BPF_TIMEVAL" STRUCT_BPF_TIMEVAL)
1336 endif()
1337 cmake_pop_check_state()
1338 elseif(PCAP_TYPE STREQUAL "haiku")
1339 #
1340 # Check for some headers just in case.
1341 #
1342 check_include_files("net/if.h;net/if_dl.h;net/if_types.h" HAVE_NET_IF_TYPES_H)
1343 set(PCAP_SRC pcap-${PCAP_TYPE}.cpp)
1344 elseif(PCAP_TYPE STREQUAL "null")
1345 else()
1346 message(FATAL_ERROR "${PCAP_TYPE} is not a valid pcap type")
1347 endif()
1348 endif(WIN32)
1349
1350 if(NOT DEFINED PCAP_SRC)
1351 set(PCAP_SRC pcap-${PCAP_TYPE}.c)
1352 endif()
1353
1354 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${PCAP_SRC})
1355
1356 #
1357 # Now figure out how we get a list of interfaces and addresses,
1358 # if we support capturing. Don't bother if we don't support
1359 # capturing.
1360 #
1361 if(NOT WIN32)
1362 #
1363 # UN*X - figure out what type of interface list mechanism we
1364 # have.
1365 #
1366 # If the capture type is null, that means we can't capture,
1367 # so we can't open any capture devices, so we won't return
1368 # any interfaces.
1369 #
1370 if(NOT PCAP_TYPE STREQUAL "null")
1371 cmake_push_check_state()
1372 set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LINK_LIBRARIES})
1373 check_function_exists(getifaddrs HAVE_GETIFADDRS)
1374 cmake_pop_check_state()
1375 if(NOT HAVE_GETIFADDRS)
1376 #
1377 # It's not in the libraries that, at this point, we've
1378 # found we need to link libpcap with.
1379 #
1380 # It's in libsocket on Solaris and possibly other OSes;
1381 # as long as we're not linking with libxnet, check there.
1382 #
1383 # NOTE: if you hand check_library_exists as its last
1384 # argument a variable that's been set, it skips the test,
1385 # so we need different variables.
1386 #
1387 if(NOT LIBXNET_HAS_GETHOSTBYNAME)
1388 check_library_exists(socket getifaddrs "" SOCKET_HAS_GETIFADDRS)
1389 if(SOCKET_HAS_GETIFADDRS)
1390 set(PCAP_LINK_LIBRARIES socket ${PCAP_LINK_LIBRARIES})
1391 set(HAVE_GETIFADDRS TRUE)
1392 endif()
1393 endif()
1394 endif()
1395 if(HAVE_GETIFADDRS)
1396 #
1397 # We have "getifaddrs()"; make sure we have <ifaddrs.h>
1398 # as well, just in case some platform is really weird.
1399 # It may require that sys/types.h be included first,
1400 # so include it first.
1401 #
1402 check_include_files("sys/types.h;ifaddrs.h" HAVE_IFADDRS_H)
1403 if(HAVE_IFADDRS_H)
1404 #
1405 # We have the header, so we use "getifaddrs()" to
1406 # get the list of interfaces.
1407 #
1408 set(FINDALLDEVS_TYPE getad)
1409 else()
1410 #
1411 # We don't have the header - give up.
1412 # XXX - we could also fall back on some other
1413 # mechanism, but, for now, this'll catch this
1414 # problem so that we can at least try to figure
1415 # out something to do on systems with "getifaddrs()"
1416 # but without "ifaddrs.h", if there is something
1417 # we can do on those systems.
1418 #
1419 message(FATAL_ERROR "Your system has getifaddrs() but doesn't have a usable <ifaddrs.h>.")
1420 endif()
1421 else()
1422 #
1423 # Well, we don't have "getifaddrs()", at least not with the
1424 # libraries with which we've decided we need to link
1425 # libpcap with, so we have to use some other mechanism.
1426 #
1427 # Note that this may happen on Solaris, which has
1428 # getifaddrs(), but in -lsocket, not in -lxnet, so we
1429 # won't find it if we link with -lxnet, which we want
1430 # to do for other reasons.
1431 #
1432 # For now, we use either the SIOCGIFCONF ioctl or the
1433 # SIOCGLIFCONF ioctl, preferring the latter if we have
1434 # it; the latter is a Solarisism that first appeared
1435 # in Solaris 8. (Solaris's getifaddrs() appears to
1436 # be built atop SIOCGLIFCONF; using it directly
1437 # avoids a not-all-that-useful middleman.)
1438 #
1439 try_compile(HAVE_SIOCGLIFCONF ${CMAKE_CURRENT_BINARY_DIR} "${pcap_SOURCE_DIR}/cmake/have_siocglifconf.c" )
1440 if(HAVE_SIOCGLIFCONF)
1441 set(FINDALLDEVS_TYPE glifc)
1442 else()
1443 set(FINDALLDEVS_TYPE gifc)
1444 endif()
1445 endif()
1446 message(STATUS "Find-interfaces mechanism type: ${FINDALLDEVS_TYPE}")
1447 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} fad-${FINDALLDEVS_TYPE}.c)
1448 endif()
1449 endif()
1450
1451 # Check for hardware timestamp support.
1452 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
1453 check_include_file(linux/net_tstamp.h HAVE_LINUX_NET_TSTAMP_H)
1454 endif()
1455
1456 #
1457 # Check for additional native sniffing capabilities.
1458 #
1459
1460 # Check for USB sniffing support on Linux.
1461 # On FreeBSD, it uses BPF, so we don't need to do anything special here.
1462 if(NOT DISABLE_USB)
1463 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
1464 set(PCAP_SUPPORT_USB TRUE)
1465 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-usb-linux.c)
1466 set(LINUX_USB_MON_DEV /dev/usbmon)
1467 #
1468 # Do we have a version of <linux/compiler.h> available?
1469 # If so, we might need it for <linux/usbdevice_fs.h>.
1470 #
1471 check_include_files("linux/compiler.h" HAVE_LINUX_COMPILER_H)
1472 if(HAVE_LINUX_COMPILER_H)
1473 #
1474 # Yes - include it when testing for <linux/usbdevice_fs.h>.
1475 #
1476 check_include_files("linux/compiler.h;linux/usbdevice_fs.h" HAVE_LINUX_USBDEVICE_FS_H)
1477 else(HAVE_LINUX_COMPILER_H)
1478 check_include_files("linux/usbdevice_fs.h" HAVE_LINUX_USBDEVICE_FS_H)
1479 endif(HAVE_LINUX_COMPILER_H)
1480 if(HAVE_LINUX_USBDEVICE_FS_H)
1481 #
1482 # OK, does it define bRequestType? Older versions of the kernel
1483 # define fields with names like "requesttype, "request", and
1484 # "value", rather than "bRequestType", "bRequest", and
1485 # "wValue".
1486 #
1487 if(HAVE_LINUX_COMPILER_H)
1488 check_struct_has_member("struct usbdevfs_ctrltransfer" bRequestType "linux/compiler.h;linux/usbdevice_fs.h" HAVE_STRUCT_USBDEVFS_CTRLTRANSFER_BREQUESTTYPE)
1489 else(HAVE_LINUX_COMPILER_H)
1490 check_struct_has_member("struct usbdevfs_ctrltransfer" bRequestType "linux/usbdevice_fs.h" HAVE_STRUCT_USBDEVFS_CTRLTRANSFER_BREQUESTTYPE)
1491 endif(HAVE_LINUX_COMPILER_H)
1492 endif()
1493 endif()
1494 endif()
1495
1496 # Check for netfilter sniffing support.
1497 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
1498 #
1499 # Life's too short to deal with trying to get this to compile
1500 # if you don't get the right types defined with
1501 # __KERNEL_STRICT_NAMES getting defined by some other include.
1502 #
1503 # Check whether the includes Just Work. If not, don't turn on
1504 # netfilter support.
1505 #
1506 check_c_source_compiles(
1507 "#include <sys/socket.h>
1508 #include <netinet/in.h>
1509 #include <linux/types.h>
1510
1511 #include <linux/netlink.h>
1512 #include <linux/netfilter.h>
1513 #include <linux/netfilter/nfnetlink.h>
1514 #include <linux/netfilter/nfnetlink_log.h>
1515 #include <linux/netfilter/nfnetlink_queue.h>
1516
1517 int
1518 main(void)
1519 {
1520 return 0;
1521 }
1522 "
1523 PCAP_SUPPORT_NETFILTER)
1524 if(PCAP_SUPPORT_NETFILTER)
1525 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-netfilter-linux.c)
1526 endif(PCAP_SUPPORT_NETFILTER)
1527 endif()
1528
1529 # Check for netmap sniffing support.
1530 if(NOT DISABLE_NETMAP)
1531 #
1532 # Check whether net/netmap_user.h is usable if NETMAP_WITH_LIBS is
1533 # defined; it's not usable on DragonFly BSD 4.6 if NETMAP_WITH_LIBS
1534 # is defined, for example, as it includes a non-existent malloc.h
1535 # header.
1536 #
1537 check_c_source_compiles(
1538 "#define NETMAP_WITH_LIBS
1539 #include <net/netmap_user.h>
1540
1541 int
1542 main(void)
1543 {
1544 return 0;
1545 }
1546 "
1547 PCAP_SUPPORT_NETMAP)
1548 if(PCAP_SUPPORT_NETMAP)
1549 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-netmap.c)
1550 endif(PCAP_SUPPORT_NETMAP)
1551 endif()
1552
1553 # Check for DPDK sniffing support
1554 if(NOT DISABLE_DPDK)
1555 find_package(dpdk)
1556 if(dpdk_FOUND)
1557 #
1558 # We include rte_bus.h, and older versions of DPDK didn't have
1559 # it, so check for it.
1560 #
1561 cmake_push_check_state()
1562 set(CMAKE_REQUIRED_INCLUDES ${dpdk_INCLUDE_DIRS})
1563 check_include_file(rte_bus.h HAVE_RTE_BUS_H)
1564 cmake_pop_check_state()
1565 if(HAVE_RTE_BUS_H)
1566 set(DPDK_C_FLAGS "-march=native")
1567 set(DPDK_LIB dpdk rt m numa dl)
1568 set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} ${DPDK_C_FLAGS})
1569 include_directories(AFTER ${dpdk_INCLUDE_DIRS})
1570 link_directories(AFTER ${dpdk_LIBRARIES})
1571 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${dpdk_LIBRARIES})
1572 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-dpdk.c)
1573 set(PCAP_SUPPORT_DPDK TRUE)
1574 endif()
1575 endif()
1576 endif()
1577
1578 # Check for Bluetooth sniffing support
1579 if(NOT DISABLE_BLUETOOTH)
1580 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
1581 check_include_file(bluetooth/bluetooth.h HAVE_BLUETOOTH_BLUETOOTH_H)
1582 if(HAVE_BLUETOOTH_BLUETOOTH_H)
1583 set(PCAP_SUPPORT_BT TRUE)
1584 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-bt-linux.c)
1585 #
1586 # OK, does struct sockaddr_hci have an hci_channel
1587 # member?
1588 #
1589 check_struct_has_member("struct sockaddr_hci" hci_channel "bluetooth/bluetooth.h;bluetooth/hci.h" HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL)
1590 if(HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL)
1591 #
1592 # OK, is HCI_CHANNEL_MONITOR defined?
1593 #
1594 check_c_source_compiles(
1595 "#include <bluetooth/bluetooth.h>
1596 #include <bluetooth/hci.h>
1597
1598 int
1599 main(void)
1600 {
1601 u_int i = HCI_CHANNEL_MONITOR;
1602 return 0;
1603 }
1604 "
1605 PCAP_SUPPORT_BT_MONITOR)
1606 if(PCAP_SUPPORT_BT_MONITOR)
1607 #
1608 # Yes, so we can also support Bluetooth monitor
1609 # sniffing.
1610 #
1611 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-bt-monitor-linux.c)
1612 endif(PCAP_SUPPORT_BT_MONITOR)
1613 endif(HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL)
1614 endif(HAVE_BLUETOOTH_BLUETOOTH_H)
1615 endif()
1616 endif()
1617
1618 # Check for Bluetooth sniffing support
1619 if(NOT DISABLE_DBUS)
1620 #
1621 # We don't support D-Bus sniffing on macOS; see
1622 #
1623 # https://bugs.freedesktop.org/show_bug.cgi?id=74029
1624 #
1625 if(APPLE)
1626 message(FATAL_ERROR "Due to freedesktop.org bug 74029, D-Bus capture support is not available on macOS")
1627 endif(APPLE)
1628 pkg_check_modules(DBUS dbus-1)
1629 if(DBUS_FOUND)
1630 set(PCAP_SUPPORT_DBUS TRUE)
1631 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-dbus.c)
1632 include_directories(${DBUS_INCLUDE_DIRS})
1633
1634 #
1635 # This "helpfully" supplies DBUS_LIBRARIES as a bunch of
1636 # library names - not paths - and DBUS_LIBRARY_DIRS as
1637 # a bunch of directories.
1638 #
1639 # CMake *really* doesn't like the notion of specifying "here are
1640 # the directories in which to look for libraries" except in
1641 # find_library() calls; it *really* prefers using full paths to
1642 # library files, rather than library names.
1643 #
1644 # Find the libraries and add their full paths.
1645 #
1646 set(DBUS_LIBRARY_FULLPATHS)
1647 foreach(_lib IN LISTS DBUS_LIBRARIES)
1648 #
1649 # Try to find this library, so we get its full path.
1650 #
1651 find_library(_libfullpath ${_lib} HINTS ${DBUS_LIBRARY_DIRS})
1652 list(APPEND DBUS_LIBRARY_FULLPATHS ${_libfullpath})
1653 endforeach()
1654 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${DBUS_LIBRARY_FULLPATHS})
1655 endif(DBUS_FOUND)
1656 endif(NOT DISABLE_DBUS)
1657
1658 # Check for RDMA sniffing support
1659 if(NOT DISABLE_RDMA)
1660 check_library_exists(ibverbs ibv_get_device_list "" LIBIBVERBS_HAS_IBV_GET_DEVICE_LIST)
1661 if(LIBIBVERBS_HAS_IBV_GET_DEVICE_LIST)
1662 check_include_file(infiniband/verbs.h HAVE_INFINIBAND_VERBS_H)
1663 if(HAVE_INFINIBAND_VERBS_H)
1664 check_symbol_exists(ibv_create_flow infiniband/verbs.h PCAP_SUPPORT_RDMASNIFF)
1665 if(PCAP_SUPPORT_RDMASNIFF)
1666 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-rdmasniff.c)
1667 set(PCAP_LINK_LIBRARIES ibverbs ${PCAP_LINK_LIBRARIES})
1668 endif(PCAP_SUPPORT_RDMASNIFF)
1669 endif(HAVE_INFINIBAND_VERBS_H)
1670 endif(LIBIBVERBS_HAS_IBV_GET_DEVICE_LIST)
1671 endif(NOT DISABLE_RDMA)
1672
1673 #
1674 # Check for sniffing capabilities using third-party APIs.
1675 #
1676
1677 # Check for Endace DAG card support.
1678 if(NOT DISABLE_DAG)
1679 #
1680 # Try to find the DAG header file and library.
1681 #
1682 find_package(DAG)
1683
1684 #
1685 # Did we succeed?
1686 #
1687 if(DAG_FOUND)
1688 #
1689 # Yes.
1690 # Check for various DAG API functions.
1691 #
1692 cmake_push_check_state()
1693 set(CMAKE_REQUIRED_INCLUDES ${DAG_INCLUDE_DIRS})
1694 set(CMAKE_REQUIRED_LIBRARIES ${DAG_LIBRARIES})
1695 check_function_exists(dag_attach_stream HAVE_DAG_STREAMS_API)
1696 if(NOT HAVE_DAG_STREAMS_API)
1697 message(FATAL_ERROR "DAG library lacks streams support")
1698 endif()
1699 check_function_exists(dag_attach_stream64 HAVE_DAG_LARGE_STREAMS_API)
1700 check_function_exists(dag_get_erf_types HAVE_DAG_GET_ERF_TYPES)
1701 check_function_exists(dag_get_stream_erf_types HAVE_DAG_GET_STREAM_ERF_TYPES)
1702 cmake_pop_check_state()
1703
1704 include_directories(AFTER ${DAG_INCLUDE_DIRS})
1705 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-dag.c)
1706 set(HAVE_DAG_API TRUE)
1707 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${DAG_LIBRARIES})
1708
1709 if(HAVE_DAG_LARGE_STREAMS_API)
1710 get_filename_component(DAG_LIBRARY_DIR ${DAG_LIBRARY} PATH)
1711 check_library_exists(vdag vdag_set_device_info ${DAG_LIBRARY_DIR} HAVE_DAG_VDAG)
1712 if(HAVE_DAG_VDAG)
1713 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
1714 endif()
1715 endif()
1716 endif()
1717 endif()
1718
1719 # Check for Septel card support.
1720 set(PROJECT_EXTERNAL_OBJECT_LIST "")
1721 if(NOT DISABLE_SEPTEL)
1722 #
1723 # Do we have the msg.h header?
1724 #
1725 set(SEPTEL_INCLUDE_DIRS "${SEPTEL_ROOT}/INC")
1726 cmake_push_check_state()
1727 set(CMAKE_REQUIRED_INCLUDES ${SEPTEL_INCLUDE_DIRS})
1728 check_include_file(msg.h HAVE_INC_MSG_H)
1729 cmake_pop_check_state()
1730 if(HAVE_INC_MSG_H)
1731 #
1732 # Yes.
1733 #
1734 include_directories(AFTER ${SEPTEL_INCLUDE_DIRS})
1735 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-septel.c)
1736 set(PROJECT_EXTERNAL_OBJECT_LIST ${PROJECT_EXTERNAL_OBJECT_LIST} "${SEPTEL_ROOT}/asciibin.o ${SEPTEL_ROOT}/bit2byte.o ${SEPTEL_ROOT}/confirm.o ${SEPTEL_ROOT}/fmtmsg.o ${SEPTEL_ROOT}/gct_unix.o ${SEPTEL_ROOT}/hqueue.o ${SEPTEL_ROOT}/ident.o ${SEPTEL_ROOT}/mem.o ${SEPTEL_ROOT}/pack.o ${SEPTEL_ROOT}/parse.o ${SEPTEL_ROOT}/pool.o ${SEPTEL_ROOT}/sdlsig.o ${SEPTEL_ROOT}/strtonum.o ${SEPTEL_ROOT}/timer.o ${SEPTEL_ROOT}/trace.o")
1737 set(HAVE_SEPTEL_API TRUE)
1738 endif()
1739 endif()
1740
1741 # Check for Myricom SNF support.
1742 if(NOT DISABLE_SNF)
1743 #
1744 # Try to find the SNF header file and library.
1745 #
1746 find_package(SNF)
1747
1748 #
1749 # Did we succeed?
1750 #
1751 if(SNF_FOUND)
1752 #
1753 # Yes.
1754 #
1755 include_directories(AFTER ${SNF_INCLUDE_DIRS})
1756 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-snf.c)
1757 set(HAVE_SNF_API TRUE)
1758 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${SNF_LIBRARIES})
1759 endif()
1760 endif()
1761
1762 # Check for Riverbed TurboCap support.
1763 if(NOT DISABLE_TC)
1764 #
1765 # Try to find the TurboCap header file and library.
1766 #
1767 find_package(TC)
1768
1769 #
1770 # Did we succeed?
1771 #
1772 if(TC_FOUND)
1773 #
1774 # Yes.
1775 #
1776 include_directories(AFTER ${TC_INCLUDE_DIRS})
1777 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-tc.c)
1778 set(HAVE_TC_API TRUE)
1779 set(PCAP_LINK_LIBRARIES "${PCAP_LINK_LIBRARIES} ${TC_LIBRARIES} ${CMAKE_USE_PTHREADS_INIT} stdc++")
1780 endif()
1781 endif()
1782
1783 #
1784 # Remote capture support.
1785 #
1786
1787 if(ENABLE_REMOTE)
1788 #
1789 # Check for various members of struct msghdr.
1790 # We need to include ftmacros.h on some platforms, to make sure we
1791 # get the POSIX/Single USER Specification version of struct msghdr,
1792 # which has those members, rather than the backwards-compatible
1793 # version, which doesn't. That's not a system header file, and
1794 # at least some versions of CMake include it as <ftmacros.h>, which
1795 # won't check the current directory, so we add the top-level
1796 # source directory to the list of include directories when we do
1797 # the check.
1798 #
1799 cmake_push_check_state()
1800 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR})
1801 check_struct_has_member("struct msghdr" msg_control "ftmacros.h;sys/socket.h" HAVE_STRUCT_MSGHDR_MSG_CONTROL)
1802 check_struct_has_member("struct msghdr" msg_flags "ftmacros.h;sys/socket.h" HAVE_STRUCT_MSGHDR_MSG_FLAGS)
1803 cmake_pop_check_state()
1804 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C}
1805 pcap-new.c pcap-rpcap.c rpcap-protocol.c sockutils.c sslutils.c)
1806 endif(ENABLE_REMOTE)
1807
1808 ###################################################################
1809 # Warning options
1810 ###################################################################
1811
1812 #
1813 # Check and add warning options if we have a .devel file.
1814 #
1815 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.devel OR EXISTS ${CMAKE_BINARY_DIR}/.devel)
1816 #
1817 # Warning options.
1818 #
1819 if(MSVC AND NOT ${CMAKE_C_COMPILER} MATCHES "clang*")
1820 #
1821 # MSVC, with Microsoft's front end and code generator.
1822 # "MSVC" is also set for Microsoft's compiler with a Clang
1823 # front end and their code generator ("Clang/C2"), so we
1824 # check for clang.exe and treat that differently.
1825 #
1826 check_and_add_compiler_option(-Wall)
1827 #
1828 # Disable some pointless warnings that /Wall turns on.
1829 #
1830 # Unfortunately, MSVC does not appear to have an equivalent
1831 # to "__attribute__((unused))" to mark a particular function
1832 # parameter as being known to be unused, so that the compiler
1833 # won't warn about it (for example, the function might have
1834 # that parameter because a pointer to it is being used, and
1835 # the signature of that function includes that parameter).
1836 # C++ lets you give a parameter a type but no name, but C
1837 # doesn't have that.
1838 #
1839 check_and_add_compiler_option(-wd4100)
1840 #
1841 # In theory, we care whether somebody uses f() rather than
1842 # f(void) to declare a function with no arguments, but, in
1843 # practice, there are places in the Windows header files
1844 # that appear to do that, so we squelch that warning.
1845 #
1846 check_and_add_compiler_option(-wd4255)
1847 #
1848 # Windows FD_SET() generates this, so we suppress it.
1849 #
1850 check_and_add_compiler_option(-wd4548)
1851 #
1852 # Perhaps testing something #defined to be 0 with #ifdef is an
1853 # error, and it should be tested with #if, but perhaps it's
1854 # not, and Microsoft does that in its headers, so we squelch
1855 # that warning.
1856 #
1857 check_and_add_compiler_option(-wd4574)
1858 #
1859 # The Windows headers also test not-defined values in #if, so
1860 # we don't want warnings about that, either.
1861 #
1862 check_and_add_compiler_option(-wd4668)
1863 #
1864 # We do *not* care whether some function is, or isn't, going to be
1865 # expanded inline.
1866 #
1867 check_and_add_compiler_option(-wd4710)
1868 check_and_add_compiler_option(-wd4711)
1869 #
1870 # We do *not* care whether we're adding padding bytes after
1871 # structure members.
1872 #
1873 check_and_add_compiler_option(-wd4820)
1874 #
1875 # We do *not* care about every single place the compiler would
1876 # have inserted Spectre mitigation if only we had told it to
1877 # do so with /Qspectre. Maybe it's worth it, as that's in
1878 # Bison-generated code that we don't control.
1879 #
1880 # XXX - add /Qspectre if that is really worth doing.
1881 #
1882 check_and_add_compiler_option(-wd5045)
1883 else()
1884 #
1885 # Other compilers, including MSVC with a Clang front end and
1886 # Microsoft's code generator. We currently treat them as if
1887 # they might support GCC-style -W options.
1888 #
1889 check_and_add_compiler_option(-Wall)
1890 check_and_add_compiler_option(-Wcomma)
1891 # Warns about safeguards added in case the enums are extended
1892 # check_and_add_compiler_option(-Wcovered-switch-default)
1893 check_and_add_compiler_option(-Wdocumentation)
1894 check_and_add_compiler_option(-Wformat-nonliteral)
1895 check_and_add_compiler_option(-Wmissing-noreturn)
1896 check_and_add_compiler_option(-Wmissing-prototypes)
1897 check_and_add_compiler_option(-Wmissing-variable-declarations)
1898 check_and_add_compiler_option(-Wpointer-arith)
1899 check_and_add_compiler_option(-Wpointer-sign)
1900 check_and_add_compiler_option(-Wshadow)
1901 check_and_add_compiler_option(-Wsign-compare)
1902 check_and_add_compiler_option(-Wshorten-64-to-32)
1903 check_and_add_compiler_option(-Wstrict-prototypes)
1904 check_and_add_compiler_option(-Wunreachable-code)
1905 check_and_add_compiler_option(-Wunused-parameter)
1906 check_and_add_compiler_option(-Wused-but-marked-unused)
1907 endif()
1908 endif()
1909
1910 #
1911 # Suppress some warnings we get with MSVC even without /Wall.
1912 #
1913 if(MSVC AND NOT ${CMAKE_C_COMPILER} MATCHES "clang*")
1914 #
1915 # Yes, we have some functions that never return but that
1916 # have a non-void return type. That's because, on some
1917 # platforms, they *do* return values but, on other
1918 # platforms, including Windows, they just fail and
1919 # longjmp out by calling bpf_error().
1920 #
1921 check_and_add_compiler_option(-wd4646)
1922 endif()
1923
1924 file(GLOB PROJECT_SOURCE_LIST_H
1925 *.h
1926 pcap/*.h
1927 )
1928
1929 #
1930 # Try to have the compiler default to hiding symbols, so that only
1931 # symbols explicitly exported with PCAP_API will be visible outside
1932 # (shared) libraries.
1933 #
1934 # Not necessary with MSVC, as that's the default.
1935 #
1936 # XXX - we don't use ADD_COMPILER_EXPORT_FLAGS, because, as of CMake
1937 # 2.8.12.2, it doesn't know about Sun C/Oracle Studio, and, as of
1938 # CMake 2.8.6, it only sets the C++ compiler flags, rather than
1939 # allowing an arbitrary variable to be set with the "hide symbols
1940 # not explicitly exported" flag.
1941 #
1942 if(NOT MSVC)
1943 if(CMAKE_C_COMPILER_ID MATCHES "SunPro")
1944 #
1945 # Sun C/Oracle Studio.
1946 #
1947 check_and_add_compiler_option(-xldscope=hidden)
1948 else()
1949 #
1950 # Try this for all other compilers; it's what GCC uses,
1951 # and a number of other compilers, such as Clang and Intel C,
1952 # use it as well.
1953 #
1954 check_and_add_compiler_option(-fvisibility=hidden)
1955 endif()
1956 endif(NOT MSVC)
1957
1958 #
1959 # Flex/Lex and YACC/Berkeley YACC/Bison.
1960 # From a mail message to the CMake mailing list by Andy Cedilnik of
1961 # Kitware.
1962 #
1963
1964 #
1965 # Try to find Flex, a Windows version of Flex, or Lex.
1966 #
1967 find_program(LEX_EXECUTABLE NAMES flex win_flex lex)
1968 if(LEX_EXECUTABLE STREQUAL "LEX_EXECUTABLE-NOTFOUND")
1969 message(FATAL_ERROR "Neither flex nor win_flex nor lex was found.")
1970 endif()
1971 message(STATUS "Lexical analyzer generator: ${LEX_EXECUTABLE}")
1972
1973 add_custom_command(
1974 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/scanner.c ${CMAKE_CURRENT_BINARY_DIR}/scanner.h
1975 SOURCE ${pcap_SOURCE_DIR}/scanner.l
1976 COMMAND ${LEX_EXECUTABLE} -P pcap_ --header-file=scanner.h --nounput -o${CMAKE_CURRENT_BINARY_DIR}/scanner.c ${pcap_SOURCE_DIR}/scanner.l
1977 DEPENDS ${pcap_SOURCE_DIR}/scanner.l
1978 )
1979
1980 #
1981 # Since scanner.c does not exist yet when cmake is run, mark
1982 # it as generated.
1983 #
1984 # Since scanner.c includes grammar.h, mark that as a dependency.
1985 #
1986 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/scanner.c PROPERTIES
1987 GENERATED TRUE
1988 OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/grammar.h
1989 )
1990
1991 #
1992 # Add scanner.c to the list of sources.
1993 #
1994 #set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${CMAKE_CURRENT_BINARY_DIR}/scanner.c)
1995
1996 #
1997 # Try to find YACC or Bison.
1998 #
1999 find_program(YACC_EXECUTABLE NAMES bison win_bison byacc yacc)
2000 if(YACC_EXECUTABLE STREQUAL "YACC_EXECUTABLE-NOTFOUND")
2001 message(FATAL_ERROR "Neither bison nor win_bison nor byacc nor yacc was found.")
2002 endif()
2003 message(STATUS "Parser generator: ${YACC_EXECUTABLE}")
2004
2005 #
2006 # Create custom command for the scanner.
2007 # Find out whether it's Bison or not by looking at the last component
2008 # of the path (without a .exe extension, if this is Windows).
2009 #
2010 get_filename_component(YACC_NAME ${YACC_EXECUTABLE} NAME_WE)
2011 if("${YACC_NAME}" STREQUAL "bison" OR "${YACC_NAME}" STREQUAL "win_bison")
2012 set(YACC_COMPATIBILITY_FLAG "-y")
2013 endif()
2014 add_custom_command(
2015 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/grammar.c ${CMAKE_CURRENT_BINARY_DIR}/grammar.h
2016 SOURCE ${pcap_SOURCE_DIR}/grammar.y
2017 COMMAND ${YACC_EXECUTABLE} ${YACC_COMPATIBILITY_FLAG} -p pcap_ -o ${CMAKE_CURRENT_BINARY_DIR}/grammar.c -d ${pcap_SOURCE_DIR}/grammar.y
2018 DEPENDS ${pcap_SOURCE_DIR}/grammar.y
2019 )
2020
2021 #
2022 # Since grammar.c does not exists yet when cmake is run, mark
2023 # it as generated.
2024 #
2025 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/grammar.c PROPERTIES
2026 GENERATED TRUE
2027 OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/scanner.h
2028 )
2029
2030 #
2031 # Add grammar.c to the list of sources.
2032 #
2033 #set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${CMAKE_CURRENT_BINARY_DIR}/grammar.c)
2034
2035 #
2036 # Assume, by default, no support for shared libraries and V7/BSD
2037 # convention for man pages (devices in section 4, file formats in
2038 # section 5, miscellaneous info in section 7, administrative commands
2039 # and daemons in section 8). Individual cases can override this.
2040 # Individual cases can override this.
2041 #
2042 set(MAN_DEVICES 4)
2043 set(MAN_FILE_FORMATS 5)
2044 set(MAN_MISC_INFO 7)
2045 set(MAN_ADMIN_COMMANDS 8)
2046 if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
2047 # Workaround to enable certain features
2048 set(_SUN TRUE)
2049 if(PCAP_TYPE STREQUAL "bpf")
2050 #
2051 # If we're using BPF, we need libodm and libcfg, as
2052 # we use them to load the BPF module.
2053 #
2054 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} odm cfg)
2055 endif()
2056 elseif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
2057 if(CMAKE_SYSTEM_VERSION MATCHES "[A-Z.]*9\.[0-9]*")
2058 #
2059 # HP-UX 9.x.
2060 #
2061 set(HAVE_HPUX9 TRUE)
2062 elseif(CMAKE_SYSTEM_VERSION MATCHES "[A-Z.]*10\.0")
2063 #
2064 # HP-UX 10.0.
2065 #
2066 elseif(CMAKE_SYSTEM_VERSION MATCHES "[A-Z.]*10\.1")
2067 #
2068 # HP-UX 10.1.
2069 #
2070 else()
2071 #
2072 # HP-UX 10.20 and later.
2073 #
2074 set(HAVE_HPUX10_20_OR_LATER TRUE)
2075 endif()
2076
2077 #
2078 # Use System V conventions for man pages.
2079 #
2080 set(MAN_ADMIN_COMMANDS 1m)
2081 set(MAN_FILE_FORMATS 4)
2082 set(MAN_MISC_INFO 5)
2083 elseif(CMAKE_SYSTEM_NAME STREQUAL "IRIX" OR CMAKE_SYSTEM_NAME STREQUAL "IRIX64")
2084 #
2085 # Use IRIX conventions for man pages; they're the same as the
2086 # System V conventions, except that they use section 8 for
2087 # administrative commands and daemons.
2088 #
2089 set(MAN_FILE_FORMATS 4)
2090 set(MAN_MISC_INFO 5)
2091 elseif(CMAKE_SYSTEM_NAME STREQUAL "OSF1")
2092 #
2093 # DEC OSF/1, a/k/a Digial UNIX, a/k/a Tru64 UNIX.
2094 # Use Tru64 UNIX conventions for man pages; they're the same as the
2095 # System V conventions except that they use section 8 for
2096 # administrative commands and daemons.
2097 #
2098 set(MAN_FILE_FORMATS 4)
2099 set(MAN_MISC_INFO 5)
2100 set(MAN_DEVICES 7)
2101 elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_VERSION MATCHES "5[.][0-9.]*")
2102 #
2103 # SunOS 5.x.
2104 #
2105 set(HAVE_SOLARIS TRUE)
2106 #
2107 # Make sure errno is thread-safe, in case we're called in
2108 # a multithreaded program. We don't guarantee that two
2109 # threads can use the *same* pcap_t safely, but the
2110 # current version does guarantee that you can use different
2111 # pcap_t's in different threads, and even that pcap_compile()
2112 # is thread-safe (it wasn't thread-safe in some older versions).
2113 #
2114 add_definitions(-D_TS_ERRNO)
2115
2116 if(CMAKE_SYSTEM_VERSION STREQUAL "5.12")
2117 else()
2118 #
2119 # Use System V conventions for man pages.
2120 #
2121 set(MAN_ADMIN_COMMANDS 1m)
2122 set(MAN_FILE_FORMATS 4)
2123 set(MAN_MISC_INFO 5)
2124 set(MAN_DEVICES 7D)
2125 endif()
2126 elseif(CMAKE_SYSTEM_NAME STREQUAL "Haiku")
2127 #
2128 # Haiku needs _BSD_SOURCE for the _IO* macros because it doesn't use them.
2129 #
2130 add_definitions(-D_BSD_SOURCE)
2131 endif()
2132
2133 source_group("Source Files" FILES ${PROJECT_SOURCE_LIST_C})
2134 source_group("Header Files" FILES ${PROJECT_SOURCE_LIST_H})
2135
2136 if(WIN32)
2137 #
2138 # Add pcap-dll.rc to the list of sources.
2139 #
2140 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${pcap_SOURCE_DIR}/pcap-dll.rc)
2141 endif(WIN32)
2142
2143 #
2144 # Add subdirectories after we've set various variables, so they pick up
2145 # pick up those variables.
2146 #
2147 if(ENABLE_REMOTE)
2148 add_subdirectory(rpcapd)
2149 endif(ENABLE_REMOTE)
2150 add_subdirectory(testprogs)
2151
2152 ######################################
2153 # Register targets
2154 ######################################
2155
2156 #
2157 # Special target to serialize the building of the generated source.
2158 #
2159 # See
2160 #
2161 # http://public.kitware.com/pipermail/cmake/2013-August/055510.html
2162 #
2163 add_custom_target(SerializeTarget
2164 DEPENDS
2165 ${CMAKE_CURRENT_BINARY_DIR}/grammar.c
2166 ${CMAKE_CURRENT_BINARY_DIR}/scanner.c
2167 )
2168
2169 set_source_files_properties(${PROJECT_EXTERNAL_OBJECT_LIST} PROPERTIES
2170 EXTERNAL_OBJECT TRUE)
2171
2172 if(BUILD_SHARED_LIBS)
2173 add_library(${LIBRARY_NAME} SHARED
2174 ${PROJECT_SOURCE_LIST_C}
2175 ${CMAKE_CURRENT_BINARY_DIR}/grammar.c
2176 ${CMAKE_CURRENT_BINARY_DIR}/scanner.c
2177 ${PROJECT_EXTERNAL_OBJECT_LIST}
2178 )
2179 add_dependencies(${LIBRARY_NAME} SerializeTarget)
2180 set_target_properties(${LIBRARY_NAME} PROPERTIES
2181 COMPILE_DEFINITIONS BUILDING_PCAP)
2182 #
2183 # No matter what the library is called - it might be called "wpcap"
2184 # in a Windows build - the symbol to define to indicate that we're
2185 # building the library, rather than a program using the library,
2186 # and thus that we're exporting functions defined in our public
2187 # header files, rather than importing those functions, is
2188 # pcap_EXPORTS.
2189 #
2190 set_target_properties(${LIBRARY_NAME} PROPERTIES
2191 DEFINE_SYMBOL pcap_EXPORTS)
2192 if(NOT "${SANITIZER_FLAGS}" STREQUAL "")
2193 set_target_properties(${LIBRARY_NAME} PROPERTIES
2194 LINK_FLAGS "${SANITIZER_FLAGS}")
2195 endif()
2196 endif(BUILD_SHARED_LIBS)
2197
2198 add_library(${LIBRARY_NAME}_static STATIC
2199 ${PROJECT_SOURCE_LIST_C}
2200 ${CMAKE_CURRENT_BINARY_DIR}/grammar.c
2201 ${CMAKE_CURRENT_BINARY_DIR}/scanner.c
2202 ${PROJECT_EXTERNAL_OBJECT_LIST}
2203 )
2204 add_dependencies(${LIBRARY_NAME}_static SerializeTarget)
2205 set_target_properties(${LIBRARY_NAME}_static PROPERTIES
2206 COMPILE_DEFINITIONS BUILDING_PCAP)
2207
2208 if(WIN32)
2209 if(BUILD_SHARED_LIBS)
2210 set_target_properties(${LIBRARY_NAME} PROPERTIES
2211 VERSION ${PACKAGE_VERSION_NOSUFFIX} # only MAJOR and MINOR are needed
2212 )
2213 endif(BUILD_SHARED_LIBS)
2214 if(MSVC)
2215 # XXX For DLLs, the TARGET_PDB_FILE generator expression can be used to locate
2216 # its PDB file's output directory for installation.
2217 # cmake doesn't offer a generator expression for PDB files generated by the
2218 # compiler (static libraries).
2219 # So instead of considering any possible output there is (there are many),
2220 # this will search for the PDB file in the compiler's initial output directory,
2221 # which is always ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles\wpcap_static.dir
2222 # regardless of architecture, build generator etc.
2223 # Quite hackish indeed.
2224 set(CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY $<TARGET_FILE_DIR:${LIBRARY_NAME}_static>)
2225 set_target_properties(${LIBRARY_NAME}_static PROPERTIES
2226 COMPILE_PDB_NAME ${LIBRARY_NAME}_static
2227 OUTPUT_NAME "${LIBRARY_NAME}_static"
2228 )
2229 elseif(MINGW)
2230 #
2231 # For compatibility, build the shared library without the "lib" prefix on
2232 # MinGW as well.
2233 #
2234 set_target_properties(${LIBRARY_NAME} PROPERTIES
2235 PREFIX ""
2236 OUTPUT_NAME "${LIBRARY_NAME}"
2237 )
2238 set_target_properties(${LIBRARY_NAME}_static PROPERTIES
2239 OUTPUT_NAME "${LIBRARY_NAME}"
2240 )
2241 endif()
2242 else(WIN32) # UN*X
2243 if(BUILD_SHARED_LIBS)
2244 if(APPLE)
2245 set_target_properties(${LIBRARY_NAME} PROPERTIES
2246 VERSION ${PACKAGE_VERSION}
2247 SOVERSION A
2248 )
2249 else(APPLE)
2250 set_target_properties(${LIBRARY_NAME} PROPERTIES
2251 VERSION ${PACKAGE_VERSION}
2252 SOVERSION ${PACKAGE_VERSION_MAJOR}
2253 )
2254 endif(APPLE)
2255 endif(BUILD_SHARED_LIBS)
2256 set_target_properties(${LIBRARY_NAME}_static PROPERTIES
2257 OUTPUT_NAME "${LIBRARY_NAME}"
2258 )
2259 endif(WIN32)
2260
2261 if(BUILD_SHARED_LIBS)
2262 if(NOT C_ADDITIONAL_FLAGS STREQUAL "")
2263 set_target_properties(${LIBRARY_NAME} PROPERTIES COMPILE_FLAGS ${C_ADDITIONAL_FLAGS})
2264 endif()
2265 target_link_libraries(${LIBRARY_NAME} ${PCAP_LINK_LIBRARIES})
2266 endif(BUILD_SHARED_LIBS)
2267
2268 if(NOT C_ADDITIONAL_FLAGS STREQUAL "")
2269 set_target_properties(${LIBRARY_NAME}_static PROPERTIES COMPILE_FLAGS ${C_ADDITIONAL_FLAGS})
2270 endif()
2271
2272 #
2273 # On macOS, build libpcap for the appropriate architectures, if
2274 # CMAKE_OSX_ARCHITECTURES isn't set (if it is, let that control
2275 # the architectures for which to build it).
2276 #
2277 if(APPLE AND "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "")
2278 #
2279 # Get the major version of Darwin.
2280 #
2281 string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MAJOR "${CMAKE_SYSTEM_VERSION}")
2282
2283 if(SYSTEM_VERSION_MAJOR LESS 8)
2284 #
2285 # Pre-Tiger. Build only for 32-bit PowerPC.
2286 #
2287 set(OSX_LIBRARY_ARCHITECTURES "ppc")
2288 elseif(SYSTEM_VERSION_MAJOR EQUAL 8)
2289 #
2290 # Tiger. Is this prior to, or with, Intel support?
2291 #
2292 # Get the minor version of Darwin.
2293 #
2294 string(REPLACE "${SYSTEM_VERSION_MAJOR}." "" SYSTEM_MINOR_AND_PATCH_VERSION ${CMAKE_SYSTEM_VERSION})
2295 string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MINOR "${SYSTEM_MINOR_AND_PATCH_VERSION}")
2296 if(SYSTEM_VERSION_MINOR LESS 4)
2297 #
2298 # Prior to Intel support. Build for 32-bit
2299 # PowerPC and 64-bit PowerPC, with 32-bit PowerPC
2300 # first. (I'm guessing that's what Apple does.)
2301 #
2302 set(OSX_LIBRARY_ARCHITECTURES "ppc;ppc64")
2303 elseif(SYSTEM_VERSION_MINOR LESS 7)
2304 #
2305 # With Intel support but prior to x86-64 support.
2306 # Build for 32-bit PowerPC, 64-bit PowerPC, and 32-bit x86,
2307 # with 32-bit PowerPC first.
2308 # (I'm guessing that's what Apple does.)
2309 #
2310 set(OSX_LIBRARY_ARCHITECTURES "ppc;ppc64;i386")
2311 else()
2312 #
2313 # With Intel support including x86-64 support.
2314 # Build for 32-bit PowerPC, 64-bit PowerPC, 32-bit x86,
2315 # and x86-64, with 32-bit PowerPC first.
2316 # (I'm guessing that's what Apple does.)
2317 #
2318 set(OSX_LIBRARY_ARCHITECTURES "ppc;ppc64;i386;x86_64")
2319 endif()
2320 elseif(SYSTEM_VERSION_MAJOR EQUAL 9)
2321 #
2322 # Leopard. Build for 32-bit PowerPC, 64-bit
2323 # PowerPC, 32-bit x86, and x86-64, with 32-bit PowerPC
2324 # first. (That's what Apple does.)
2325 #
2326 set(OSX_LIBRARY_ARCHITECTURES "ppc;ppc64;i386;x86_64")
2327 elseif(SYSTEM_VERSION_MAJOR EQUAL 10)
2328 #
2329 # Snow Leopard. Build for x86-64, 32-bit x86, and
2330 # 32-bit PowerPC, with x86-64 first. (That's
2331 # what Apple does, even though Snow Leopard
2332 # doesn't run on PPC, so PPC libpcap runs under
2333 # Rosetta, and Rosetta doesn't support BPF
2334 # ioctls, so PPC programs can't do live
2335 # captures.)
2336 #
2337 set(OSX_LIBRARY_ARCHITECTURES "x86_64;i386;ppc")
2338 else()
2339 #
2340 # Post-Snow Leopard. Build for x86-64 and 32-bit x86,
2341 # with x86-64 first. (That's what Apple does)
2342 # XXX - update if and when Apple drops support
2343 # for 32-bit x86 code and if and when Apple adds
2344 # ARM-based Macs. (You're on your own for iOS etc.)
2345 #
2346 # First, check whether we're building with OpenSSL.
2347 # If so, don't bother trying to build fat.
2348 #
2349 if(HAVE_OPENSSL)
2350 set(X86_32_BIT_SUPPORTED NO)
2351 set(OSX_LIBRARY_ARCHITECTURES "x86_64")
2352 message(WARNING "We're assuming the OpenSSL libraries are 64-bit only, so we're not compiling for 32-bit x86")
2353 else()
2354 #
2355 # Now, check whether we *can* build for i386.
2356 #
2357 cmake_push_check_state()
2358 set(CMAKE_REQUIRED_FLAGS "-arch i386")
2359 check_c_source_compiles(
2360 "int
2361 main(void)
2362 {
2363 return 0;
2364 }
2365 "
2366 X86_32_BIT_SUPPORTED)
2367 cmake_pop_check_state()
2368 if(X86_32_BIT_SUPPORTED)
2369 set(OSX_LIBRARY_ARCHITECTURES "x86_64;i386")
2370 else()
2371 set(OSX_LIBRARY_ARCHITECTURES "x86_64")
2372 #
2373 # We can't build fat; suggest that the user install the
2374 # /usr/include headers if they want to build fat.
2375 #
2376 if(SYSTEM_VERSION_MAJOR LESS 18)
2377 #
2378 # Pre-Mojave; the command-line tools should be sufficient to
2379 # enable 32-bit x86 builds.
2380 #
2381 message(WARNING "Compiling for 32-bit x86 gives an error; try installing the command-line tools")
2382 else()
2383 message(WARNING "Compiling for 32-bit x86 gives an error; try installing the command-line tools and, after that, installing the /usr/include headers from the /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg package")
2384 endif()
2385 endif()
2386 endif()
2387 endif()
2388 if(BUILD_SHARED_LIBS)
2389 set_target_properties(${LIBRARY_NAME} PROPERTIES
2390 OSX_ARCHITECTURES "${OSX_LIBRARY_ARCHITECTURES}")
2391 endif(BUILD_SHARED_LIBS)
2392 set_target_properties(${LIBRARY_NAME}_static PROPERTIES
2393 OSX_ARCHITECTURES "${OSX_LIBRARY_ARCHITECTURES}")
2394 endif()
2395
2396 ######################################
2397 # Write out the config.h file
2398 ######################################
2399
2400 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
2401
2402 ######################################
2403 # Install pcap library, include files, and man pages
2404 ######################################
2405
2406 #
2407 # "Define GNU standard installation directories", which actually
2408 # are also defined, to some degree, by autotools, and at least
2409 # some of which are general UN*X conventions.
2410 #
2411 include(GNUInstallDirs)
2412
2413 set(LIBRARY_NAME_STATIC ${LIBRARY_NAME}_static)
2414
2415 function(install_manpage_symlink SOURCE TARGET MANDIR)
2416 if(MINGW)
2417 find_program(LINK_EXECUTABLE ln)
2418 if(LINK_EXECUTABLE)
2419 set(LINK_COMMAND "\"${LINK_EXECUTABLE}\" \"-s\" \"${SOURCE}\" \"${TARGET}\"")
2420 else(LINK_EXECUTABLE)
2421 message(FATAL_ERROR "ln (http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ln.html) not found.")
2422 endif(LINK_EXECUTABLE)
2423 else(MINGW)
2424 set(LINK_COMMAND "\"${CMAKE_COMMAND}\" \"-E\" \"create_symlink\" \"${SOURCE}\" \"${TARGET}\"")
2425 endif(MINGW)
2426
2427 install(CODE
2428 "message(STATUS \"Symlinking: ${CMAKE_INSTALL_PREFIX}/${MANDIR}/${SOURCE} to ${TARGET}\")
2429 execute_process(
2430 COMMAND \"${CMAKE_COMMAND}\" \"-E\" \"remove\" \"${TARGET}\"
2431 WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${MANDIR}
2432 )
2433 execute_process(
2434 COMMAND ${LINK_COMMAND}
2435 WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${MANDIR}
2436 RESULT_VARIABLE EXIT_STATUS
2437 )
2438 if(NOT EXIT_STATUS EQUAL 0)
2439 message(FATAL_ERROR \"Could not create symbolic link from ${CMAKE_INSTALL_PREFIX}/${MANDIR}/${SOURCE} to ${TARGET}\")
2440 endif()
2441 set(CMAKE_INSTALL_MANIFEST_FILES \${CMAKE_INSTALL_MANIFEST_FILES} ${CMAKE_INSTALL_PREFIX}/${MANDIR}/${TARGET})")
2442 endfunction(install_manpage_symlink)
2443
2444 set(MAN1_NOEXPAND pcap-config.1)
2445 set(MAN3PCAP_EXPAND
2446 pcap.3pcap.in
2447 pcap_compile.3pcap.in
2448 pcap_datalink.3pcap.in
2449 pcap_dump_open.3pcap.in
2450 pcap_get_tstamp_precision.3pcap.in
2451 pcap_list_datalinks.3pcap.in
2452 pcap_list_tstamp_types.3pcap.in
2453 pcap_open_dead.3pcap.in
2454 pcap_open_offline.3pcap.in
2455 pcap_set_immediate_mode.3pcap.in
2456 pcap_set_tstamp_precision.3pcap.in
2457 pcap_set_tstamp_type.3pcap.in
2458 )
2459 set(MAN3PCAP_NOEXPAND
2460 pcap_activate.3pcap
2461 pcap_breakloop.3pcap
2462 pcap_can_set_rfmon.3pcap
2463 pcap_close.3pcap
2464 pcap_create.3pcap
2465 pcap_datalink_name_to_val.3pcap
2466 pcap_datalink_val_to_name.3pcap
2467 pcap_dump.3pcap
2468 pcap_dump_close.3pcap
2469 pcap_dump_file.3pcap
2470 pcap_dump_flush.3pcap
2471 pcap_dump_ftell.3pcap
2472 pcap_file.3pcap
2473 pcap_fileno.3pcap
2474 pcap_findalldevs.3pcap
2475 pcap_freecode.3pcap
2476 pcap_get_required_select_timeout.3pcap
2477 pcap_get_selectable_fd.3pcap
2478 pcap_geterr.3pcap
2479 pcap_inject.3pcap
2480 pcap_is_swapped.3pcap
2481 pcap_lib_version.3pcap
2482 pcap_lookupdev.3pcap
2483 pcap_lookupnet.3pcap
2484 pcap_loop.3pcap
2485 pcap_major_version.3pcap
2486 pcap_next_ex.3pcap
2487 pcap_offline_filter.3pcap
2488 pcap_open_live.3pcap
2489 pcap_set_buffer_size.3pcap
2490 pcap_set_datalink.3pcap
2491 pcap_set_promisc.3pcap
2492 pcap_set_protocol_linux.3pcap
2493 pcap_set_rfmon.3pcap
2494 pcap_set_snaplen.3pcap
2495 pcap_set_timeout.3pcap
2496 pcap_setdirection.3pcap
2497 pcap_setfilter.3pcap
2498 pcap_setnonblock.3pcap
2499 pcap_snapshot.3pcap
2500 pcap_stats.3pcap
2501 pcap_statustostr.3pcap
2502 pcap_strerror.3pcap
2503 pcap_tstamp_type_name_to_val.3pcap
2504 pcap_tstamp_type_val_to_name.3pcap
2505 )
2506 set(MANFILE_EXPAND pcap-savefile.manfile.in)
2507 set(MANMISC_EXPAND
2508 pcap-filter.manmisc.in
2509 pcap-linktype.manmisc.in
2510 pcap-tstamp.manmisc.in
2511 )
2512
2513 if(NOT BUILD_SHARED_LIBS)
2514 unset(LIBRARY_NAME)
2515 endif(NOT BUILD_SHARED_LIBS)
2516
2517 if(WIN32)
2518 if(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8)
2519 #
2520 # Install 64-bit code built with MSVC in the amd64 subdirectories,
2521 # as that's where it expects it to be.
2522 #
2523 install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC}
2524 RUNTIME DESTINATION bin/amd64
2525 LIBRARY DESTINATION lib/amd64
2526 ARCHIVE DESTINATION lib/amd64)
2527 if(NOT MINGW)
2528 install(FILES $<TARGET_FILE_DIR:${LIBRARY_NAME_STATIC}>/${LIBRARY_NAME_STATIC}.pdb
2529 DESTINATION bin/amd64 OPTIONAL)
2530 if(BUILD_SHARED_LIBS)
2531 install(FILES $<TARGET_PDB_FILE:${LIBRARY_NAME}>
2532 DESTINATION bin/amd64 OPTIONAL)
2533 endif(BUILD_SHARED_LIBS)
2534 endif(NOT MINGW)
2535 else(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8)
2536 #
2537 # Install 32-bit code, and 64-bit code not built with MSVC
2538 # in the top-level directories, as those are where they
2539 # expect it to be.
2540 #
2541 install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC}
2542 RUNTIME DESTINATION bin
2543 LIBRARY DESTINATION lib
2544 ARCHIVE DESTINATION lib)
2545 if(NOT MINGW)
2546 install(FILES $<TARGET_FILE_DIR:${LIBRARY_NAME_STATIC}>/${LIBRARY_NAME_STATIC}.pdb
2547 DESTINATION bin OPTIONAL)
2548 if(BUILD_SHARED_LIBS)
2549 install(FILES $<TARGET_PDB_FILE:${LIBRARY_NAME}>
2550 DESTINATION bin OPTIONAL)
2551 endif(BUILD_SHARED_LIBS)
2552 endif(NOT MINGW)
2553 endif(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8)
2554 else(WIN32)
2555 install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC} DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR})
2556 endif(WIN32)
2557
2558 install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/pcap/ DESTINATION include/pcap)
2559 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pcap.h DESTINATION include)
2560 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pcap-bpf.h DESTINATION include)
2561 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pcap-namedb.h DESTINATION include)
2562
2563 # On UN*X, and on Windows when not using MSVC, generate libpcap.pc and
2564 # pcap-config and process man pages and arrange that they be installed.
2565 if(NOT MSVC)
2566 set(PACKAGE_NAME ${LIBRARY_NAME})
2567 set(prefix ${CMAKE_INSTALL_PREFIX})
2568 set(exec_prefix "\${prefix}")
2569 set(includedir "\${prefix}/include")
2570 set(libdir "\${exec_prefix}/lib")
2571 if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR
2572 CMAKE_SYSTEM_NAME STREQUAL "NetBSD" OR
2573 CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR
2574 CMAKE_SYSTEM_NAME STREQUAL "DragonFly BSD" OR
2575 CMAKE_SYSTEM_NAME STREQUAL "Linux" OR
2576 CMAKE_SYSTEM_NAME STREQUAL "OSF1")
2577 #
2578 # Platforms where the linker is the GNU linker
2579 # or accepts command-line arguments like
2580 # those the GNU linker accepts.
2581 #
2582 set(V_RPATH_OPT "-Wl,-rpath,")
2583 elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_VERSION MATCHES "5[.][0-9.]*")
2584 #
2585 # SunOS 5.x.
2586 #
2587 # XXX - this assumes GCC is using the Sun linker,
2588 # rather than the GNU linker.
2589 #
2590 set(V_RPATH_OPT "-Wl,-R,")
2591 else()
2592 #
2593 # No option needed to set the RPATH.
2594 #
2595 set(V_RPATH_OPT "")
2596 endif()
2597 set(LIBS "")
2598 foreach(LIB ${PCAP_LINK_LIBRARIES})
2599 set(LIBS "${LIBS} -l${LIB}")
2600 endforeach(LIB)
2601 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/pcap-config.in ${CMAKE_CURRENT_BINARY_DIR}/pcap-config @ONLY)
2602 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpcap.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libpcap.pc @ONLY)
2603 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/pcap-config DESTINATION bin)
2604 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpcap.pc DESTINATION lib/pkgconfig)
2605
2606 #
2607 # Man pages.
2608 #
2609 # For each section of the manual for which we have man pages
2610 # that require macro expansion, do the expansion.
2611 #
2612 set(MAN1 "")
2613 foreach(MANPAGE ${MAN1_NOEXPAND})
2614 set(MAN1 ${MAN1} ${CMAKE_CURRENT_SOURCE_DIR}/${MANPAGE})
2615 endforeach(MANPAGE)
2616 install(FILES ${MAN1} DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
2617
2618 set(MAN3PCAP "")
2619 foreach(MANPAGE ${MAN3PCAP_NOEXPAND})
2620 set(MAN3PCAP ${MAN3PCAP} ${CMAKE_CURRENT_SOURCE_DIR}/${MANPAGE})
2621 endforeach(MANPAGE)
2622 foreach(TEMPLATE_MANPAGE ${MAN3PCAP_EXPAND})
2623 string(REPLACE ".in" "" MANPAGE ${TEMPLATE_MANPAGE})
2624 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY)
2625 set(MAN3PCAP ${MAN3PCAP} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE})
2626 endforeach(TEMPLATE_MANPAGE)
2627 install(FILES ${MAN3PCAP} DESTINATION ${CMAKE_INSTALL_MANDIR}/man3)
2628 install_manpage_symlink(pcap_datalink_val_to_name.3pcap pcap_datalink_val_to_description.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2629 install_manpage_symlink(pcap_dump_open.3pcap pcap_dump_fopen.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2630 install_manpage_symlink(pcap_findalldevs.3pcap pcap_freealldevs.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2631 install_manpage_symlink(pcap_geterr.3pcap pcap_perror.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2632 install_manpage_symlink(pcap_inject.3pcap pcap_sendpacket.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2633 install_manpage_symlink(pcap_list_datalinks.3pcap pcap_free_datalinks.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2634 install_manpage_symlink(pcap_list_tstamp_types.3pcap pcap_free_tstamp_types.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2635 install_manpage_symlink(pcap_loop.3pcap pcap_dispatch.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2636 install_manpage_symlink(pcap_major_version.3pcap pcap_minor_version.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2637 install_manpage_symlink(pcap_next_ex.3pcap pcap_next.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2638 install_manpage_symlink(pcap_open_dead.3pcap pcap_open_dead_with_tstamp_precision.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2639 install_manpage_symlink(pcap_open_offline.3pcap pcap_open_offline_with_tstamp_precision.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2640 install_manpage_symlink(pcap_open_offline.3pcap pcap_fopen_offline.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2641 install_manpage_symlink(pcap_open_offline.3pcap pcap_fopen_offline_with_tstamp_precision.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2642 install_manpage_symlink(pcap_tstamp_type_val_to_name.3pcap pcap_tstamp_type_val_to_description.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2643 install_manpage_symlink(pcap_setnonblock.3pcap pcap_getnonblock.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2644
2645 set(MANFILE "")
2646 foreach(TEMPLATE_MANPAGE ${MANFILE_EXPAND})
2647 string(REPLACE ".manfile.in" ".${MAN_FILE_FORMATS}" MANPAGE ${TEMPLATE_MANPAGE})
2648 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY)
2649 set(MANFILE ${MANFILE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE})
2650 endforeach(TEMPLATE_MANPAGE)
2651 install(FILES ${MANFILE} DESTINATION ${CMAKE_INSTALL_MANDIR}/man${MAN_FILE_FORMATS})
2652
2653 set(MANMISC "")
2654 foreach(TEMPLATE_MANPAGE ${MANMISC_EXPAND})
2655 string(REPLACE ".manmisc.in" ".${MAN_MISC_INFO}" MANPAGE ${TEMPLATE_MANPAGE})
2656 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY)
2657 set(MANMISC ${MANMISC} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE})
2658 endforeach(TEMPLATE_MANPAGE)
2659 install(FILES ${MANMISC} DESTINATION ${CMAKE_INSTALL_MANDIR}/man${MAN_MISC_INFO})
2660 endif(NOT MSVC)
2661
2662 # uninstall target
2663 configure_file(
2664 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
2665 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
2666 IMMEDIATE @ONLY)
2667
2668 add_custom_target(uninstall
2669 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)