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