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