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