1335640Shselaskycmake_minimum_required(VERSION 2.8.6) 2335640Shselasky 3335640Shselasky# 4335640Shselasky# Apple doesn't build with an install_name starting with @rpath, and 5335640Shselasky# neither do we with autotools; don't do so with CMake, either, and 6335640Shselasky# suppress warnings about that. 7335640Shselasky# 8335640Shselaskyif(POLICY CMP0042) 9335640Shselasky cmake_policy(SET CMP0042 OLD) 10335640Shselaskyendif() 11335640Shselasky 12356341Scyset(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules) 13335640Shselasky 14335640Shselaskyproject(pcap) 15335640Shselasky 16335640Shselasky# 17335640Shselasky# Try to enable as many C99 features as we can. 18335640Shselasky# At minimum, we want C++/C99-style // comments. 19335640Shselasky# 20335640Shselasky# Newer versions of compilers might default to supporting C99, but older 21335640Shselasky# versions may require a special flag. 22335640Shselasky# 23335640Shselasky# Prior to CMake 3.1, setting CMAKE_C_STANDARD will not have any effect, 24335640Shselasky# so, unless and until we require CMake 3.1 or later, we have to do it 25335640Shselasky# ourselves on pre-3.1 CMake, so we just do it ourselves on all versions 26335640Shselasky# of CMake. 27335640Shselasky# 28335640Shselasky# Note: with CMake 3.1 through 3.5, the only compilers for which CMake 29335640Shselasky# handles CMAKE_C_STANDARD are GCC and Clang. 3.6 adds support only 30335640Shselasky# for Intel C; 3.9 adds support for PGI C, Sun C, and IBM XL C, and 31335640Shselasky# 3.10 adds support for Cray C and IAR C, but no version of CMake has 32335640Shselasky# support for HP C. Therefore, even if we use CMAKE_C_STANDARD with 33335640Shselasky# compilers for which CMake supports it, we may still have to do it 34335640Shselasky# ourselves on other compilers. 35335640Shselasky# 36335640Shselasky# See the CMake documentation for the CMAKE_<LANG>_COMPILER_ID variables 37335640Shselasky# for a list of compiler IDs. 38335640Shselasky# 39335640Shselasky# We don't worry about MSVC; it doesn't have such a flag - either it 40335640Shselasky# doesn't support the C99 features we need at all, or it supports them 41335640Shselasky# regardless of the compiler flag. 42335640Shselasky# 43335640Shselasky# XXX - this just tests whether the option works and adds it if it does. 44335640Shselasky# We don't test whether it's necessary in order to get the C99 features 45335640Shselasky# that we use; if we ever have a user who tries to compile with a compiler 46335640Shselasky# that can't be made to support those features, we can add a test to make 47335640Shselasky# sure we actually *have* C99 support. 48335640Shselasky# 49335640Shselaskyinclude(CheckCCompilerFlag) 50335640Shselaskymacro(check_and_add_compiler_option _option) 51335640Shselasky message(STATUS "Checking C compiler flag ${_option}") 52335640Shselasky string(REPLACE "=" "-" _temp_option_variable ${_option}) 53335640Shselasky string(REGEX REPLACE "^-" "" _option_variable ${_temp_option_variable}) 54335640Shselasky check_c_compiler_flag("${_option}" ${_option_variable}) 55335640Shselasky if(${${_option_variable}}) 56335640Shselasky set(C_ADDITIONAL_FLAGS "${C_ADDITIONAL_FLAGS} ${_option}") 57335640Shselasky endif() 58335640Shselaskyendmacro() 59335640Shselasky 60335640Shselaskyset(C_ADDITIONAL_FLAGS "") 61335640Shselaskyif(CMAKE_C_COMPILER_ID MATCHES "GNU" OR 62335640Shselasky CMAKE_C_COMPILER_ID MATCHES "Clang") 63335640Shselasky check_and_add_compiler_option("-std=gnu99") 64335640Shselaskyelseif(CMAKE_C_COMPILER_ID MATCHES "XL") 65335640Shselasky # 66335640Shselasky # We want support for extensions picked up for GNU C compatibility, 67335640Shselasky # so we use -qlanglvl=extc99. 68335640Shselasky # 69335640Shselasky check_and_add_compiler_option("-qlanglvl=extc99") 70335640Shselaskyelseif(CMAKE_C_COMPILER_ID MATCHES "HP") 71335640Shselasky check_and_add_compiler_option("-AC99") 72335640Shselaskyelseif(CMAKE_C_COMPILER_ID MATCHES "Sun") 73335640Shselasky check_and_add_compiler_option("-xc99") 74335640Shselaskyelseif(CMAKE_C_COMPILER_ID MATCHES "Intel") 75335640Shselasky check_and_add_compiler_option("-c99") 76335640Shselaskyendif() 77335640Shselasky 78335640Shselasky# 79335640Shselasky# Build all runtimes in the top-level binary directory; that way, 80335640Shselasky# on Windows, the executables will be in the same directory as 81335640Shselasky# the DLLs, so the system will find pcap.dll when any of the 82335640Shselasky# executables are run. 83335640Shselasky# 84335640Shselaskyset(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run) 85335640Shselasky 86335640Shselasky################################################################### 87335640Shselasky# Parameters 88335640Shselasky################################################################### 89335640Shselasky 90335640Shselaskyif(WIN32) 91335640Shselasky # 92335640Shselasky # On Windows, allow the library name to be overridden, for the 93335640Shselasky # benefit of projects that combine libpcap with their own 94335640Shselasky # kernel-mode code to support capturing. 95335640Shselasky # 96335640Shselasky set(LIBRARY_NAME pcap CACHE STRING "Library name") 97335640Shselaskyelse() 98335640Shselasky # 99335640Shselasky # On UN*X, it's always been libpcap. 100335640Shselasky # 101335640Shselasky set(LIBRARY_NAME pcap) 102335640Shselaskyendif() 103335640Shselasky 104335640Shselaskyoption(INET6 "Enable IPv6" ON) 105335640Shselaskyif(WIN32) 106335640Shselasky option(USE_STATIC_RT "Use static Runtime" ON) 107335640Shselaskyendif(WIN32) 108335640Shselaskyoption(BUILD_SHARED_LIBS "Build shared libraries" ON) 109335640Shselaskyif(WIN32) 110335640Shselasky set(PACKET_DLL_DIR "" CACHE PATH "Path to directory with include and lib subdirectories for packet.dll") 111335640Shselaskyendif(WIN32) 112335640Shselasky 113335640Shselasky# To pacify those who hate the protochain instruction 114335640Shselaskyoption(NO_PROTOCHAIN "Disable protochain instruction" OFF) 115335640Shselasky 116335640Shselasky# 117335640Shselasky# Start out with the capture mechanism type unspecified; the user 118335640Shselasky# can explicitly specify it and, if they don't, we'll pick an 119335640Shselasky# appropriate one. 120335640Shselasky# 121335640Shselaskyset(PCAP_TYPE "" CACHE STRING "Packet capture type") 122335640Shselasky 123335640Shselasky# 124335640Shselasky# Default to having remote capture support on Windows and, for now, to 125335640Shselasky# not having it on UN*X. 126335640Shselasky# 127335640Shselaskyif(WIN32) 128335640Shselasky option(ENABLE_REMOTE "Enable remote capture" ON) 129335640Shselaskyelse() 130335640Shselasky option(ENABLE_REMOTE "Enable remote capture" OFF) 131335640Shselaskyendif(WIN32) 132335640Shselasky 133335640Shselaskyif(CMAKE_SYSTEM_NAME STREQUAL "Linux") 134335640Shselasky option(PCAP_SUPPORT_PACKET_RING "Enable Linux packet ring support" ON) 135335640Shselasky option(BUILD_WITH_LIBNL "Build with libnl" ON) 136335640Shselaskyendif() 137335640Shselasky 138335640Shselasky# 139335640Shselasky# Additional capture modules. 140335640Shselasky# 141335640Shselaskyoption(DISABLE_USB "Disable USB sniffing support" OFF) 142335640Shselaskyoption(DISABLE_BLUETOOTH "Disable Bluetooth sniffing support" OFF) 143335640Shselaskyoption(DISABLE_NETMAP "Disable netmap support" OFF) 144335640Shselasky# 145335640Shselasky# We don't support D-Bus sniffing on macOS; see 146335640Shselasky# 147335640Shselasky# https://bugs.freedesktop.org/show_bug.cgi?id=74029 148335640Shselasky# 149335640Shselaskyif(APPLE) 150335640Shselasky option(DISABLE_DBUS "Disable D-Bus sniffing support" ON) 151335640Shselaskyelse(APPLE) 152335640Shselasky option(DISABLE_DBUS "Disable D-Bus sniffing support" OFF) 153335640Shselaskyendif(APPLE) 154335640Shselaskyoption(DISABLE_RDMA "Disable RDMA sniffing support" OFF) 155335640Shselasky 156335640Shselaskyoption(DISABLE_DAG "Disable Endace DAG card support" OFF) 157335640Shselasky 158335640Shselaskyoption(DISABLE_SEPTEL "Disable Septel card support" OFF) 159356341Scyset(SEPTEL_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../septel" CACHE PATH "Path to directory with include and lib subdirectories for Septel API") 160335640Shselasky 161335640Shselaskyoption(DISABLE_SNF "Disable Myricom SNF support" OFF) 162335640Shselasky 163335640Shselaskyoption(DISABLE_TC "Disable Riverbed TurboCap support" OFF) 164335640Shselasky 165335640Shselasky# 166335640Shselasky# Debugging options. 167335640Shselasky# 168335640Shselaskyoption(BDEBUG "Build optimizer debugging code" OFF) 169335640Shselaskyoption(YYDEBUG "Build parser debugging code" OFF) 170335640Shselasky 171335640Shselasky################################################################### 172335640Shselasky# Versioning 173335640Shselasky################################################################### 174335640Shselasky 175335640Shselasky# Get, parse, format and set pcap's version string from [pcap_root]/VERSION 176335640Shselasky# for later use. 177356341Scy 178335640Shselasky# Get MAJOR, MINOR, PATCH & SUFFIX 179335640Shselaskyfile(STRINGS ${pcap_SOURCE_DIR}/VERSION 180335640Shselasky PACKAGE_VERSION 181335640Shselasky LIMIT_COUNT 1 # Read only the first line 182335640Shselasky) 183335640Shselasky 184335640Shselasky# Get "just" MAJOR 185335640Shselaskystring(REGEX MATCH "^([0-9]+)" PACKAGE_VERSION_MAJOR "${PACKAGE_VERSION}") 186335640Shselasky 187335640Shselasky# Get MAJOR, MINOR & PATCH 188335640Shselaskystring(REGEX MATCH "^([0-9]+.)?([0-9]+.)?([0-9]+)" PACKAGE_VERSION_NOSUFFIX "${PACKAGE_VERSION}") 189335640Shselasky 190356341Scyif(WIN32) 191335640Shselasky # Convert PCAP_VERSION_NOSUFFIX to Windows preferred version format 192335640Shselasky string(REPLACE "." "," PACKAGE_VERSION_PREDLL ${PACKAGE_VERSION_NOSUFFIX}) 193335640Shselasky 194335640Shselasky # Append NANO (used for Windows internal versioning) to PCAP_VERSION_PREDLL 195335640Shselasky # 0 means unused. 196335640Shselasky set(PACKAGE_VERSION_DLL ${PACKAGE_VERSION_PREDLL},0) 197335640Shselaskyendif(WIN32) 198335640Shselasky 199335640Shselaskyset(PACKAGE_NAME "${LIBRARY_NAME}") 200335640Shselaskyset(PACKAGE_STRING "${LIBRARY_NAME} ${PACKAGE_VERSION}") 201335640Shselasky 202335640Shselasky###################################### 203335640Shselasky# Project settings 204335640Shselasky###################################### 205335640Shselasky 206335640Shselaskyadd_definitions(-DHAVE_CONFIG_H) 207335640Shselasky 208335640Shselaskyinclude_directories( 209335640Shselasky ${CMAKE_CURRENT_BINARY_DIR} 210335640Shselasky ${pcap_SOURCE_DIR} 211335640Shselasky) 212335640Shselasky 213335640Shselaskyinclude(CheckFunctionExists) 214335640Shselaskyinclude(CMakePushCheckState) 215356341Scyinclude(CheckSymbolExists) 216335640Shselasky 217335640Shselaskyif(WIN32) 218335640Shselasky 219335640Shselasky if(IS_DIRECTORY ${CMAKE_HOME_DIRECTORY}/../../Common) 220335640Shselasky include_directories(${CMAKE_HOME_DIRECTORY}/../../Common) 221335640Shselasky endif(IS_DIRECTORY ${CMAKE_HOME_DIRECTORY}/../../Common) 222335640Shselasky 223335640Shselasky find_package(Packet) 224335640Shselasky if(PACKET_FOUND) 225335640Shselasky set(HAVE_PACKET32 TRUE) 226335640Shselasky include_directories(${PACKET_INCLUDE_DIRS}) 227335640Shselasky # 228335640Shselasky # Check whether we have the NPcap PacketIsLoopbackAdapter() 229335640Shselasky # function. 230335640Shselasky # 231335640Shselasky cmake_push_check_state() 232335640Shselasky set(CMAKE_REQUIRED_LIBRARIES ${PACKET_LIBRARIES}) 233335640Shselasky check_function_exists(PacketIsLoopbackAdapter HAVE_PACKET_IS_LOOPBACK_ADAPTER) 234335640Shselasky cmake_pop_check_state() 235335640Shselasky endif(PACKET_FOUND) 236335640Shselasky 237356341Scy message(STATUS "checking for Npcap's version.h") 238356341Scy check_symbol_exists(WINPCAP_PRODUCT_NAME "../../version.h" HAVE_VERSION_H) 239356341Scy if(HAVE_VERSION_H) 240356341Scy message(STATUS "HAVE version.h") 241356341Scy else(HAVE_VERSION_H) 242356341Scy message(STATUS "MISSING version.h") 243356341Scy endif(HAVE_VERSION_H) 244356341Scy 245335640Shselaskyendif(WIN32) 246335640Shselasky 247335640Shselaskyif(MSVC) 248335640Shselasky add_definitions(-D__STDC__) 249335640Shselasky add_definitions(-D_CRT_SECURE_NO_WARNINGS) 250335640Shselaskyendif(MSVC) 251335640Shselasky 252335640Shselaskyif(USE_STATIC_RT) 253335640Shselasky message(STATUS "Use STATIC runtime") 254335640Shselasky if(MSVC) 255335640Shselasky foreach(RT_FLAG 256335640Shselasky CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE 257335640Shselasky CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO 258335640Shselasky CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE 259335640Shselasky CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) 260335640Shselasky string(REGEX REPLACE "/MD" "/MT" ${RT_FLAG} "${${RT_FLAG}}") 261335640Shselasky endforeach(RT_FLAG) 262335640Shselasky elseif(MINGW) 263335640Shselasky set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc") 264335640Shselasky endif() 265335640Shselaskyelse (USE_STATIC_RT) 266335640Shselasky message(STATUS "Use DYNAMIC runtime") 267335640Shselaskyendif(USE_STATIC_RT) 268335640Shselasky 269335640Shselasky################################################################### 270335640Shselasky# Detect available platform features 271335640Shselasky################################################################### 272335640Shselasky 273335640Shselaskyinclude(CheckIncludeFile) 274335640Shselaskyinclude(CheckIncludeFiles) 275335640Shselaskyinclude(CheckStructHasMember) 276335640Shselaskyinclude(CheckTypeSize) 277335640Shselasky 278335640Shselasky# 279356341Scy# Tests are a bit expensive with Visual Studio on Windows, so, on 280356341Scy# Windows, we skip tests for UN*X-only headers and functions. 281356341Scy# 282356341Scy 283356341Scy# 284335640Shselasky# Header files. 285335640Shselasky# 286335640Shselaskycheck_include_file(inttypes.h HAVE_INTTYPES_H) 287335640Shselaskycheck_include_file(stdint.h HAVE_STDINT_H) 288335640Shselaskycheck_include_file(unistd.h HAVE_UNISTD_H) 289335640Shselaskyif(NOT HAVE_UNISTD_H) 290335640Shselasky add_definitions(-DYY_NO_UNISTD_H) 291335640Shselaskyendif(NOT HAVE_UNISTD_H) 292335640Shselaskycheck_include_file(bitypes.h HAVE_SYS_BITYPES_H) 293335640Shselaskyif(NOT WIN32) 294335640Shselasky check_include_file(sys/ioccom.h HAVE_SYS_IOCCOM_H) 295335640Shselasky check_include_file(sys/sockio.h HAVE_SYS_SOCKIO_H) 296335640Shselasky check_include_file(sys/select.h HAVE_SYS_SELECT_H) 297335640Shselaskyendif(NOT WIN32) 298335640Shselaskycheck_include_file(limits.h HAVE_LIMITS_H) 299335640Shselaskyif(NOT WIN32) 300335640Shselasky check_include_file(netpacket/packet.h HAVE_NETPACKET_PACKET_H) 301335640Shselasky check_include_files("sys/types.h;sys/socket.h;net/if.h;net/pfvar.h" HAVE_NET_PFVAR_H) 302335640Shselasky if(HAVE_NET_PFVAR_H) 303335640Shselasky # 304335640Shselasky # Check for various PF actions. 305335640Shselasky # 306335640Shselasky check_c_source_compiles( 307335640Shselasky"#include <sys/types.h> 308335640Shselasky#include <sys/socket.h> 309335640Shselasky#include <net/if.h> 310335640Shselasky#include <net/pfvar.h> 311335640Shselasky 312335640Shselaskyint 313335640Shselaskymain(void) 314335640Shselasky{ 315335640Shselasky return PF_NAT+PF_NONAT+PF_BINAT+PF_NOBINAT+PF_RDR+PF_NORDR; 316335640Shselasky} 317335640Shselasky" 318335640Shselasky HAVE_PF_NAT_THROUGH_PF_NORDR) 319335640Shselasky endif(HAVE_NET_PFVAR_H) 320335640Shselasky check_include_file(netinet/if_ether.h HAVE_NETINET_IF_ETHER_H) 321335640Shselasky if(CMAKE_SYSTEM_NAME STREQUAL "Linux") 322335640Shselasky check_include_file(linux/sockios.h HAVE_LINUX_SOCKIOS_H) 323335640Shselasky # 324335640Shselasky # linux/if_bonding.h requires sys/socket.h. 325335640Shselasky # 326335640Shselasky check_include_files("sys/socket.h;linux/if_bonding.h" HAVE_LINUX_IF_BONDING_H) 327335640Shselasky endif() 328335640Shselaskyendif(NOT WIN32) 329335640Shselasky 330335640Shselasky# 331335640Shselasky# Functions. 332335640Shselasky# 333335640Shselaskycheck_function_exists(strerror HAVE_STRERROR) 334335640Shselaskycheck_function_exists(strerror_r HAVE_STRERROR_R) 335356341Scyif(HAVE_STRERROR_R) 336356341Scy # 337356341Scy # We have strerror_r; if we define _GNU_SOURCE, is it a 338356341Scy # POSIX-compliant strerror_r() or a GNU strerror_r()? 339356341Scy # 340356341Scy check_c_source_compiles( 341356341Scy"#define _GNU_SOURCE 342356341Scy#include <string.h> 343356341Scy 344356341Scy/* Define it GNU-style; that will cause an error if it's not GNU-style */ 345356341Scyextern char *strerror_r(int, char *, size_t); 346356341Scy 347356341Scyint 348356341Scymain(void) 349356341Scy{ 350356341Scy return 0; 351356341Scy} 352356341Scy" 353356341Scy HAVE_GNU_STRERROR_R) 354356341Scy if(NOT HAVE_GNU_STRERROR_R) 355356341Scy set(HAVE_POSIX_STRERROR_R YES) 356356341Scy endif(NOT HAVE_GNU_STRERROR_R) 357356341Scyelse(HAVE_STRERROR_R) 358356341Scy # 359356341Scy # We don't have strerror_r; do we have strerror_s? 360356341Scy # 361356341Scy check_function_exists(strerror_s HAVE_STRERROR_S) 362356341Scyendif(HAVE_STRERROR_R) 363335640Shselaskycheck_function_exists(strlcpy HAVE_STRLCPY) 364335640Shselaskycheck_function_exists(strlcat HAVE_STRLCAT) 365335640Shselaskycheck_function_exists(snprintf HAVE_SNPRINTF) 366335640Shselaskycheck_function_exists(vsnprintf HAVE_VSNPRINTF) 367356341Scycheck_function_exists(asprintf HAVE_ASPRINTF) 368356341Scycheck_function_exists(vasprintf HAVE_VASPRINTF) 369335640Shselaskycheck_function_exists(strtok_r HAVE_STRTOK_R) 370356341Scyif(NOT WIN32) 371356341Scy check_function_exists(vsyslog HAVE_VSYSLOG) 372356341Scyendif() 373335640Shselasky 374335640Shselasky# 375335640Shselasky# These tests are for network applications that need socket functions 376335640Shselasky# and getaddrinfo()/getnameinfo()-ish functions. We now require 377335640Shselasky# getaddrinfo() and getnameinfo(). On UN*X systems, we also prefer 378335640Shselasky# versions of recvmsg() that conform to the Single UNIX Specification, 379335640Shselasky# so that we can check whether a datagram received with recvmsg() was 380335640Shselasky# truncated when received due to the buffer being too small. 381335640Shselasky# 382335640Shselasky# On Windows, getaddrinfo() is in the ws2_32 library. 383335640Shselasky 384335640Shselasky# On most UN*X systems, they're available in the system library. 385335640Shselasky# 386335640Shselasky# Under Solaris, we need to link with libsocket and libnsl to get 387335640Shselasky# getaddrinfo() and getnameinfo() and, if we have libxnet, we need to 388335640Shselasky# link with libxnet before libsocket to get a version of recvmsg() 389335640Shselasky# that conforms to the Single UNIX Specification. 390335640Shselasky# 391335640Shselasky# We use getaddrinfo() because we want a portable thread-safe way 392335640Shselasky# of getting information for a host name or port; there exist _r 393335640Shselasky# versions of gethostbyname() and getservbyname() on some platforms, 394335640Shselasky# but not on all platforms. 395335640Shselasky# 396335640Shselasky# NOTE: if you hand check_library_exists as its last argument a variable 397335640Shselasky# that's been set, it skips the test, so we need different variables. 398335640Shselasky# 399335640Shselaskyset(PCAP_LINK_LIBRARIES "") 400335640Shselaskyinclude(CheckLibraryExists) 401335640Shselaskyif(WIN32) 402335640Shselasky # 403335640Shselasky # We need winsock2.h and ws2tcpip.h. 404335640Shselasky # 405335640Shselasky cmake_push_check_state() 406335640Shselasky set(CMAKE_REQUIRED_LIBRARIES ws2_32) 407335640Shselasky check_symbol_exists(getaddrinfo "winsock2.h;ws2tcpip.h" LIBWS2_32_HAS_GETADDRINFO) 408335640Shselasky cmake_pop_check_state() 409335640Shselasky if(LIBWS2_32_HAS_GETADDRINFO) 410335640Shselasky set(PCAP_LINK_LIBRARIES ws2_32 ${PCAP_LINK_LIBRARIES}) 411335640Shselasky else(LIBWS2_32_HAS_GETADDRINFO) 412335640Shselasky message(FATAL_ERROR "getaddrinfo is required, but wasn't found") 413335640Shselasky endif(LIBWS2_32_HAS_GETADDRINFO) 414335640Shselaskyelse(WIN32) 415335640Shselasky # 416335640Shselasky # UN*X. First try the system libraries, then try the libraries 417335640Shselasky # for Solaris and possibly other systems that picked up the 418335640Shselasky # System V library split. 419335640Shselasky # 420335640Shselasky check_function_exists(getaddrinfo STDLIBS_HAVE_GETADDRINFO) 421335640Shselasky if(NOT STDLIBS_HAVE_GETADDRINFO) 422335640Shselasky # 423335640Shselasky # Not found in the standard system libraries. 424335640Shselasky # Try libsocket, which requires libnsl. 425335640Shselasky # 426335640Shselasky cmake_push_check_state() 427335640Shselasky set(CMAKE_REQUIRED_LIBRARIES nsl) 428335640Shselasky check_library_exists(socket getaddrinfo "" LIBSOCKET_HAS_GETADDRINFO) 429335640Shselasky cmake_pop_check_state() 430335640Shselasky if(LIBSOCKET_HAS_GETADDRINFO) 431335640Shselasky # 432335640Shselasky # OK, we found it in libsocket. 433335640Shselasky # 434335640Shselasky set(PCAP_LINK_LIBRARIES socket nsl ${PCAP_LINK_LIBRARIES}) 435335640Shselasky else(LIBSOCKET_HAS_GETADDRINFO) 436335640Shselasky # 437335640Shselasky # We didn't find it. 438335640Shselasky # 439335640Shselasky message(FATAL_ERROR "getaddrinfo is required, but wasn't found") 440335640Shselasky endif(LIBSOCKET_HAS_GETADDRINFO) 441335640Shselasky 442335640Shselasky # 443335640Shselasky # OK, do we have recvmsg() in libxnet? 444335640Shselasky # We also link with libsocket and libnsl. 445335640Shselasky # 446335640Shselasky cmake_push_check_state() 447335640Shselasky set(CMAKE_REQUIRED_LIBRARIES socket nsl) 448335640Shselasky check_library_exists(xnet recvmsg "" LIBXNET_HAS_RECVMSG) 449335640Shselasky cmake_pop_check_state() 450335640Shselasky if(LIBXNET_HAS_RECVMSG) 451335640Shselasky # 452335640Shselasky # Yes - link with it as well. 453335640Shselasky # 454335640Shselasky set(PCAP_LINK_LIBRARIES xnet ${PCAP_LINK_LIBRARIES}) 455335640Shselasky endif(LIBXNET_HAS_RECVMSG) 456335640Shselasky endif(NOT STDLIBS_HAVE_GETADDRINFO) 457335640Shselasky 458335640Shselasky # DLPI needs putmsg under HPUX so test for -lstr while we're at it 459335640Shselasky check_function_exists(putmsg STDLIBS_HAVE_PUTMSG) 460335640Shselasky if(NOT STDLIBS_HAVE_PUTMSG) 461335640Shselasky check_library_exists(str putmsg "" LIBSTR_HAS_PUTMSG) 462335640Shselasky if(LIBSTR_HAS_PUTMSG) 463335640Shselasky set(PCAP_LINK_LIBRARIES str ${PCAP_LINK_LIBRARIES}) 464335640Shselasky endif(LIBSTR_HAS_PUTMSG) 465335640Shselasky endif(NOT STDLIBS_HAVE_PUTMSG) 466335640Shselaskyendif(WIN32) 467335640Shselasky 468335640Shselasky# 469335640Shselasky# Check for reentrant versions of getnetbyname_r(), as provided by 470335640Shselasky# Linux (glibc), Solaris/IRIX, and AIX (with three different APIs!). 471335640Shselasky# If we don't find one, we just use getnetbyname(), which uses 472335640Shselasky# thread-specific data on many platforms, but doesn't use it on 473335640Shselasky# NetBSD or OpenBSD, and may not use it on older versions of other 474335640Shselasky# platforms. 475335640Shselasky# 476335640Shselasky# Only do the check if we have a declaration of getnetbyname_r(); 477335640Shselasky# without it, we can't check which API it has. (We assume that 478335640Shselasky# if there's a declaration, it has a prototype, so that the API 479335640Shselasky# can be checked.) 480335640Shselasky# 481335640Shselaskycmake_push_check_state() 482335640Shselaskyset(CMAKE_REQUIRED_LIBRARIES ${PCAP_LINK_LIBRARIES}) 483335640Shselaskycheck_symbol_exists(getnetbyname_r netdb.h NETDB_H_DECLARES_GETNETBYNAME_R) 484335640Shselaskyif(NETDB_H_DECLARES_GETNETBYNAME_R) 485335640Shselasky check_c_source_compiles( 486335640Shselasky"#include <netdb.h> 487335640Shselasky 488335640Shselaskyint 489335640Shselaskymain(void) 490335640Shselasky{ 491335640Shselasky struct netent netent_buf; 492335640Shselasky char buf[1024]; 493335640Shselasky struct netent *resultp; 494335640Shselasky int h_errnoval; 495335640Shselasky 496335640Shselasky return getnetbyname_r((const char *)0, &netent_buf, buf, sizeof buf, &resultp, &h_errnoval); 497335640Shselasky} 498335640Shselasky" 499335640Shselasky HAVE_LINUX_GETNETBYNAME_R) 500335640Shselasky if(NOT HAVE_LINUX_GETNETBYNAME_R) 501335640Shselasky check_c_source_compiles( 502335640Shselasky"#include <netdb.h> 503335640Shselasky 504335640Shselaskyint 505335640Shselaskymain(void) 506335640Shselasky{ 507335640Shselasky struct netent netent_buf; 508335640Shselasky char buf[1024]; 509335640Shselasky 510335640Shselasky return getnetbyname_r((const char *)0, &netent_buf, buf, (int)sizeof buf) != NULL; 511335640Shselasky} 512335640Shselasky" 513335640Shselasky HAVE_SOLARIS_IRIX_GETNETBYNAME_R) 514335640Shselasky if(NOT HAVE_SOLARIS_IRIX_GETNETBYNAME_R) 515335640Shselasky check_c_source_compiles( 516335640Shselasky"#include <netdb.h> 517335640Shselasky 518335640Shselaskyint 519335640Shselaskymain(void) 520335640Shselasky{ 521335640Shselasky struct netent netent_buf; 522335640Shselasky struct netent_data net_data; 523335640Shselasky 524335640Shselasky return getnetbyname_r((const char *)0, &netent_buf, &net_data); 525335640Shselasky} 526335640Shselasky" 527335640Shselasky HAVE_AIX_GETNETBYNAME_R) 528335640Shselasky endif(NOT HAVE_SOLARIS_IRIX_GETNETBYNAME_R) 529335640Shselasky endif(NOT HAVE_LINUX_GETNETBYNAME_R) 530335640Shselaskyendif(NETDB_H_DECLARES_GETNETBYNAME_R) 531335640Shselaskycmake_pop_check_state() 532335640Shselasky 533335640Shselasky# 534335640Shselasky# Check for reentrant versions of getprotobyname_r(), as provided by 535335640Shselasky# Linux (glibc), Solaris/IRIX, and AIX (with three different APIs!). 536335640Shselasky# If we don't find one, we just use getprotobyname(), which uses 537335640Shselasky# thread-specific data on many platforms, but doesn't use it on 538335640Shselasky# NetBSD or OpenBSD, and may not use it on older versions of other 539335640Shselasky# platforms. 540335640Shselasky# 541335640Shselasky# Only do the check if we have a declaration of getprotobyname_r(); 542335640Shselasky# without it, we can't check which API it has. (We assume that 543335640Shselasky# if there's a declaration, it has a prototype, so that the API 544335640Shselasky# can be checked.) 545335640Shselasky# 546335640Shselaskycmake_push_check_state() 547335640Shselaskyset(CMAKE_REQUIRED_LIBRARIES ${PCAP_LINK_LIBRARIES}) 548335640Shselaskycheck_symbol_exists(getprotobyname_r netdb.h NETDB_H_DECLARES_GETPROTOBYNAME_R) 549335640Shselaskyif(NETDB_H_DECLARES_GETPROTOBYNAME_R) 550335640Shselasky check_c_source_compiles( 551335640Shselasky"#include <netdb.h> 552335640Shselasky 553335640Shselaskyint 554335640Shselaskymain(void) 555335640Shselasky{ 556335640Shselasky struct protoent protoent_buf; 557335640Shselasky char buf[1024]; 558335640Shselasky struct protoent *resultp; 559335640Shselasky 560335640Shselasky return getprotobyname_r((const char *)0, &protoent_buf, buf, sizeof buf, &resultp); 561335640Shselasky} 562335640Shselasky" 563335640Shselasky HAVE_LINUX_GETPROTOBYNAME_R) 564335640Shselasky if(NOT HAVE_LINUX_GETPROTOBYNAME_R) 565335640Shselasky check_c_source_compiles( 566335640Shselasky"#include <netdb.h> 567335640Shselasky 568335640Shselaskyint 569335640Shselaskymain(void) 570335640Shselasky{ 571335640Shselasky struct protoent protoent_buf; 572335640Shselasky char buf[1024]; 573335640Shselasky 574335640Shselasky return getprotobyname_r((const char *)0, &protoent_buf, buf, (int)sizeof buf) != NULL; 575335640Shselasky} 576335640Shselasky" 577335640Shselasky HAVE_SOLARIS_IRIX_GETPROTOBYNAME_R) 578335640Shselasky if(NOT HAVE_SOLARIS_IRIX_GETPROTOBYNAME_R) 579335640Shselasky check_c_source_compiles( 580335640Shselasky"#include <netdb.h> 581335640Shselasky 582335640Shselaskyint 583335640Shselaskymain(void) 584335640Shselasky{ 585335640Shselasky struct protoent protoent_buf; 586335640Shselasky struct protoent_data proto_data; 587335640Shselasky 588335640Shselasky return getprotobyname_r((const char *)0, &protoent_buf, &proto_data); 589335640Shselasky} 590335640Shselasky" 591335640Shselasky HAVE_AIX_GETPROTOBYNAME_R) 592335640Shselasky endif(NOT HAVE_SOLARIS_IRIX_GETPROTOBYNAME_R) 593335640Shselasky endif(NOT HAVE_LINUX_GETPROTOBYNAME_R) 594335640Shselaskyendif(NETDB_H_DECLARES_GETPROTOBYNAME_R) 595335640Shselaskycmake_pop_check_state() 596335640Shselasky 597335640Shselasky# 598335640Shselasky# Data types. 599335640Shselasky# 600335640Shselasky# XXX - there's no check_type() macro that's like check_type_size() 601335640Shselasky# except that it only checks for the existence of the structure type, 602335640Shselasky# so we use check_type_size() and ignore the size. 603335640Shselasky# 604335640Shselaskycmake_push_check_state() 605335640Shselaskyif(WIN32) 606335640Shselasky set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h) 607335640Shselaskyelse(WIN32) 608335640Shselasky set(CMAKE_EXTRA_INCLUDE_FILES unistd.h sys/socket.h) 609335640Shselaskyendif(WIN32) 610335640Shselaskycheck_type_size("struct sockaddr_storage" STRUCT_SOCKADDR_STORAGE) 611335640Shselaskycheck_type_size("socklen_t" SOCKLEN_T) 612335640Shselaskycmake_pop_check_state() 613335640Shselasky 614335640Shselasky# 615335640Shselasky# Structure fields. 616335640Shselasky# 617335640Shselaskyif(WIN32) 618335640Shselasky check_struct_has_member("struct sockaddr" sa_len winsock2.h HAVE_STRUCT_SOCKADDR_SA_LEN) 619335640Shselaskyelse(WIN32) 620335640Shselasky check_struct_has_member("struct sockaddr" sa_len sys/socket.h HAVE_STRUCT_SOCKADDR_SA_LEN) 621335640Shselaskyendif(WIN32) 622335640Shselasky 623335640Shselasky# 624335640Shselasky# Do we have ffs(), and is it declared in <strings.h>? 625335640Shselasky# 626335640Shselaskycheck_function_exists(ffs HAVE_FFS) 627335640Shselaskyif(HAVE_FFS) 628335640Shselasky # 629335640Shselasky # OK, we have ffs(). Is it declared in <strings.h>? 630335640Shselasky # 631335640Shselasky # This test fails if we don't have <strings.h> or if we do 632335640Shselasky # but it doesn't declare ffs(). 633335640Shselasky # 634335640Shselasky check_symbol_exists(ffs strings.h STRINGS_H_DECLARES_FFS) 635335640Shselaskyendif() 636335640Shselasky 637335640Shselasky# 638335640Shselasky# This requires the libraries that we require, as ether_hostton might be 639335640Shselasky# in one of those libraries. That means we have to do this after 640335640Shselasky# we check for those libraries. 641335640Shselasky# 642335640Shselasky# You are in a twisty little maze of UN*Xes, all different. 643335640Shselasky# Some might not have ether_hostton(). 644335640Shselasky# Some might have it and declare it in <net/ethernet.h>. 645335640Shselasky# Some might have it and declare it in <netinet/ether.h> 646335640Shselasky# Some might have it and declare it in <sys/ethernet.h>. 647335640Shselasky# Some might have it and declare it in <arpa/inet.h>. 648335640Shselasky# Some might have it and declare it in <netinet/if_ether.h>. 649335640Shselasky# Some might have it and not declare it in any header file. 650335640Shselasky# 651335640Shselasky# Before you is a C compiler. 652335640Shselasky# 653335640Shselaskycmake_push_check_state() 654335640Shselaskyset(CMAKE_REQUIRED_LIBRARIES ${PCAP_LINK_LIBRARIES}) 655335640Shselaskycheck_function_exists(ether_hostton HAVE_ETHER_HOSTTON) 656335640Shselaskyif(HAVE_ETHER_HOSTTON) 657335640Shselasky # 658335640Shselasky # OK, we have ether_hostton(). Is it declared in <net/ethernet.h>? 659335640Shselasky # 660335640Shselasky # This test fails if we don't have <net/ethernet.h> or if we do 661335640Shselasky # but it doesn't declare ether_hostton(). 662335640Shselasky # 663335640Shselasky check_symbol_exists(ether_hostton net/ethernet.h NET_ETHERNET_H_DECLARES_ETHER_HOSTTON) 664335640Shselasky if(NET_ETHERNET_H_DECLARES_ETHER_HOSTTON) 665335640Shselasky # 666335640Shselasky # Yes - we have it declared. 667335640Shselasky # 668335640Shselasky set(HAVE_DECL_ETHER_HOSTTON TRUE) 669335640Shselasky endif() 670335640Shselasky # 671335640Shselasky # Did that succeed? 672335640Shselasky # 673335640Shselasky if(NOT HAVE_DECL_ETHER_HOSTTON) 674335640Shselasky # 675335640Shselasky # No - how about <netinet/ether.h>, as on Linux? 676335640Shselasky # 677335640Shselasky # This test fails if we don't have <netinet/ether.h> 678335640Shselasky # or if we do but it doesn't declare ether_hostton(). 679335640Shselasky # 680335640Shselasky check_symbol_exists(ether_hostton netinet/ether.h NETINET_ETHER_H_DECLARES_ETHER_HOSTTON) 681335640Shselasky if(NETINET_ETHER_H_DECLARES_ETHER_HOSTTON) 682335640Shselasky # 683335640Shselasky # Yes - we have it declared. 684335640Shselasky # 685335640Shselasky set(HAVE_DECL_ETHER_HOSTTON TRUE) 686335640Shselasky endif() 687335640Shselasky endif() 688335640Shselasky # 689335640Shselasky # Did that succeed? 690335640Shselasky # 691335640Shselasky if(NOT HAVE_DECL_ETHER_HOSTTON) 692335640Shselasky # 693335640Shselasky # No - how about <sys/ethernet.h>, as on Solaris 10 and later? 694335640Shselasky # 695335640Shselasky # This test fails if we don't have <sys/ethernet.h> 696335640Shselasky # or if we do but it doesn't declare ether_hostton(). 697335640Shselasky # 698335640Shselasky check_symbol_exists(ether_hostton sys/ethernet.h SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON) 699335640Shselasky if(SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON) 700335640Shselasky # 701335640Shselasky # Yes - we have it declared. 702335640Shselasky # 703335640Shselasky set(HAVE_DECL_ETHER_HOSTTON TRUE) 704335640Shselasky endif() 705335640Shselasky endif() 706335640Shselasky # 707335640Shselasky # Did that succeed? 708335640Shselasky # 709335640Shselasky if(NOT HAVE_DECL_ETHER_HOSTTON) 710335640Shselasky # 711335640Shselasky # No, how about <arpa/inet.h>, as on AIX? 712335640Shselasky # 713335640Shselasky # This test fails if we don't have <arpa/inet.h> 714335640Shselasky # or if we do but it doesn't declare ether_hostton(). 715335640Shselasky # 716335640Shselasky check_symbol_exists(ether_hostton arpa/inet.h ARPA_INET_H_DECLARES_ETHER_HOSTTON) 717335640Shselasky if(ARPA_INET_H_DECLARES_ETHER_HOSTTON) 718335640Shselasky # 719335640Shselasky # Yes - we have it declared. 720335640Shselasky # 721335640Shselasky set(HAVE_DECL_ETHER_HOSTTON TRUE) 722335640Shselasky endif() 723335640Shselasky endif() 724335640Shselasky # 725335640Shselasky # Did that succeed? 726335640Shselasky # 727335640Shselasky if(NOT HAVE_DECL_ETHER_HOSTTON) 728335640Shselasky # 729335640Shselasky # No, how about <netinet/if_ether.h>? 730335640Shselasky # On some platforms, it requires <net/if.h> and 731335640Shselasky # <netinet/in.h>, and we always include it with 732335640Shselasky # both of them, so test it with both of them. 733335640Shselasky # 734335640Shselasky # This test fails if we don't have <netinet/if_ether.h> 735335640Shselasky # and the headers we include before it, or if we do but 736335640Shselasky # <netinet/if_ether.h> doesn't declare ether_hostton(). 737335640Shselasky # 738335640Shselasky 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) 739335640Shselasky if(NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON) 740335640Shselasky # 741335640Shselasky # Yes - we have it declared. 742335640Shselasky # 743335640Shselasky set(HAVE_DECL_ETHER_HOSTTON TRUE) 744335640Shselasky endif() 745335640Shselasky endif() 746335640Shselasky # 747335640Shselasky # After all that, is ether_hostton() declared? 748335640Shselasky # 749335640Shselasky if(NOT HAVE_DECL_ETHER_HOSTTON) 750335640Shselasky # 751335640Shselasky # No, we'll have to declare it ourselves. 752335640Shselasky # Do we have "struct ether_addr" if we include <netinet/if_ether.h>? 753335640Shselasky # 754335640Shselasky # XXX - there's no check_type() macro that's like check_type_size() 755335640Shselasky # except that it only checks for the existence of the structure type, 756335640Shselasky # so we use check_type_size() and ignore the size. 757335640Shselasky # 758335640Shselasky cmake_push_check_state() 759335640Shselasky set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h sys/socket.h net/if.h netinet/in.h netinet/if_ether.h) 760335640Shselasky check_type_size("struct ether_addr" STRUCT_ETHER_ADDR) 761335640Shselasky cmake_pop_check_state() 762335640Shselasky endif() 763335640Shselaskyendif() 764335640Shselaskycmake_pop_check_state() 765335640Shselasky 766335640Shselasky# 767335640Shselasky# Large file support on UN*X, a/k/a LFS. 768335640Shselasky# 769335640Shselaskyif(NOT WIN32) 770335640Shselasky include(FindLFS) 771335640Shselasky if(LFS_FOUND) 772335640Shselasky # 773335640Shselasky # Add the required #defines. 774335640Shselasky # 775335640Shselasky add_definitions(${LFS_DEFINITIONS}) 776335640Shselasky endif() 777335640Shselasky 778335640Shselasky # 779335640Shselasky # Check for fseeko as well. 780335640Shselasky # 781335640Shselasky include(FindFseeko) 782335640Shselasky if(FSEEKO_FOUND) 783335640Shselasky set(HAVE_FSEEKO ON) 784335640Shselasky 785335640Shselasky # 786335640Shselasky # Add the required #defines. 787335640Shselasky # 788335640Shselasky add_definitions(${FSEEKO_DEFINITIONS}) 789335640Shselasky endif() 790335640Shselaskyendif() 791335640Shselasky 792335640Shselaskyif(INET6) 793335640Shselasky message(STATUS "Support IPv6") 794335640Shselaskyendif(INET6) 795335640Shselasky 796335640Shselasky# 797335640Shselasky# Pthreads. 798335640Shselasky# We might need them, because some libraries we use might use them, 799335640Shselasky# but we don't necessarily need them. 800335640Shselasky# That's only on UN*X; on Windows, if they use threads, we assume 801335640Shselasky# they're native Windows threads. 802335640Shselasky# 803335640Shselaskyif(NOT WIN32) 804335640Shselasky set(CMAKE_THREAD_PREFER_PTHREAD ON) 805335640Shselasky find_package(Threads) 806335640Shselasky if(NOT CMAKE_USE_PTHREADS_INIT) 807335640Shselasky # 808335640Shselasky # If it's not pthreads, we won't use it; we use it for libraries 809335640Shselasky # that require it. 810335640Shselasky # 811335640Shselasky set(CMAKE_THREAD_LIBS_INIT "") 812335640Shselasky endif(NOT CMAKE_USE_PTHREADS_INIT) 813335640Shselaskyendif(NOT WIN32) 814335640Shselasky 815335640Shselasky###################################### 816335640Shselasky# Input files 817335640Shselasky###################################### 818335640Shselasky 819335640Shselaskyset(PROJECT_SOURCE_LIST_C 820335640Shselasky bpf_dump.c 821335640Shselasky bpf_filter.c 822335640Shselasky bpf_image.c 823335640Shselasky etherent.c 824335640Shselasky fmtutils.c 825335640Shselasky gencode.c 826335640Shselasky nametoaddr.c 827335640Shselasky optimize.c 828335640Shselasky pcap-common.c 829335640Shselasky pcap.c 830335640Shselasky savefile.c 831335640Shselasky sf-pcapng.c 832335640Shselasky sf-pcap.c 833335640Shselasky) 834335640Shselasky 835335640Shselaskyif(WIN32) 836356341Scy # 837356341Scy # For now, we assume we don't have snprintf() or that it's not one 838356341Scy # that behaves enough like C99's snprintf() for our purposes (i.e., 839356341Scy # it doesn't null-terminate the string if it truncates it to fit in 840356341Scy # the buffer), so we have to provide our own (a wrapper around 841356341Scy # _snprintf() that null-terminates the buffer). 842356341Scy # 843356341Scy # We also assume we don't have asprintf(), and provide an implementation 844356341Scy # that uses _vscprintf() to determine how big the string needs to be. 845356341Scy # 846356341Scy set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} 847356341Scy missing/win_snprintf.c missing/win_asprintf.c) 848335640Shselaskyelse() 849356341Scy # 850356341Scy # Either: 851356341Scy # 852356341Scy # we have snprintf() and vsnprintf(), and have asprintf() and 853356341Scy # vasprintf(); 854356341Scy # 855356341Scy # we have snprintf() and vsnprintf(), but don't have asprintf() 856356341Scy # or vasprintf(); 857356341Scy # 858356341Scy # we have neither snprintf() nor vsnprintf(), and don't have 859356341Scy # asprintf() or vasprintf(), either. 860356341Scy # 861356341Scy # We assume that if we have asprintf() we have vasprintf(), as well 862356341Scy # as snprintf() and vsnprintf(), and that if we have snprintf() we 863356341Scy # have vsnprintf(). 864356341Scy # 865356341Scy # For the first case, we don't need any replacement routines. 866356341Scy # For the second case, we need replacement asprintf()/vasprintf() 867356341Scy # routines. 868356341Scy # For the third case, we need replacement snprintf()/vsnprintf() and 869356341Scy # asprintf()/vasprintf() routines. 870356341Scy # 871335640Shselasky if(NOT HAVE_SNPRINTF) 872356341Scy # 873356341Scy # We assume we have none of them; missing/snprintf.c supplies 874356341Scy # all of them. 875356341Scy # 876335640Shselasky set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/snprintf.c) 877356341Scy elif(NOT HAVE_ASPRINTF) 878356341Scy # 879356341Scy # We assume we have snprintf()/vsnprintf() but lack 880356341Scy # asprintf()/vasprintf(); missing/asprintf.c supplies 881356341Scy # the latter (using vsnprintf()). 882356341Scy # 883356341Scy set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/asprintf.c) 884356341Scy endif() 885356341Scy if(NOT HAVE_STRLCAT) 886356341Scy set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/strlcat.c) 887356341Scy endif(NOT HAVE_STRLCAT) 888356341Scy if(NOT HAVE_STRLCPY) 889356341Scy set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/strlcpy.c) 890356341Scy endif(NOT HAVE_STRLCPY) 891335640Shselasky if(NOT HAVE_STRTOK_R) 892335640Shselasky set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/strtok_r.c) 893335640Shselasky endif(NOT HAVE_STRTOK_R) 894335640Shselaskyendif(WIN32) 895335640Shselasky 896335640Shselasky# 897335640Shselasky# Determine the main pcap-XXX.c file to use, and the libraries with 898335640Shselasky# which we need to link libpcap, if any. 899335640Shselasky# 900335640Shselaskyif(WIN32) 901335640Shselasky # 902335640Shselasky # Windows. 903335640Shselasky # 904335640Shselasky # Has the user explicitly specified a capture type? 905335640Shselasky # 906335640Shselasky if(PCAP_TYPE STREQUAL "") 907335640Shselasky # 908335640Shselasky # The user didn't explicitly specify a capture mechanism. 909335640Shselasky # Check whether we have packet.dll. 910335640Shselasky # 911335640Shselasky if(HAVE_PACKET32) 912335640Shselasky # 913335640Shselasky # We have packet.dll. 914335640Shselasky # Set the capture type to NPF. 915335640Shselasky # 916335640Shselasky set(PCAP_TYPE npf) 917335640Shselasky else() 918335640Shselasky # 919335640Shselasky # We don't have any capture type we know about, so just use 920335640Shselasky # the null capture type, and only support reading (and writing) 921335640Shselasky # capture files. 922335640Shselasky # 923335640Shselasky set(PCAP_TYPE null) 924335640Shselasky endif() 925335640Shselasky endif() 926335640Shselaskyelse() 927335640Shselasky # 928335640Shselasky # UN*X. 929335640Shselasky # 930335640Shselasky # Figure out what type of packet capture mechanism we have, and 931335640Shselasky # what libraries we'd need to link libpcap with, if any. 932335640Shselasky # 933335640Shselasky 934335640Shselasky # 935335640Shselasky # Has the user explicitly specified a capture type? 936335640Shselasky # 937335640Shselasky if(PCAP_TYPE STREQUAL "") 938335640Shselasky # 939335640Shselasky # Check for a bunch of headers for various packet capture mechanisms. 940335640Shselasky # 941335640Shselasky check_include_files("sys/types.h;net/bpf.h" HAVE_NET_BPF_H) 942335640Shselasky if(HAVE_NET_BPF_H) 943335640Shselasky # 944335640Shselasky # Does it define BIOCSETIF? 945335640Shselasky # I.e., is it a header for an LBL/BSD-style capture 946335640Shselasky # mechanism, or is it just a header for a BPF filter 947335640Shselasky # engine? Some versions of Arch Linux, for example, 948335640Shselasky # have a net/bpf.h that doesn't define BIOCSETIF; 949335640Shselasky # as it's a Linux, it should use packet sockets, 950335640Shselasky # instead. 951335640Shselasky # 952335640Shselasky # We need: 953335640Shselasky # 954335640Shselasky # sys/types.h, because FreeBSD 10's net/bpf.h 955335640Shselasky # requires that various BSD-style integer types 956335640Shselasky # be defined; 957335640Shselasky # 958356341Scy # sys/time.h, because AIX 5.2 and 5.3's net/bpf.h 959356341Scy # doesn't include it but does use struct timeval 960356341Scy # in ioctl definitions; 961356341Scy # 962335640Shselasky # sys/ioctl.h and, if we have it, sys/ioccom.h, 963335640Shselasky # because net/bpf.h defines ioctls; 964335640Shselasky # 965335640Shselasky # net/if.h, because it defines some structures 966335640Shselasky # used in ioctls defined by net/bpf.h; 967335640Shselasky # 968335640Shselasky # sys/socket.h, because OpenBSD 5.9's net/bpf.h 969335640Shselasky # defines some structure fields as being 970335640Shselasky # struct sockaddrs; 971335640Shselasky # 972335640Shselasky # and net/bpf.h doesn't necessarily include all 973335640Shselasky # of those headers itself. 974335640Shselasky # 975335640Shselasky if(HAVE_SYS_IOCCOM_H) 976356341Scy 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) 977335640Shselasky else(HAVE_SYS_IOCCOM_H) 978356341Scy 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) 979335640Shselasky endif(HAVE_SYS_IOCCOM_H) 980335640Shselasky endif(HAVE_NET_BPF_H) 981335640Shselasky check_include_file(net/pfilt.h HAVE_NET_PFILT_H) 982335640Shselasky check_include_file(net/enet.h HAVE_NET_ENET_H) 983335640Shselasky check_include_file(net/nit.h HAVE_NET_NIT_H) 984335640Shselasky check_include_file(sys/net/nit.h HAVE_SYS_NET_NIT_H) 985335640Shselasky check_include_file(linux/socket.h HAVE_LINUX_SOCKET_H) 986335640Shselasky check_include_file(net/raw.h HAVE_NET_RAW_H) 987335640Shselasky check_include_file(sys/dlpi.h HAVE_SYS_DLPI_H) 988335640Shselasky 989335640Shselasky if(BPF_H_DEFINES_BIOCSETIF) 990335640Shselasky # 991335640Shselasky # BPF. 992335640Shselasky # Check this before DLPI, so that we pick BPF on 993335640Shselasky # Solaris 11 and later. 994335640Shselasky # 995335640Shselasky set(PCAP_TYPE bpf) 996335640Shselasky elseif(HAVE_LINUX_SOCKET_H) 997335640Shselasky # 998335640Shselasky # No prizes for guessing this one. 999335640Shselasky # 1000335640Shselasky set(PCAP_TYPE linux) 1001335640Shselasky elseif(HAVE_NET_PFILT_H) 1002335640Shselasky # 1003335640Shselasky # DEC OSF/1, Digital UNIX, Tru64 UNIX 1004335640Shselasky # 1005335640Shselasky set(PCAP_TYPE pf) 1006335640Shselasky elseif(HAVE_NET_ENET_H) 1007335640Shselasky # 1008335640Shselasky # Stanford Enetfilter. 1009335640Shselasky # 1010335640Shselasky set(PCAP_TYPE enet) 1011335640Shselasky elseif(HAVE_NET_NIT_H) 1012335640Shselasky # 1013335640Shselasky # SunOS 4.x STREAMS NIT. 1014335640Shselasky # 1015335640Shselasky set(PCAP_TYPE snit) 1016335640Shselasky elseif(HAVE_SYS_NET_NIT_H) 1017335640Shselasky # 1018335640Shselasky # Pre-SunOS 4.x non-STREAMS NIT. 1019335640Shselasky # 1020335640Shselasky set(PCAP_TYPE nit) 1021335640Shselasky elseif(HAVE_NET_RAW_H) 1022335640Shselasky # 1023335640Shselasky # IRIX snoop. 1024335640Shselasky # 1025335640Shselasky set(PCAP_TYPE snoop) 1026335640Shselasky elseif(HAVE_SYS_DLPI_H) 1027335640Shselasky # 1028335640Shselasky # DLPI on pre-Solaris 11 SunOS 5, HP-UX, possibly others. 1029335640Shselasky # 1030335640Shselasky set(PCAP_TYPE dlpi) 1031335640Shselasky else() 1032335640Shselasky # 1033335640Shselasky # Nothing we support. 1034335640Shselasky # 1035335640Shselasky set(PCAP_TYPE null) 1036335640Shselasky endif() 1037335640Shselasky endif() 1038335640Shselaskyendif(WIN32) 1039335640Shselaskymessage(STATUS "Packet capture mechanism type: ${PCAP_TYPE}") 1040335640Shselasky 1041335640Shselasky# 1042335640Shselasky# Do capture-mechanism-dependent tests. 1043335640Shselasky# 1044335640Shselaskyif(WIN32) 1045335640Shselasky if(PCAP_TYPE STREQUAL "npf") 1046335640Shselasky # 1047335640Shselasky # Link with packet.dll before WinSock2. 1048335640Shselasky # 1049335640Shselasky set(PCAP_LINK_LIBRARIES ${PACKET_LIBRARIES} ${PCAP_LINK_LIBRARIES}) 1050335640Shselasky elseif(PCAP_TYPE STREQUAL "null") 1051335640Shselasky else() 1052335640Shselasky message(ERROR "${PCAP_TYPE} is not a valid pcap type") 1053335640Shselasky endif() 1054335640Shselaskyelse(WIN32) 1055335640Shselasky if(PCAP_TYPE STREQUAL "dlpi") 1056335640Shselasky # 1057335640Shselasky # Needed for common functions used by pcap-[dlpi,libdlpi].c 1058335640Shselasky # 1059335640Shselasky set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} dlpisubs.c) 1060335640Shselasky 1061335640Shselasky # 1062335640Shselasky # Checks for some header files. 1063335640Shselasky # 1064335640Shselasky check_include_file(sys/bufmod.h HAVE_SYS_BUFMOD_H) 1065335640Shselasky check_include_file(sys/dlpi_ext.h HAVE_SYS_DLPI_EXT_H) 1066335640Shselasky 1067335640Shselasky # 1068335640Shselasky # Checks to see if Solaris has the public libdlpi(3LIB) library. 1069335640Shselasky # Note: The existence of /usr/include/libdlpi.h does not mean it is the 1070335640Shselasky # public libdlpi(3LIB) version. Before libdlpi was made public, a 1071335640Shselasky # private version also existed, which did not have the same APIs. 1072335640Shselasky # Due to a gcc bug, the default search path for 32-bit libraries does 1073335640Shselasky # not include /lib, we add it explicitly here. 1074335640Shselasky # [http://bugs.opensolaris.org/view_bug.do?bug_id=6619485]. 1075335640Shselasky # Also, due to the bug above applications that link to libpcap with 1076335640Shselasky # libdlpi will have to add "-L/lib" option to "configure". 1077335640Shselasky # 1078335640Shselasky cmake_push_check_state() 1079335640Shselasky set(CMAKE_REQUIRED_FLAGS "-L/lib") 1080335640Shselasky set(CMAKE_REQUIRED_LIBRARIES dlpi) 1081335640Shselasky check_function_exists(dlpi_walk HAVE_LIBDLPI) 1082335640Shselasky cmake_pop_check_state() 1083335640Shselasky if(HAVE_LIBDLPI) 1084335640Shselasky # 1085335640Shselasky # XXX - add -L/lib 1086335640Shselasky # 1087335640Shselasky set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} dlpi) 1088335640Shselasky set(PCAP_TYPE libdlpi) 1089335640Shselasky endif() 1090335640Shselasky 1091335640Shselasky # 1092335640Shselasky # This check is for Solaris with DLPI support for passive modes. 1093335640Shselasky # See dlpi(7P) for more details. 1094335640Shselasky # 1095335640Shselasky # XXX - there's no check_type() macro that's like check_type_size() 1096335640Shselasky # except that it only checks for the existence of the structure type, 1097335640Shselasky # so we use check_type_size() and ignore the size. 1098335640Shselasky # 1099335640Shselasky cmake_push_check_state() 1100335640Shselasky set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h sys/dlpi.h) 1101335640Shselasky check_type_size(dl_passive_req_t DL_PASSIVE_REQ_T) 1102335640Shselasky cmake_pop_check_state() 1103335640Shselasky elseif(PCAP_TYPE STREQUAL "linux") 1104335640Shselasky # 1105335640Shselasky # Do we have the wireless extensions? 1106335640Shselasky # linux/wireless.h requires sys/socket.h. 1107335640Shselasky # 1108335640Shselasky check_include_files("sys/socket.h;linux/wireless.h" HAVE_LINUX_WIRELESS_H) 1109335640Shselasky 1110335640Shselasky # 1111335640Shselasky # Do we have libnl? 1112335640Shselasky # 1113335640Shselasky if(BUILD_WITH_LIBNL) 1114335640Shselasky # 1115335640Shselasky # Try libnl 3.x first. 1116335640Shselasky # 1117335640Shselasky cmake_push_check_state() 1118335640Shselasky set(CMAKE_REQUIRED_LIBRARIES nl-3) 1119335640Shselasky check_function_exists(nl_socket_alloc HAVE_LIBNL) 1120335640Shselasky cmake_pop_check_state() 1121335640Shselasky if(HAVE_LIBNL) 1122335640Shselasky # 1123335640Shselasky # Yes, we have libnl 3.x. 1124335640Shselasky # 1125335640Shselasky set(PCAP_LINK_LIBRARIES nl-genl-3 nl-3 ${PCAP_LINK_LIBRARIES}) 1126335640Shselasky set(HAVE_LIBNL_3_x ON) 1127335640Shselasky set(HAVE_LIBNL_NLE ON) 1128335640Shselasky set(HAVE_LIBNL_SOCKETS ON) 1129335640Shselasky include_directories("/usr/include/libnl3") 1130335640Shselasky else() 1131335640Shselasky # 1132335640Shselasky # Try libnl 2.x. 1133335640Shselasky # 1134335640Shselasky cmake_push_check_state() 1135335640Shselasky set(CMAKE_REQUIRED_LIBRARIES nl) 1136335640Shselasky check_function_exists(nl_socket_alloc HAVE_LIBNL) 1137335640Shselasky cmake_pop_check_state() 1138335640Shselasky if(HAVE_LIBNL) 1139335640Shselasky # 1140335640Shselasky # Yes, we have libnl 2.x. 1141335640Shselasky # 1142335640Shselasky set(PCAP_LINK_LIBRARIES nl-genl nl ${PCAP_LINK_LIBRARIES}) 1143335640Shselasky set(HAVE_LIBNL_2_x ON) 1144335640Shselasky set(HAVE_LIBNL_NLE ON) 1145335640Shselasky set(HAVE_LIBNL_SOCKETS ON) 1146335640Shselasky else() 1147335640Shselasky # 1148335640Shselasky # No, we don't; do we have libnl 1.x? 1149335640Shselasky # 1150335640Shselasky cmake_push_check_state() 1151335640Shselasky set(CMAKE_REQUIRED_LIBRARIES nl) 1152335640Shselasky check_function_exists(nl_handle_alloc HAVE_LIBNL) 1153335640Shselasky cmake_pop_check_state() 1154335640Shselasky if(HAVE_LIBNL) 1155335640Shselasky set(PCAP_LINK_LIBRARIES nl ${PCAP_LINK_LIBRARIES}) 1156335640Shselasky endif() 1157335640Shselasky endif() 1158335640Shselasky endif() 1159335640Shselasky endif() 1160335640Shselasky 1161335640Shselasky check_include_file(linux/ethtool.h HAVE_LINUX_ETHTOOL_H) 1162335640Shselasky 1163335640Shselasky # 1164335640Shselasky # Checks to see if tpacket_stats is defined in linux/if_packet.h 1165335640Shselasky # If so then pcap-linux.c can use this to report proper statistics. 1166335640Shselasky # 1167335640Shselasky # XXX - there's no check_type() macro that's like check_type_size() 1168335640Shselasky # except that it only checks for the existence of the structure type, 1169335640Shselasky # so we use check_type_size() and ignore the size. 1170335640Shselasky # 1171335640Shselasky cmake_push_check_state() 1172335640Shselasky set(CMAKE_EXTRA_INCLUDE_FILES linux/if_packet.h) 1173335640Shselasky check_type_size("struct tpacket_stats" STRUCT_TPACKET_STATS) 1174335640Shselasky cmake_pop_check_state() 1175335640Shselasky 1176335640Shselasky check_struct_has_member("struct tpacket_auxdata" tp_vlan_tci linux/if_packet.h HAVE_STRUCT_TPACKET_AUXDATA_TP_VLAN_TCI) 1177335640Shselasky elseif(PCAP_TYPE STREQUAL "bpf") 1178335640Shselasky # 1179335640Shselasky # Check whether we have the *BSD-style ioctls. 1180335640Shselasky # 1181335640Shselasky check_include_files("sys/types.h;net/if_media.h" HAVE_NET_IF_MEDIA_H) 1182335640Shselasky 1183335640Shselasky # 1184335640Shselasky # Check whether we have struct BPF_TIMEVAL. 1185335640Shselasky # 1186335640Shselasky # XXX - there's no check_type() macro that's like check_type_size() 1187335640Shselasky # except that it only checks for the existence of the structure type, 1188335640Shselasky # so we use check_type_size() and ignore the size. 1189335640Shselasky # 1190335640Shselasky cmake_push_check_state() 1191335640Shselasky if(HAVE_SYS_IOCCOM_H) 1192335640Shselasky set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h sys/ioccom.h net/bpf.h) 1193335640Shselasky check_type_size("struct BPF_TIMEVAL" STRUCT_BPF_TIMEVAL) 1194335640Shselasky else() 1195335640Shselasky set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h net/bpf.h) 1196335640Shselasky check_type_size("struct BPF_TIMEVAL" STRUCT_BPF_TIMEVAL) 1197335640Shselasky endif() 1198335640Shselasky cmake_pop_check_state() 1199335640Shselasky elseif(PCAP_TYPE STREQUAL "null") 1200335640Shselasky else() 1201335640Shselasky message(FATAL_ERROR "${PCAP_TYPE} is not a valid pcap type") 1202335640Shselasky endif() 1203335640Shselaskyendif(WIN32) 1204335640Shselasky 1205335640Shselaskyset(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-${PCAP_TYPE}.c) 1206335640Shselasky 1207335640Shselasky# 1208335640Shselasky# Now figure out how we get a list of interfaces and addresses, 1209335640Shselasky# if we support capturing. Don't bother if we don't support 1210335640Shselasky# capturing. 1211335640Shselasky# 1212335640Shselaskyif(NOT WIN32) 1213335640Shselasky # 1214335640Shselasky # UN*X - figure out what type of interface list mechanism we 1215335640Shselasky # have. 1216335640Shselasky # 1217335640Shselasky # If the capture type is null, that means we can't capture, 1218335640Shselasky # so we can't open any capture devices, so we won't return 1219335640Shselasky # any interfaces. 1220335640Shselasky # 1221335640Shselasky if(NOT PCAP_TYPE STREQUAL "null") 1222335640Shselasky cmake_push_check_state() 1223335640Shselasky set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LINK_LIBRARIES}) 1224335640Shselasky check_function_exists(getifaddrs HAVE_GETIFADDRS) 1225335640Shselasky cmake_pop_check_state() 1226335640Shselasky if(NOT HAVE_GETIFADDRS) 1227335640Shselasky # 1228335640Shselasky # It's not in the libraries that, at this point, we've 1229335640Shselasky # found we need to link libpcap with. 1230335640Shselasky # 1231335640Shselasky # It's in libsocket on Solaris and possibly other OSes; 1232335640Shselasky # as long as we're not linking with libxnet, check there. 1233335640Shselasky # 1234335640Shselasky # NOTE: if you hand check_library_exists as its last 1235335640Shselasky # argument a variable that's been set, it skips the test, 1236335640Shselasky # so we need different variables. 1237335640Shselasky # 1238335640Shselasky if(NOT LIBXNET_HAS_GETHOSTBYNAME) 1239335640Shselasky check_library_exists(socket getifaddrs "" SOCKET_HAS_GETIFADDRS) 1240335640Shselasky if(SOCKET_HAS_GETIFADDRS) 1241335640Shselasky set(PCAP_LINK_LIBRARIES socket ${PCAP_LINK_LIBRARIES}) 1242335640Shselasky set(HAVE_GETIFADDRS TRUE) 1243335640Shselasky endif() 1244335640Shselasky endif() 1245335640Shselasky endif() 1246335640Shselasky if(HAVE_GETIFADDRS) 1247335640Shselasky # 1248335640Shselasky # We have "getifaddrs()"; make sure we have <ifaddrs.h> 1249335640Shselasky # as well, just in case some platform is really weird. 1250335640Shselasky # It may require that sys/types.h be included first, 1251335640Shselasky # so include it first. 1252335640Shselasky # 1253335640Shselasky check_include_files("sys/types.h;ifaddrs.h" HAVE_IFADDRS_H) 1254335640Shselasky if(HAVE_IFADDRS_H) 1255335640Shselasky # 1256335640Shselasky # We have the header, so we use "getifaddrs()" to 1257335640Shselasky # get the list of interfaces. 1258335640Shselasky # 1259335640Shselasky set(FINDALLDEVS_TYPE getad) 1260335640Shselasky else() 1261335640Shselasky # 1262335640Shselasky # We don't have the header - give up. 1263335640Shselasky # XXX - we could also fall back on some other 1264335640Shselasky # mechanism, but, for now, this'll catch this 1265335640Shselasky # problem so that we can at least try to figure 1266335640Shselasky # out something to do on systems with "getifaddrs()" 1267335640Shselasky # but without "ifaddrs.h", if there is something 1268335640Shselasky # we can do on those systems. 1269335640Shselasky # 1270335640Shselasky message(FATAL_ERROR "Your system has getifaddrs() but doesn't have a usable <ifaddrs.h>.") 1271335640Shselasky endif() 1272335640Shselasky else() 1273335640Shselasky # 1274335640Shselasky # Well, we don't have "getifaddrs()", at least not with the 1275335640Shselasky # libraries with which we've decided we need to link 1276335640Shselasky # libpcap with, so we have to use some other mechanism. 1277335640Shselasky # 1278335640Shselasky # Note that this may happen on Solaris, which has 1279335640Shselasky # getifaddrs(), but in -lsocket, not in -lxnet, so we 1280335640Shselasky # won't find it if we link with -lxnet, which we want 1281335640Shselasky # to do for other reasons. 1282335640Shselasky # 1283335640Shselasky # For now, we use either the SIOCGIFCONF ioctl or the 1284335640Shselasky # SIOCGLIFCONF ioctl, preferring the latter if we have 1285335640Shselasky # it; the latter is a Solarisism that first appeared 1286335640Shselasky # in Solaris 8. (Solaris's getifaddrs() appears to 1287335640Shselasky # be built atop SIOCGLIFCONF; using it directly 1288335640Shselasky # avoids a not-all-that-useful middleman.) 1289335640Shselasky # 1290335640Shselasky try_compile(HAVE_SIOCGLIFCONF ${CMAKE_CURRENT_BINARY_DIR} "${pcap_SOURCE_DIR}/cmake/have_siocglifconf.c" ) 1291335640Shselasky if(HAVE_SIOCGLIFCONF) 1292335640Shselasky set(FINDALLDEVS_TYPE glifc) 1293335640Shselasky else() 1294335640Shselasky set(FINDALLDEVS_TYPE gifc) 1295335640Shselasky endif() 1296335640Shselasky endif() 1297335640Shselasky message(STATUS "Find-interfaces mechanism type: ${FINDALLDEVS_TYPE}") 1298335640Shselasky set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} fad-${FINDALLDEVS_TYPE}.c) 1299335640Shselasky endif() 1300335640Shselaskyendif() 1301335640Shselasky 1302335640Shselasky# Check for hardware timestamp support. 1303335640Shselaskyif(CMAKE_SYSTEM_NAME STREQUAL "Linux") 1304335640Shselasky check_include_file(linux/net_tstamp.h HAVE_LINUX_NET_TSTAMP_H) 1305335640Shselaskyendif() 1306335640Shselasky 1307335640Shselasky# 1308335640Shselasky# Check for additional native sniffing capabilities. 1309335640Shselasky# 1310335640Shselasky 1311335640Shselasky# Check for USB sniffing support on Linux. 1312335640Shselasky# On FreeBSD, it uses BPF, so we don't need to do anything special here. 1313335640Shselaskyif(NOT DISABLE_USB) 1314335640Shselasky if(CMAKE_SYSTEM_NAME STREQUAL "Linux") 1315335640Shselasky set(PCAP_SUPPORT_USB TRUE) 1316335640Shselasky set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-usb-linux.c) 1317335640Shselasky set(LINUX_USB_MON_DEV /dev/usbmon) 1318335640Shselasky # 1319335640Shselasky # Do we have a version of <linux/compiler.h> available? 1320335640Shselasky # If so, we might need it for <linux/usbdevice_fs.h>. 1321335640Shselasky # 1322335640Shselasky check_include_files("linux/compiler.h" HAVE_LINUX_COMPILER_H) 1323335640Shselasky if(HAVE_LINUX_COMPILER_H) 1324335640Shselasky # 1325335640Shselasky # Yes - include it when testing for <linux/usbdevice_fs.h>. 1326335640Shselasky # 1327335640Shselasky check_include_files("linux/compiler.h;linux/usbdevice_fs.h" HAVE_LINUX_USBDEVICE_FS_H) 1328335640Shselasky else(HAVE_LINUX_COMPILER_H) 1329335640Shselasky check_include_files("linux/usbdevice_fs.h" HAVE_LINUX_USBDEVICE_FS_H) 1330335640Shselasky endif(HAVE_LINUX_COMPILER_H) 1331335640Shselasky if(HAVE_LINUX_USBDEVICE_FS_H) 1332335640Shselasky # 1333335640Shselasky # OK, does it define bRequestType? Older versions of the kernel 1334335640Shselasky # define fields with names like "requesttype, "request", and 1335335640Shselasky # "value", rather than "bRequestType", "bRequest", and 1336335640Shselasky # "wValue". 1337335640Shselasky # 1338335640Shselasky if(HAVE_LINUX_COMPILER_H) 1339335640Shselasky check_struct_has_member("struct usbdevfs_ctrltransfer" bRequestType "linux/compiler.h;linux/usbdevice_fs.h" HAVE_STRUCT_USBDEVFS_CTRLTRANSFER_BREQUESTTYPE) 1340335640Shselasky else(HAVE_LINUX_COMPILER_H) 1341335640Shselasky check_struct_has_member("struct usbdevfs_ctrltransfer" bRequestType "linux/usbdevice_fs.h" HAVE_STRUCT_USBDEVFS_CTRLTRANSFER_BREQUESTTYPE) 1342335640Shselasky endif(HAVE_LINUX_COMPILER_H) 1343335640Shselasky endif() 1344335640Shselasky endif() 1345335640Shselaskyendif() 1346335640Shselasky 1347335640Shselasky# Check for netfilter sniffing support. 1348335640Shselaskyif(CMAKE_SYSTEM_NAME STREQUAL "Linux") 1349335640Shselasky # 1350335640Shselasky # Life's too short to deal with trying to get this to compile 1351335640Shselasky # if you don't get the right types defined with 1352335640Shselasky # __KERNEL_STRICT_NAMES getting defined by some other include. 1353335640Shselasky # 1354335640Shselasky # Check whether the includes Just Work. If not, don't turn on 1355335640Shselasky # netfilter support. 1356335640Shselasky # 1357335640Shselasky check_c_source_compiles( 1358335640Shselasky"#include <sys/socket.h> 1359335640Shselasky#include <netinet/in.h> 1360335640Shselasky#include <linux/types.h> 1361335640Shselasky 1362335640Shselasky#include <linux/netlink.h> 1363335640Shselasky#include <linux/netfilter.h> 1364335640Shselasky#include <linux/netfilter/nfnetlink.h> 1365335640Shselasky#include <linux/netfilter/nfnetlink_log.h> 1366335640Shselasky#include <linux/netfilter/nfnetlink_queue.h> 1367335640Shselasky 1368335640Shselaskyint 1369335640Shselaskymain(void) 1370335640Shselasky{ 1371335640Shselasky return 0; 1372335640Shselasky} 1373335640Shselasky" 1374335640Shselasky PCAP_SUPPORT_NETFILTER) 1375335640Shselasky if(PCAP_SUPPORT_NETFILTER) 1376335640Shselasky set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-netfilter-linux.c) 1377335640Shselasky endif(PCAP_SUPPORT_NETFILTER) 1378335640Shselaskyendif() 1379335640Shselasky 1380335640Shselasky# Check for netmap sniffing support. 1381335640Shselaskyif(NOT DISABLE_NETMAP) 1382335640Shselasky # 1383335640Shselasky # Check whether net/netmap_user.h is usable if NETMAP_WITH_LIBS is 1384335640Shselasky # defined; it's not usable on DragonFly BSD 4.6 if NETMAP_WITH_LIBS 1385335640Shselasky # is defined, for example, as it includes a non-existent malloc.h 1386335640Shselasky # header. 1387335640Shselasky # 1388335640Shselasky check_c_source_compiles( 1389335640Shselasky"#define NETMAP_WITH_LIBS 1390335640Shselasky#include <net/netmap_user.h> 1391335640Shselasky 1392335640Shselaskyint 1393335640Shselaskymain(void) 1394335640Shselasky{ 1395335640Shselasky return 0; 1396335640Shselasky} 1397335640Shselasky" 1398335640Shselasky PCAP_SUPPORT_NETMAP) 1399335640Shselasky if(PCAP_SUPPORT_NETMAP) 1400335640Shselasky set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-netmap.c) 1401335640Shselasky endif(PCAP_SUPPORT_NETMAP) 1402335640Shselaskyendif() 1403335640Shselasky 1404335640Shselasky# Check for Bluetooth sniffing support 1405335640Shselaskyif(NOT DISABLE_BLUETOOTH) 1406335640Shselasky if(CMAKE_SYSTEM_NAME STREQUAL "Linux") 1407335640Shselasky check_include_file(bluetooth/bluetooth.h HAVE_BLUETOOTH_BLUETOOTH_H) 1408335640Shselasky if(HAVE_BLUETOOTH_BLUETOOTH_H) 1409335640Shselasky set(PCAP_SUPPORT_BT TRUE) 1410335640Shselasky set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-bt-linux.c) 1411335640Shselasky # 1412335640Shselasky # OK, does struct sockaddr_hci have an hci_channel 1413335640Shselasky # member? 1414335640Shselasky # 1415335640Shselasky check_struct_has_member("struct sockaddr_hci" hci_channel "bluetooth/bluetooth.h;bluetooth/hci.h" HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL) 1416335640Shselasky if(HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL) 1417335640Shselasky # 1418335640Shselasky # OK, is HCI_CHANNEL_MONITOR defined? 1419335640Shselasky # 1420335640Shselasky check_c_source_compiles( 1421335640Shselasky"#include <bluetooth/bluetooth.h> 1422335640Shselasky#include <bluetooth/hci.h> 1423335640Shselasky 1424335640Shselaskyint 1425335640Shselaskymain(void) 1426335640Shselasky{ 1427335640Shselasky u_int i = HCI_CHANNEL_MONITOR; 1428335640Shselasky return 0; 1429335640Shselasky} 1430335640Shselasky" 1431335640Shselasky PCAP_SUPPORT_BT_MONITOR) 1432335640Shselasky if(PCAP_SUPPORT_BT_MONITOR) 1433335640Shselasky # 1434335640Shselasky # Yes, so we can also support Bluetooth monitor 1435335640Shselasky # sniffing. 1436335640Shselasky # 1437335640Shselasky set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-bt-monitor-linux.c) 1438335640Shselasky endif(PCAP_SUPPORT_BT_MONITOR) 1439335640Shselasky endif(HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL) 1440335640Shselasky endif(HAVE_BLUETOOTH_BLUETOOTH_H) 1441335640Shselasky endif() 1442335640Shselaskyendif() 1443335640Shselasky 1444335640Shselasky# Check for Bluetooth sniffing support 1445335640Shselaskyif(NOT DISABLE_DBUS) 1446335640Shselasky # 1447335640Shselasky # We don't support D-Bus sniffing on macOS; see 1448335640Shselasky # 1449335640Shselasky # https://bugs.freedesktop.org/show_bug.cgi?id=74029 1450335640Shselasky # 1451335640Shselasky if(APPLE) 1452335640Shselasky message(FATAL_ERROR "Due to freedesktop.org bug 74029, D-Bus capture support is not available on macOS") 1453335640Shselasky endif(APPLE) 1454335640Shselasky include(FindPkgConfig) 1455335640Shselasky pkg_check_modules(DBUS dbus-1) 1456335640Shselasky if(DBUS_FOUND) 1457335640Shselasky set(PCAP_SUPPORT_DBUS TRUE) 1458335640Shselasky set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-dbus.c) 1459335640Shselasky include_directories(${DBUS_INCLUDE_DIRS}) 1460356341Scy 1461356341Scy # 1462356341Scy # This "helpfully" supplies DBUS_LIBRARIES as a bunch of 1463356341Scy # library names - not paths - and DBUS_LIBRARY_DIRS as 1464356341Scy # a bunch of directories. 1465356341Scy # 1466356341Scy # CMake *really* doesn't like the notion of specifying "here are 1467356341Scy # the directories in which to look for libraries" except in 1468356341Scy # find_library() calls; it *really* prefers using full paths to 1469356341Scy # library files, rather than library names. 1470356341Scy # 1471356341Scy # Find the libraries and add their full paths. 1472356341Scy # 1473356341Scy set(DBUS_LIBRARY_FULLPATHS) 1474356341Scy foreach(_lib IN LISTS DBUS_LIBRARIES) 1475356341Scy # 1476356341Scy # Try to find this library, so we get its full path. 1477356341Scy # 1478356341Scy find_library(_libfullpath ${_lib} HINTS ${DBUS_LIBRARY_DIRS}) 1479356341Scy list(APPEND DBUS_LIBRARY_FULLPATHS ${_libfullpath}) 1480356341Scy endforeach() 1481356341Scy set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${DBUS_LIBRARY_FULLPATHS}) 1482335640Shselasky endif(DBUS_FOUND) 1483335640Shselaskyendif(NOT DISABLE_DBUS) 1484335640Shselasky 1485335640Shselasky# Check for RDMA sniffing support 1486335640Shselaskyif(NOT DISABLE_RDMA) 1487335640Shselasky check_library_exists(ibverbs ibv_get_device_list "" LIBIBVERBS_HAS_IBV_GET_DEVICE_LIST) 1488335640Shselasky if(LIBIBVERBS_HAS_IBV_GET_DEVICE_LIST) 1489335640Shselasky check_include_file(infiniband/verbs.h HAVE_INFINIBAND_VERBS_H) 1490335640Shselasky if(HAVE_INFINIBAND_VERBS_H) 1491335640Shselasky check_symbol_exists(ibv_create_flow infiniband/verbs.h PCAP_SUPPORT_RDMASNIFF) 1492335640Shselasky if(PCAP_SUPPORT_RDMASNIFF) 1493335640Shselasky set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-rdmasniff.c) 1494335640Shselasky set(PCAP_LINK_LIBRARIES ibverbs ${PCAP_LINK_LIBRARIES}) 1495335640Shselasky endif(PCAP_SUPPORT_RDMASNIFF) 1496335640Shselasky endif(HAVE_INFINIBAND_VERBS_H) 1497335640Shselasky endif(LIBIBVERBS_HAS_IBV_GET_DEVICE_LIST) 1498335640Shselaskyendif(NOT DISABLE_RDMA) 1499335640Shselasky 1500335640Shselasky# 1501335640Shselasky# Check for sniffing capabilities using third-party APIs. 1502335640Shselasky# 1503335640Shselasky 1504335640Shselasky# Check for Endace DAG card support. 1505335640Shselaskyif(NOT DISABLE_DAG) 1506335640Shselasky # 1507335640Shselasky # Try to find the DAG header file and library. 1508335640Shselasky # 1509335640Shselasky find_package(DAG) 1510335640Shselasky 1511335640Shselasky # 1512335640Shselasky # Did we succeed? 1513335640Shselasky # 1514335640Shselasky if(DAG_FOUND) 1515335640Shselasky # 1516335640Shselasky # Yes. 1517335640Shselasky # Check for various DAG API functions. 1518335640Shselasky # 1519335640Shselasky cmake_push_check_state() 1520335640Shselasky set(CMAKE_REQUIRED_INCLUDES ${DAG_INCLUDE_DIRS}) 1521335640Shselasky set(CMAKE_REQUIRED_LIBRARIES ${DAG_LIBRARIES}) 1522335640Shselasky check_function_exists(dag_attach_stream HAVE_DAG_STREAMS_API) 1523335640Shselasky if(NOT HAVE_DAG_STREAMS_API) 1524335640Shselasky message(FATAL_ERROR "DAG library lacks streams support") 1525335640Shselasky endif() 1526335640Shselasky check_function_exists(dag_attach_stream64 HAVE_DAG_LARGE_STREAMS_API) 1527335640Shselasky check_function_exists(dag_get_erf_types HAVE_DAG_GET_ERF_TYPES) 1528335640Shselasky check_function_exists(dag_get_stream_erf_types HAVE_DAG_GET_STREAM_ERF_TYPES) 1529335640Shselasky cmake_pop_check_state() 1530335640Shselasky 1531335640Shselasky include_directories(AFTER ${DAG_INCLUDE_DIRS}) 1532335640Shselasky set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-dag.c) 1533335640Shselasky set(HAVE_DAG_API TRUE) 1534335640Shselasky set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${DAG_LIBRARIES}) 1535335640Shselasky 1536335640Shselasky if(HAVE_DAG_LARGE_STREAMS_API) 1537335640Shselasky get_filename_component(DAG_LIBRARY_DIR ${DAG_LIBRARY} PATH) 1538335640Shselasky check_library_exists(vdag vdag_set_device_info ${DAG_LIBRARY_DIR} HAVE_DAG_VDAG) 1539335640Shselasky if(HAVE_DAG_VDAG) 1540335640Shselasky set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) 1541335640Shselasky endif() 1542335640Shselasky endif() 1543335640Shselasky endif() 1544356341Scyendif() 1545335640Shselasky 1546335640Shselasky# Check for Septel card support. 1547335640Shselaskyset(PROJECT_EXTERNAL_OBJECT_LIST "") 1548335640Shselaskyif(NOT DISABLE_SEPTEL) 1549335640Shselasky # 1550335640Shselasky # Do we have the msg.h header? 1551335640Shselasky # 1552335640Shselasky set(SEPTEL_INCLUDE_DIRS "${SEPTEL_ROOT}/INC") 1553335640Shselasky cmake_push_check_state() 1554335640Shselasky set(CMAKE_REQUIRED_INCLUDES ${SEPTEL_INCLUDE_DIRS}) 1555335640Shselasky check_include_file(msg.h HAVE_INC_MSG_H) 1556335640Shselasky cmake_pop_check_state() 1557335640Shselasky if(HAVE_INC_MSG_H) 1558335640Shselasky # 1559335640Shselasky # Yes. 1560335640Shselasky # 1561335640Shselasky include_directories(AFTER ${SEPTEL_INCLUDE_DIRS}) 1562335640Shselasky set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-septel.c) 1563335640Shselasky 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") 1564335640Shselasky set(HAVE_SEPTEL_API TRUE) 1565335640Shselasky endif() 1566356341Scyendif() 1567335640Shselasky 1568335640Shselasky# Check for Myricom SNF support. 1569335640Shselaskyif(NOT DISABLE_SNF) 1570335640Shselasky # 1571335640Shselasky # Try to find the SNF header file and library. 1572335640Shselasky # 1573335640Shselasky find_package(SNF) 1574335640Shselasky 1575335640Shselasky # 1576335640Shselasky # Did we succeed? 1577335640Shselasky # 1578335640Shselasky if(SNF_FOUND) 1579335640Shselasky # 1580335640Shselasky # Yes. 1581335640Shselasky # 1582335640Shselasky include_directories(AFTER ${SNF_INCLUDE_DIRS}) 1583335640Shselasky set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-snf.c) 1584335640Shselasky set(HAVE_SNF_API TRUE) 1585335640Shselasky set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${SNF_LIBRARIES}) 1586335640Shselasky endif() 1587356341Scyendif() 1588335640Shselasky 1589335640Shselasky# Check for Riverbed TurboCap support. 1590335640Shselaskyif(NOT DISABLE_TC) 1591335640Shselasky # 1592335640Shselasky # Try to find the TurboCap header file and library. 1593335640Shselasky # 1594335640Shselasky find_package(TC) 1595335640Shselasky 1596335640Shselasky # 1597335640Shselasky # Did we succeed? 1598335640Shselasky # 1599335640Shselasky if(TC_FOUND) 1600335640Shselasky # 1601335640Shselasky # Yes. 1602335640Shselasky # 1603335640Shselasky include_directories(AFTER ${TC_INCLUDE_DIRS}) 1604335640Shselasky set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-tc.c) 1605335640Shselasky set(HAVE_TC_API TRUE) 1606335640Shselasky set(PCAP_LINK_LIBRARIES "${PCAP_LINK_LIBRARIES} ${TC_LIBRARIES} ${CMAKE_USE_PTHREADS_INIT} stdc++") 1607335640Shselasky endif() 1608356341Scyendif() 1609335640Shselasky 1610335640Shselasky# 1611335640Shselasky# Remote capture support. 1612335640Shselasky# 1613335640Shselasky 1614335640Shselaskyif(ENABLE_REMOTE) 1615335640Shselasky # 1616335640Shselasky # Check for various members of struct msghdr. 1617335640Shselasky # We need to include ftmacros.h on some platforms, to make sure we 1618335640Shselasky # get the POSIX/Single USER Specification version of struct msghdr, 1619335640Shselasky # which has those members, rather than the backwards-compatible 1620335640Shselasky # version, which doesn't. That's not a system header file, and 1621335640Shselasky # at least some versions of CMake include it as <ftmacros.h>, which 1622335640Shselasky # won't check the current directory, so we add the top-level 1623335640Shselasky # source directory to the list of include directories when we do 1624335640Shselasky # the check. 1625335640Shselasky # 1626335640Shselasky cmake_push_check_state() 1627356341Scy set(CMAKE_REQUIRED_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}) 1628335640Shselasky check_struct_has_member("struct msghdr" msg_control "ftmacros.h;sys/socket.h" HAVE_STRUCT_MSGHDR_MSG_CONTROL) 1629335640Shselasky check_struct_has_member("struct msghdr" msg_flags "ftmacros.h;sys/socket.h" HAVE_STRUCT_MSGHDR_MSG_FLAGS) 1630335640Shselasky cmake_pop_check_state() 1631335640Shselasky set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} 1632335640Shselasky pcap-new.c pcap-rpcap.c rpcap-protocol.c sockutils.c) 1633335640Shselaskyendif(ENABLE_REMOTE) 1634335640Shselasky 1635335640Shselasky################################################################### 1636335640Shselasky# Warning options 1637335640Shselasky################################################################### 1638335640Shselasky 1639335640Shselasky# 1640335640Shselasky# Check and add warning options if we have a .devel file. 1641335640Shselasky# 1642356341Scyif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.devel OR EXISTS ${CMAKE_BINARY_DIR}/.devel) 1643335640Shselasky # 1644335640Shselasky # Warning options. 1645335640Shselasky # 1646335640Shselasky if(MSVC AND NOT ${CMAKE_C_COMPILER} MATCHES "clang*") 1647335640Shselasky # 1648335640Shselasky # MSVC, with Microsoft's front end and code generator. 1649335640Shselasky # "MSVC" is also set for Microsoft's compiler with a Clang 1650335640Shselasky # front end and their code generator ("Clang/C2"), so we 1651335640Shselasky # check for clang.exe and treat that differently. 1652335640Shselasky # 1653335640Shselasky check_and_add_compiler_option(-Wall) 1654335640Shselasky # 1655335640Shselasky # Disable some pointless warnings that /Wall turns on. 1656335640Shselasky # 1657335640Shselasky # Unfortunately, MSVC does not appear to have an equivalent 1658335640Shselasky # to "__attribute__((unused))" to mark a particular function 1659335640Shselasky # parameter as being known to be unused, so that the compiler 1660335640Shselasky # won't warn about it (for example, the function might have 1661335640Shselasky # that parameter because a pointer to it is being used, and 1662335640Shselasky # the signature of that function includes that parameter). 1663335640Shselasky # C++ lets you give a parameter a type but no name, but C 1664335640Shselasky # doesn't have that. 1665335640Shselasky # 1666335640Shselasky check_and_add_compiler_option(-wd4100) 1667335640Shselasky # 1668335640Shselasky # In theory, we care whether somebody uses f() rather than 1669335640Shselasky # f(void) to declare a function with no arguments, but, in 1670335640Shselasky # practice, there are places in the Windows header files 1671335640Shselasky # that appear to do that, so we squelch that warning. 1672335640Shselasky # 1673335640Shselasky check_and_add_compiler_option(-wd4255) 1674335640Shselasky # 1675335640Shselasky # Windows FD_SET() generates this, so we suppress it. 1676335640Shselasky # 1677335640Shselasky check_and_add_compiler_option(-wd4548) 1678335640Shselasky # 1679335640Shselasky # Perhaps testing something #defined to be 0 with #ifdef is an 1680335640Shselasky # error, and it should be tested with #if, but perhaps it's 1681335640Shselasky # not, and Microsoft does that in its headers, so we squelch 1682335640Shselasky # that warning. 1683335640Shselasky # 1684335640Shselasky check_and_add_compiler_option(-wd4574) 1685335640Shselasky # 1686335640Shselasky # The Windows headers also test not-defined values in #if, so 1687335640Shselasky # we don't want warnings about that, either. 1688335640Shselasky # 1689335640Shselasky check_and_add_compiler_option(-wd4668) 1690335640Shselasky # 1691335640Shselasky # We do *not* care whether some function is, or isn't, going to be 1692335640Shselasky # expanded inline. 1693335640Shselasky # 1694335640Shselasky check_and_add_compiler_option(-wd4710) 1695335640Shselasky check_and_add_compiler_option(-wd4711) 1696335640Shselasky # 1697335640Shselasky # We do *not* care whether we're adding padding bytes after 1698335640Shselasky # structure members. 1699335640Shselasky # 1700335640Shselasky check_and_add_compiler_option(-wd4820) 1701335640Shselasky else() 1702335640Shselasky # 1703335640Shselasky # Other compilers, including MSVC with a Clang front end and 1704335640Shselasky # Microsoft's code generator. We currently treat them as if 1705335640Shselasky # they might support GCC-style -W options. 1706335640Shselasky # 1707335640Shselasky check_and_add_compiler_option(-Wall) 1708335640Shselasky check_and_add_compiler_option(-Wsign-compare) 1709335640Shselasky check_and_add_compiler_option(-Wmissing-prototypes) 1710335640Shselasky check_and_add_compiler_option(-Wstrict-prototypes) 1711335640Shselasky check_and_add_compiler_option(-Wshadow) 1712335640Shselasky check_and_add_compiler_option(-Wdeclaration-after-statement) 1713335640Shselasky check_and_add_compiler_option(-Wused-but-marked-unused) 1714335640Shselasky check_and_add_compiler_option(-Wdocumentation) 1715335640Shselasky check_and_add_compiler_option(-Wcomma) 1716335640Shselasky check_and_add_compiler_option(-Wmissing-noreturn) 1717335640Shselasky # Warns about safeguards added in case the enums are extended 1718335640Shselasky # check_and_add_compiler_option(-Wcovered-switch-default) 1719335640Shselasky check_and_add_compiler_option(-Wmissing-variable-declarations) 1720335640Shselasky check_and_add_compiler_option(-Wunused-parameter) 1721335640Shselasky check_and_add_compiler_option(-Wformat-nonliteral) 1722335640Shselasky check_and_add_compiler_option(-Wunreachable-code) 1723335640Shselasky endif() 1724335640Shselaskyendif() 1725335640Shselasky 1726335640Shselasky# 1727335640Shselasky# Suppress some warnings we get with MSVC even without /Wall. 1728335640Shselasky# 1729335640Shselaskyif(MSVC AND NOT ${CMAKE_C_COMPILER} MATCHES "clang*") 1730335640Shselasky # 1731335640Shselasky # Yes, we have some functions that never return but that 1732335640Shselasky # have a non-void return type. That's because, on some 1733335640Shselasky # platforms, they *do* return values but, on other 1734335640Shselasky # platforms, including Windows, they just fail and 1735335640Shselasky # longjmp out by calling bpf_error(). 1736335640Shselasky # 1737335640Shselasky check_and_add_compiler_option(-wd4646) 1738335640Shselaskyendif() 1739335640Shselasky 1740335640Shselaskyfile(GLOB PROJECT_SOURCE_LIST_H 1741335640Shselasky *.h 1742335640Shselasky pcap/*.h 1743335640Shselasky) 1744335640Shselasky 1745335640Shselasky# 1746335640Shselasky# Try to have the compiler default to hiding symbols, so that only 1747335640Shselasky# symbols explicitly exported with PCAP_API will be visible outside 1748335640Shselasky# (shared) libraries. 1749335640Shselasky# 1750335640Shselasky# Not necessary with MSVC, as that's the default. 1751335640Shselasky# 1752335640Shselasky# XXX - we don't use ADD_COMPILER_EXPORT_FLAGS, because, as of CMake 1753335640Shselasky# 2.8.12.2, it doesn't know about Sun C/Oracle Studio, and, as of 1754335640Shselasky# CMake 2.8.6, it only sets the C++ compiler flags, rather than 1755335640Shselasky# allowing an arbitrary variable to be set with the "hide symbols 1756335640Shselasky# not explicitly exported" flag. 1757335640Shselasky# 1758335640Shselaskyif(NOT MSVC) 1759335640Shselasky if(CMAKE_C_COMPILER_ID MATCHES "SunPro") 1760335640Shselasky # 1761335640Shselasky # Sun C/Oracle Studio. 1762335640Shselasky # 1763335640Shselasky check_and_add_compiler_option(-xldscope=hidden) 1764335640Shselasky else() 1765335640Shselasky # 1766335640Shselasky # Try this for all other compilers; it's what GCC uses, 1767335640Shselasky # and a number of other compilers, such as Clang and Intel C, 1768335640Shselasky # use it as well. 1769335640Shselasky # 1770335640Shselasky check_and_add_compiler_option(-fvisibility=hidden) 1771335640Shselasky endif() 1772335640Shselaskyendif(NOT MSVC) 1773335640Shselasky 1774335640Shselasky# 1775335640Shselasky# Flex/Lex and YACC/Berkeley YACC/Bison. 1776335640Shselasky# From a mail message to the CMake mailing list by Andy Cedilnik of 1777335640Shselasky# Kitware. 1778335640Shselasky# 1779335640Shselasky 1780335640Shselasky# 1781335640Shselasky# Try to find Flex, a Windows version of Flex, or Lex. 1782335640Shselasky# 1783335640Shselaskyfind_program(LEX_EXECUTABLE NAMES flex win_flex lex) 1784335640Shselaskyif(LEX_EXECUTABLE STREQUAL "LEX_EXECUTABLE-NOTFOUND") 1785335640Shselasky message(FATAL_ERROR "Neither flex nor win_flex nor lex was found.") 1786335640Shselaskyendif() 1787335640Shselaskymessage(STATUS "Lexical analyzer generator: ${LEX_EXECUTABLE}") 1788335640Shselasky 1789335640Shselaskyadd_custom_command( 1790335640Shselasky OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/scanner.c ${CMAKE_CURRENT_BINARY_DIR}/scanner.h 1791335640Shselasky SOURCE ${pcap_SOURCE_DIR}/scanner.l 1792335640Shselasky COMMAND ${LEX_EXECUTABLE} -P pcap_ --header-file=scanner.h --nounput -o${CMAKE_CURRENT_BINARY_DIR}/scanner.c ${pcap_SOURCE_DIR}/scanner.l 1793335640Shselasky DEPENDS ${pcap_SOURCE_DIR}/scanner.l 1794335640Shselasky) 1795335640Shselasky 1796335640Shselasky# 1797335640Shselasky# Since scanner.c does not exist yet when cmake is run, mark 1798335640Shselasky# it as generated. 1799335640Shselasky# 1800335640Shselasky# Since scanner.c includes grammar.h, mark that as a dependency. 1801335640Shselasky# 1802335640Shselaskyset_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/scanner.c PROPERTIES 1803335640Shselasky GENERATED TRUE 1804335640Shselasky OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/grammar.h 1805335640Shselasky) 1806335640Shselasky 1807335640Shselasky# 1808335640Shselasky# Add scanner.c to the list of sources. 1809335640Shselasky# 1810335640Shselasky#set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${CMAKE_CURRENT_BINARY_DIR}/scanner.c) 1811335640Shselasky 1812335640Shselasky# 1813335640Shselasky# Try to find YACC or Bison. 1814335640Shselasky# 1815335640Shselaskyfind_program(YACC_EXECUTABLE NAMES bison win_bison byacc yacc) 1816335640Shselaskyif(YACC_EXECUTABLE STREQUAL "YACC_EXECUTABLE-NOTFOUND") 1817335640Shselasky message(FATAL_ERROR "Neither bison nor win_bison nor byacc nor yacc was found.") 1818335640Shselaskyendif() 1819335640Shselaskymessage(STATUS "Parser generator: ${YACC_EXECUTABLE}") 1820335640Shselasky 1821335640Shselasky# 1822335640Shselasky# Create custom command for the scanner. 1823335640Shselasky# Find out whether it's Bison or not by looking at the last component 1824335640Shselasky# of the path (without a .exe extension, if this is Windows). 1825335640Shselasky# 1826335640Shselaskyget_filename_component(YACC_NAME ${YACC_EXECUTABLE} NAME_WE) 1827335640Shselaskyif("${YACC_NAME}" STREQUAL "bison" OR "${YACC_NAME}" STREQUAL "win_bison") 1828335640Shselasky set(YACC_COMPATIBILITY_FLAG "-y") 1829335640Shselaskyendif() 1830335640Shselaskyadd_custom_command( 1831335640Shselasky OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/grammar.c ${CMAKE_CURRENT_BINARY_DIR}/grammar.h 1832335640Shselasky SOURCE ${pcap_SOURCE_DIR}/grammar.y 1833335640Shselasky COMMAND ${YACC_EXECUTABLE} ${YACC_COMPATIBILITY_FLAG} -p pcap_ -o ${CMAKE_CURRENT_BINARY_DIR}/grammar.c -d ${pcap_SOURCE_DIR}/grammar.y 1834335640Shselasky DEPENDS ${pcap_SOURCE_DIR}/grammar.y 1835335640Shselasky) 1836335640Shselasky 1837335640Shselasky# 1838335640Shselasky# Since grammar.c does not exists yet when cmake is run, mark 1839335640Shselasky# it as generated. 1840335640Shselasky# 1841335640Shselaskyset_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/grammar.c PROPERTIES 1842335640Shselasky GENERATED TRUE 1843335640Shselasky OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/scanner.h 1844335640Shselasky) 1845335640Shselasky 1846335640Shselasky# 1847335640Shselasky# Add grammar.c to the list of sources. 1848335640Shselasky# 1849335640Shselasky#set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${CMAKE_CURRENT_BINARY_DIR}/grammar.c) 1850335640Shselasky 1851335640Shselasky# 1852335640Shselasky# Assume, by default, no support for shared libraries and V7/BSD 1853356341Scy# convention for man pages (devices in section 4, file formats in 1854356341Scy# section 5, miscellaneous info in section 7, administrative commands 1855356341Scy# and daemons in section 8). Individual cases can override this. 1856335640Shselasky# Individual cases can override this. 1857335640Shselasky# 1858356341Scyset(MAN_DEVICES 4) 1859335640Shselaskyset(MAN_FILE_FORMATS 5) 1860335640Shselaskyset(MAN_MISC_INFO 7) 1861335640Shselaskyset(MAN_ADMIN_COMMANDS 8) 1862335640Shselaskyif(CMAKE_SYSTEM_NAME STREQUAL "AIX") 1863335640Shselasky # Workaround to enable certain features 1864335640Shselasky set(_SUN TRUE) 1865335640Shselasky if(PCAP_TYPE STREQUAL "bpf") 1866335640Shselasky # 1867335640Shselasky # If we're using BPF, we need libodm and libcfg, as 1868335640Shselasky # we use them to load the BPF module. 1869335640Shselasky # 1870335640Shselasky set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} odm cfg) 1871335640Shselasky endif() 1872335640Shselaskyelseif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX") 1873335640Shselasky if(CMAKE_SYSTEM_VERSION MATCHES "[A-Z.]*9\.[0-9]*") 1874335640Shselasky # 1875335640Shselasky # HP-UX 9.x. 1876335640Shselasky # 1877335640Shselasky set(HAVE_HPUX9 TRUE) 1878335640Shselasky elseif(CMAKE_SYSTEM_VERSION MATCHES "[A-Z.]*10\.0") 1879335640Shselasky # 1880335640Shselasky # HP-UX 10.0. 1881335640Shselasky # 1882335640Shselasky elseif(CMAKE_SYSTEM_VERSION MATCHES "[A-Z.]*10\.1") 1883335640Shselasky # 1884335640Shselasky # HP-UX 10.1. 1885335640Shselasky # 1886335640Shselasky else() 1887335640Shselasky # 1888335640Shselasky # HP-UX 10.20 and later. 1889335640Shselasky # 1890335640Shselasky set(HAVE_HPUX10_20_OR_LATER TRUE) 1891335640Shselasky endif() 1892335640Shselasky 1893335640Shselasky # 1894335640Shselasky # Use System V conventions for man pages. 1895335640Shselasky # 1896335640Shselasky set(MAN_ADMIN_COMMANDS 1m) 1897335640Shselasky set(MAN_FILE_FORMATS 4) 1898335640Shselasky set(MAN_MISC_INFO 5) 1899335640Shselaskyelseif(CMAKE_SYSTEM_NAME STREQUAL "IRIX" OR CMAKE_SYSTEM_NAME STREQUAL "IRIX64") 1900335640Shselasky # 1901335640Shselasky # Use IRIX conventions for man pages; they're the same as the 1902335640Shselasky # System V conventions, except that they use section 8 for 1903335640Shselasky # administrative commands and daemons. 1904335640Shselasky # 1905335640Shselasky set(MAN_FILE_FORMATS 4) 1906335640Shselasky set(MAN_MISC_INFO 5) 1907335640Shselaskyelseif(CMAKE_SYSTEM_NAME STREQUAL "OSF1") 1908335640Shselasky # 1909335640Shselasky # DEC OSF/1, a/k/a Digial UNIX, a/k/a Tru64 UNIX. 1910335640Shselasky # Use Tru64 UNIX conventions for man pages; they're the same as the 1911335640Shselasky # System V conventions except that they use section 8 for 1912335640Shselasky # administrative commands and daemons. 1913335640Shselasky # 1914335640Shselasky set(MAN_FILE_FORMATS 4) 1915335640Shselasky set(MAN_MISC_INFO 5) 1916356341Scy set(MAN_DEVICES 7) 1917335640Shselaskyelseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_VERSION MATCHES "5[.][0-9.]*") 1918335640Shselasky # 1919335640Shselasky # SunOS 5.x. 1920335640Shselasky # 1921335640Shselasky set(HAVE_SOLARIS TRUE) 1922335640Shselasky # 1923335640Shselasky # Make sure errno is thread-safe, in case we're called in 1924335640Shselasky # a multithreaded program. We don't guarantee that two 1925335640Shselasky # threads can use the *same* pcap_t safely, but the 1926335640Shselasky # current version does guarantee that you can use different 1927335640Shselasky # pcap_t's in different threads, and even that pcap_compile() 1928335640Shselasky # is thread-safe (it wasn't thread-safe in some older versions). 1929335640Shselasky # 1930335640Shselasky add_definitions(-D_TS_ERRNO) 1931335640Shselasky 1932335640Shselasky if(CMAKE_SYSTEM_VERSION STREQUAL "5.12") 1933335640Shselasky else() 1934335640Shselasky # 1935335640Shselasky # Use System V conventions for man pages. 1936335640Shselasky # 1937335640Shselasky set(MAN_ADMIN_COMMANDS 1m) 1938335640Shselasky set(MAN_FILE_FORMATS 4) 1939335640Shselasky set(MAN_MISC_INFO 5) 1940356341Scy set(MAN_DEVICES 7D) 1941335640Shselasky endif() 1942335640Shselaskyendif() 1943335640Shselasky 1944335640Shselaskysource_group("Source Files" FILES ${PROJECT_SOURCE_LIST_C}) 1945335640Shselaskysource_group("Header Files" FILES ${PROJECT_SOURCE_LIST_H}) 1946335640Shselasky 1947335640Shselaskyif(WIN32) 1948335640Shselasky # 1949335640Shselasky # Add pcap-dll.rc to the list of sources. 1950335640Shselasky # 1951335640Shselasky set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${pcap_SOURCE_DIR}/pcap-dll.rc) 1952335640Shselaskyendif(WIN32) 1953335640Shselasky 1954335640Shselasky# 1955335640Shselasky# Add subdirectories after we've set various variables, so they pick up 1956335640Shselasky# pick up those variables. 1957335640Shselasky# 1958335640Shselaskyif(ENABLE_REMOTE) 1959335640Shselasky add_subdirectory(rpcapd) 1960335640Shselaskyendif(ENABLE_REMOTE) 1961335640Shselaskyadd_subdirectory(testprogs) 1962335640Shselasky 1963335640Shselasky###################################### 1964335640Shselasky# Register targets 1965335640Shselasky###################################### 1966335640Shselasky 1967335640Shselasky# 1968335640Shselasky# Special target to serialize the building of the generated source. 1969335640Shselasky# 1970335640Shselasky# See 1971335640Shselasky# 1972335640Shselasky# http://public.kitware.com/pipermail/cmake/2013-August/055510.html 1973335640Shselasky# 1974335640Shselaskyadd_custom_target(SerializeTarget 1975335640Shselasky DEPENDS 1976335640Shselasky ${CMAKE_CURRENT_BINARY_DIR}/grammar.c 1977335640Shselasky ${CMAKE_CURRENT_BINARY_DIR}/scanner.c 1978335640Shselasky) 1979335640Shselasky 1980335640Shselaskyset_source_files_properties(${PROJECT_EXTERNAL_OBJECT_LIST} PROPERTIES 1981335640Shselasky EXTERNAL_OBJECT TRUE) 1982335640Shselasky 1983335640Shselaskyif(BUILD_SHARED_LIBS) 1984335640Shselasky add_library(${LIBRARY_NAME} SHARED 1985335640Shselasky ${PROJECT_SOURCE_LIST_C} 1986335640Shselasky ${CMAKE_CURRENT_BINARY_DIR}/grammar.c 1987335640Shselasky ${CMAKE_CURRENT_BINARY_DIR}/scanner.c 1988335640Shselasky ${PROJECT_EXTERNAL_OBJECT_LIST} 1989335640Shselasky ) 1990335640Shselasky add_dependencies(${LIBRARY_NAME} SerializeTarget) 1991335640Shselasky set_target_properties(${LIBRARY_NAME} PROPERTIES 1992335640Shselasky COMPILE_DEFINITIONS BUILDING_PCAP) 1993356341Scy # 1994356341Scy # No matter what the library is called - it might be called "wpcap" 1995356341Scy # in a Windows build - the symbol to define to indicate that we're 1996356341Scy # building the library, rather than a program using the library, 1997356341Scy # and thus that we're exporting functions defined in our public 1998356341Scy # header files, rather than importing those functions, is 1999356341Scy # pcap_EXPORTS. 2000356341Scy # 2001356341Scy set_target_properties(${LIBRARY_NAME} PROPERTIES 2002356341Scy DEFINE_SYMBOL pcap_EXPORTS) 2003335640Shselaskyendif(BUILD_SHARED_LIBS) 2004335640Shselasky 2005335640Shselaskyadd_library(${LIBRARY_NAME}_static STATIC 2006335640Shselasky ${PROJECT_SOURCE_LIST_C} 2007335640Shselasky ${CMAKE_CURRENT_BINARY_DIR}/grammar.c 2008335640Shselasky ${CMAKE_CURRENT_BINARY_DIR}/scanner.c 2009335640Shselasky ${PROJECT_EXTERNAL_OBJECT_LIST} 2010335640Shselasky) 2011335640Shselaskyadd_dependencies(${LIBRARY_NAME}_static SerializeTarget) 2012335640Shselaskyset_target_properties(${LIBRARY_NAME}_static PROPERTIES 2013335640Shselasky COMPILE_DEFINITIONS BUILDING_PCAP) 2014335640Shselasky 2015335640Shselaskyif(WIN32) 2016335640Shselasky if(BUILD_SHARED_LIBS) 2017335640Shselasky set_target_properties(${LIBRARY_NAME} PROPERTIES 2018335640Shselasky VERSION ${PACKAGE_VERSION_NOSUFFIX} # only MAJOR and MINOR are needed 2019335640Shselasky ) 2020335640Shselasky endif(BUILD_SHARED_LIBS) 2021335640Shselasky if(MSVC) 2022335640Shselasky # XXX For DLLs, the TARGET_PDB_FILE generator expression can be used to locate 2023335640Shselasky # its PDB file's output directory for installation. 2024335640Shselasky # cmake doesn't offer a generator expression for PDB files generated by the 2025335640Shselasky # compiler (static libraries). 2026335640Shselasky # So instead of considering any possible output there is (there are many), 2027335640Shselasky # this will search for the PDB file in the compiler's initial output directory, 2028335640Shselasky # which is always ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles\wpcap_static.dir 2029335640Shselasky # regardless of architecture, build generator etc. 2030335640Shselasky # Quite hackish indeed. 2031335640Shselasky set(CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY $<TARGET_FILE_DIR:${LIBRARY_NAME}_static>) 2032335640Shselasky set_target_properties(${LIBRARY_NAME}_static PROPERTIES 2033335640Shselasky COMPILE_PDB_NAME ${LIBRARY_NAME}_static 2034335640Shselasky OUTPUT_NAME "${LIBRARY_NAME}_static" 2035335640Shselasky ) 2036335640Shselasky elseif(MINGW) 2037335640Shselasky # 2038335640Shselasky # For compatibility, build the shared library without the "lib" prefix on 2039335640Shselasky # MinGW as well. 2040335640Shselasky # 2041356341Scy set_target_properties(${LIBRARY_NAME} PROPERTIES 2042335640Shselasky PREFIX "" 2043335640Shselasky OUTPUT_NAME "${LIBRARY_NAME}" 2044335640Shselasky ) 2045335640Shselasky set_target_properties(${LIBRARY_NAME}_static PROPERTIES 2046335640Shselasky OUTPUT_NAME "${LIBRARY_NAME}" 2047335640Shselasky ) 2048335640Shselasky endif() 2049335640Shselaskyelse(WIN32) # UN*X 2050335640Shselasky if(BUILD_SHARED_LIBS) 2051335640Shselasky if(APPLE) 2052335640Shselasky set_target_properties(${LIBRARY_NAME} PROPERTIES 2053335640Shselasky VERSION ${PACKAGE_VERSION} 2054335640Shselasky SOVERSION A 2055335640Shselasky ) 2056335640Shselasky else(APPLE) 2057335640Shselasky set_target_properties(${LIBRARY_NAME} PROPERTIES 2058335640Shselasky VERSION ${PACKAGE_VERSION} 2059335640Shselasky SOVERSION ${PACKAGE_VERSION_MAJOR} 2060335640Shselasky ) 2061335640Shselasky endif(APPLE) 2062335640Shselasky endif(BUILD_SHARED_LIBS) 2063335640Shselasky set_target_properties(${LIBRARY_NAME}_static PROPERTIES 2064335640Shselasky OUTPUT_NAME "${LIBRARY_NAME}" 2065335640Shselasky ) 2066335640Shselaskyendif(WIN32) 2067335640Shselasky 2068335640Shselaskyif(BUILD_SHARED_LIBS) 2069335640Shselasky if(NOT C_ADDITIONAL_FLAGS STREQUAL "") 2070335640Shselasky set_target_properties(${LIBRARY_NAME} PROPERTIES COMPILE_FLAGS ${C_ADDITIONAL_FLAGS}) 2071335640Shselasky endif() 2072335640Shselasky target_link_libraries(${LIBRARY_NAME} ${PCAP_LINK_LIBRARIES}) 2073335640Shselaskyendif(BUILD_SHARED_LIBS) 2074335640Shselasky 2075335640Shselaskyif(NOT C_ADDITIONAL_FLAGS STREQUAL "") 2076335640Shselasky set_target_properties(${LIBRARY_NAME}_static PROPERTIES COMPILE_FLAGS ${C_ADDITIONAL_FLAGS}) 2077335640Shselaskyendif() 2078335640Shselasky 2079356341Scy# 2080356341Scy# On macOS, build libpcap for the appropriate architectures, if 2081356341Scy# CMAKE_OSX_ARCHITECTURES isn't set (if it is, let that control 2082356341Scy# the architectures for which to build it). 2083356341Scy# 2084356341Scyif(APPLE AND "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "") 2085356341Scy # 2086356341Scy # Get the major version of Darwin. 2087356341Scy # 2088356341Scy string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MAJOR "${CMAKE_SYSTEM_VERSION}") 2089356341Scy 2090356341Scy if(SYSTEM_VERSION_MAJOR LESS 8) 2091356341Scy # 2092356341Scy # Pre-Tiger. Build only for 32-bit PowerPC. 2093356341Scy # 2094356341Scy set(OSX_LIBRARY_ARCHITECTURES "ppc") 2095356341Scy elseif(SYSTEM_VERSION_MAJOR EQUAL 8) 2096356341Scy # 2097356341Scy # Tiger. Is this prior to, or with, Intel support? 2098356341Scy # 2099356341Scy # Get the minor version of Darwin. 2100356341Scy # 2101356341Scy string(REPLACE "${SYSTEM_VERSION_MAJOR}." "" SYSTEM_MINOR_AND_PATCH_VERSION ${CMAKE_SYSTEM_VERSION}) 2102356341Scy string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MINOR "${SYSTEM_MINOR_AND_PATCH_VERSION}") 2103356341Scy if(SYSTEM_VERSION_MINOR LESS 4) 2104356341Scy # 2105356341Scy # Prior to Intel support. Build for 32-bit 2106356341Scy # PowerPC and 64-bit PowerPC, with 32-bit PowerPC 2107356341Scy # first. (I'm guessing that's what Apple does.) 2108356341Scy # 2109356341Scy set(OSX_LIBRARY_ARCHITECTURES "ppc;ppc64") 2110356341Scy elseif(SYSTEM_VERSION_MINOR LESS 7) 2111356341Scy # 2112356341Scy # With Intel support but prior to x86-64 support. 2113356341Scy # Build for 32-bit PowerPC, 64-bit PowerPC, and 32-bit x86, 2114356341Scy # with 32-bit PowerPC first. 2115356341Scy # (I'm guessing that's what Apple does.) 2116356341Scy # 2117356341Scy set(OSX_LIBRARY_ARCHITECTURES "ppc;ppc64;i386") 2118356341Scy else() 2119356341Scy # 2120356341Scy # With Intel support including x86-64 support. 2121356341Scy # Build for 32-bit PowerPC, 64-bit PowerPC, 32-bit x86, 2122356341Scy # and x86-64, with 32-bit PowerPC first. 2123356341Scy # (I'm guessing that's what Apple does.) 2124356341Scy # 2125356341Scy set(OSX_LIBRARY_ARCHITECTURES "ppc;ppc64;i386;x86_64") 2126356341Scy endif() 2127356341Scy elseif(SYSTEM_VERSION_MAJOR EQUAL 9) 2128356341Scy # 2129356341Scy # Leopard. Build for 32-bit PowerPC, 64-bit 2130356341Scy # PowerPC, 32-bit x86, and x86-64, with 32-bit PowerPC 2131356341Scy # first. (That's what Apple does.) 2132356341Scy # 2133356341Scy set(OSX_LIBRARY_ARCHITECTURES "ppc;ppc64;i386;x86_64") 2134356341Scy elseif(SYSTEM_VERSION_MAJOR EQUAL 10) 2135356341Scy # 2136356341Scy # Snow Leopard. Build for x86-64, 32-bit x86, and 2137356341Scy # 32-bit PowerPC, with x86-64 first. (That's 2138356341Scy # what Apple does, even though Snow Leopard 2139356341Scy # doesn't run on PPC, so PPC libpcap runs under 2140356341Scy # Rosetta, and Rosetta doesn't support BPF 2141356341Scy # ioctls, so PPC programs can't do live 2142356341Scy # captures.) 2143356341Scy # 2144356341Scy set(OSX_LIBRARY_ARCHITECTURES "x86_64;i386;ppc") 2145356341Scy else() 2146356341Scy # 2147356341Scy # Post-Snow Leopard. Build for x86-64 and 32-bit x86, 2148356341Scy # with x86-64 first. (That's what Apple does) 2149356341Scy # XXX - update if and when Apple drops support 2150356341Scy # for 32-bit x86 code and if and when Apple adds 2151356341Scy # ARM-based Macs. (You're on your own for iOS etc.) 2152356341Scy # 2153356341Scy # XXX - check whether we *can* build for i386 and, if not, 2154356341Scy # suggest that the user install the /usr/include headers if 2155356341Scy # they want to build fat. 2156356341Scy # 2157356341Scy cmake_push_check_state() 2158356341Scy set(CMAKE_REQUIRED_FLAGS "-arch i386") 2159356341Scy check_c_source_compiles( 2160356341Scy"int 2161356341Scymain(void) 2162356341Scy{ 2163356341Scy return 0; 2164356341Scy} 2165356341Scy" 2166356341Scy X86_32_BIT_SUPPORTED) 2167356341Scy cmake_pop_check_state() 2168356341Scy if(X86_32_BIT_SUPPORTED) 2169356341Scy set(OSX_LIBRARY_ARCHITECTURES "x86_64;i386") 2170356341Scy else() 2171356341Scy set(OSX_LIBRARY_ARCHITECTURES "x86_64") 2172356341Scy if(SYSTEM_VERSION_MAJOR LESS 18) 2173356341Scy # 2174356341Scy # Pre-Mojave; the command-line tools should be sufficient to 2175356341Scy # enable 32-bit x86 builds. 2176356341Scy # 2177356341Scy message(WARNING "Compiling for 32-bit x86 gives an error; try installing the command-line tools") 2178356341Scy else() 2179356341Scy 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") 2180356341Scy endif() 2181356341Scy endif() 2182356341Scy endif() 2183356341Scy if(BUILD_SHARED_LIBS) 2184356341Scy set_target_properties(${LIBRARY_NAME} PROPERTIES 2185356341Scy OSX_ARCHITECTURES "${OSX_LIBRARY_ARCHITECTURES}") 2186356341Scy endif(BUILD_SHARED_LIBS) 2187356341Scy set_target_properties(${LIBRARY_NAME}_static PROPERTIES 2188356341Scy OSX_ARCHITECTURES "${OSX_LIBRARY_ARCHITECTURES}") 2189356341Scyendif() 2190356341Scy 2191335640Shselasky###################################### 2192335640Shselasky# Write out the config.h file 2193335640Shselasky###################################### 2194335640Shselasky 2195335640Shselaskyconfigure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h) 2196335640Shselasky 2197335640Shselasky###################################### 2198335640Shselasky# Install pcap library, include files, and man pages 2199335640Shselasky###################################### 2200335640Shselasky 2201335640Shselasky# 2202335640Shselasky# "Define GNU standard installation directories", which actually 2203335640Shselasky# are also defined, to some degree, by autotools, and at least 2204335640Shselasky# some of which are general UN*X conventions. 2205335640Shselasky# 2206335640Shselaskyinclude(GNUInstallDirs) 2207335640Shselasky 2208335640Shselaskyset(LIBRARY_NAME_STATIC ${LIBRARY_NAME}_static) 2209335640Shselasky 2210335640Shselaskyfunction(install_manpage_symlink SOURCE TARGET MANDIR) 2211335640Shselasky if(MINGW) 2212335640Shselasky find_program(LINK_EXECUTABLE ln) 2213335640Shselasky if(LINK_EXECUTABLE) 2214335640Shselasky set(LINK_COMMAND "\"${LINK_EXECUTABLE}\" \"-s\" \"${SOURCE}\" \"${TARGET}\"") 2215335640Shselasky else(LINK_EXECUTABLE) 2216335640Shselasky message(FATAL_ERROR "ln (http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ln.html) not found.") 2217335640Shselasky endif(LINK_EXECUTABLE) 2218335640Shselasky else(MINGW) 2219335640Shselasky set(LINK_COMMAND "\"${CMAKE_COMMAND}\" \"-E\" \"create_symlink\" \"${SOURCE}\" \"${TARGET}\"") 2220335640Shselasky endif(MINGW) 2221335640Shselasky 2222335640Shselasky install(CODE 2223335640Shselasky "message(STATUS \"Symlinking: ${CMAKE_INSTALL_PREFIX}/${MANDIR}/${SOURCE} to ${TARGET}\") 2224335640Shselasky execute_process( 2225335640Shselasky COMMAND \"${CMAKE_COMMAND}\" \"-E\" \"remove\" \"${TARGET}\" 2226335640Shselasky WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${MANDIR} 2227335640Shselasky ) 2228335640Shselasky execute_process( 2229335640Shselasky COMMAND ${LINK_COMMAND} 2230335640Shselasky WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${MANDIR} 2231335640Shselasky RESULT_VARIABLE EXIT_STATUS 2232335640Shselasky ) 2233335640Shselasky if(NOT EXIT_STATUS EQUAL 0) 2234335640Shselasky message(FATAL_ERROR \"Could not create symbolic link from ${CMAKE_INSTALL_PREFIX}/${MANDIR}/${SOURCE} to ${TARGET}\") 2235335640Shselasky endif() 2236335640Shselasky set(CMAKE_INSTALL_MANIFEST_FILES \${CMAKE_INSTALL_MANIFEST_FILES} ${CMAKE_INSTALL_PREFIX}/${MANDIR}/${TARGET})") 2237335640Shselaskyendfunction(install_manpage_symlink) 2238335640Shselasky 2239335640Shselaskyset(MAN1_NOEXPAND pcap-config.1) 2240335640Shselaskyset(MAN3PCAP_EXPAND 2241335640Shselasky pcap.3pcap.in 2242335640Shselasky pcap_compile.3pcap.in 2243335640Shselasky pcap_datalink.3pcap.in 2244335640Shselasky pcap_dump_open.3pcap.in 2245335640Shselasky pcap_get_tstamp_precision.3pcap.in 2246335640Shselasky pcap_list_datalinks.3pcap.in 2247335640Shselasky pcap_list_tstamp_types.3pcap.in 2248335640Shselasky pcap_open_dead.3pcap.in 2249335640Shselasky pcap_open_offline.3pcap.in 2250356341Scy pcap_set_immediate_mode.3pcap.in 2251335640Shselasky pcap_set_tstamp_precision.3pcap.in 2252335640Shselasky pcap_set_tstamp_type.3pcap.in 2253335640Shselasky) 2254335640Shselaskyset(MAN3PCAP_NOEXPAND 2255335640Shselasky pcap_activate.3pcap 2256335640Shselasky pcap_breakloop.3pcap 2257335640Shselasky pcap_can_set_rfmon.3pcap 2258335640Shselasky pcap_close.3pcap 2259335640Shselasky pcap_create.3pcap 2260335640Shselasky pcap_datalink_name_to_val.3pcap 2261335640Shselasky pcap_datalink_val_to_name.3pcap 2262335640Shselasky pcap_dump.3pcap 2263335640Shselasky pcap_dump_close.3pcap 2264335640Shselasky pcap_dump_file.3pcap 2265335640Shselasky pcap_dump_flush.3pcap 2266335640Shselasky pcap_dump_ftell.3pcap 2267335640Shselasky pcap_file.3pcap 2268335640Shselasky pcap_fileno.3pcap 2269335640Shselasky pcap_findalldevs.3pcap 2270335640Shselasky pcap_freecode.3pcap 2271335640Shselasky pcap_get_required_select_timeout.3pcap 2272335640Shselasky pcap_get_selectable_fd.3pcap 2273335640Shselasky pcap_geterr.3pcap 2274335640Shselasky pcap_inject.3pcap 2275335640Shselasky pcap_is_swapped.3pcap 2276335640Shselasky pcap_lib_version.3pcap 2277335640Shselasky pcap_lookupdev.3pcap 2278335640Shselasky pcap_lookupnet.3pcap 2279335640Shselasky pcap_loop.3pcap 2280335640Shselasky pcap_major_version.3pcap 2281335640Shselasky pcap_next_ex.3pcap 2282335640Shselasky pcap_offline_filter.3pcap 2283335640Shselasky pcap_open_live.3pcap 2284335640Shselasky pcap_set_buffer_size.3pcap 2285335640Shselasky pcap_set_datalink.3pcap 2286335640Shselasky pcap_set_promisc.3pcap 2287356341Scy pcap_set_protocol_linux.3pcap 2288335640Shselasky pcap_set_rfmon.3pcap 2289335640Shselasky pcap_set_snaplen.3pcap 2290335640Shselasky pcap_set_timeout.3pcap 2291335640Shselasky pcap_setdirection.3pcap 2292335640Shselasky pcap_setfilter.3pcap 2293335640Shselasky pcap_setnonblock.3pcap 2294335640Shselasky pcap_snapshot.3pcap 2295335640Shselasky pcap_stats.3pcap 2296335640Shselasky pcap_statustostr.3pcap 2297335640Shselasky pcap_strerror.3pcap 2298335640Shselasky pcap_tstamp_type_name_to_val.3pcap 2299335640Shselasky pcap_tstamp_type_val_to_name.3pcap 2300335640Shselasky) 2301335640Shselaskyset(MANFILE_EXPAND pcap-savefile.manfile.in) 2302335640Shselaskyset(MANMISC_EXPAND 2303335640Shselasky pcap-filter.manmisc.in 2304335640Shselasky pcap-linktype.manmisc.in 2305335640Shselasky pcap-tstamp.manmisc.in 2306335640Shselasky) 2307335640Shselasky 2308335640Shselaskyif(NOT BUILD_SHARED_LIBS) 2309335640Shselasky unset(LIBRARY_NAME) 2310335640Shselaskyendif(NOT BUILD_SHARED_LIBS) 2311335640Shselasky 2312335640Shselaskyif(WIN32) 2313335640Shselasky if(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8) 2314335640Shselasky # 2315335640Shselasky # Install 64-bit code built with MSVC in the amd64 subdirectories, 2316335640Shselasky # as that's where it expects it to be. 2317335640Shselasky # 2318335640Shselasky install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC} 2319335640Shselasky RUNTIME DESTINATION bin/amd64 2320335640Shselasky LIBRARY DESTINATION lib/amd64 2321335640Shselasky ARCHIVE DESTINATION lib/amd64) 2322335640Shselasky if(NOT MINGW) 2323335640Shselasky install(FILES $<TARGET_FILE_DIR:${LIBRARY_NAME_STATIC}>/${LIBRARY_NAME_STATIC}.pdb 2324335640Shselasky DESTINATION bin/amd64 OPTIONAL) 2325335640Shselasky if(BUILD_SHARED_LIBS) 2326335640Shselasky install(FILES $<TARGET_PDB_FILE:${LIBRARY_NAME}> 2327335640Shselasky DESTINATION bin/amd64 OPTIONAL) 2328335640Shselasky endif(BUILD_SHARED_LIBS) 2329335640Shselasky endif(NOT MINGW) 2330335640Shselasky else(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8) 2331335640Shselasky # 2332335640Shselasky # Install 32-bit code, and 64-bit code not built with MSVC 2333335640Shselasky # in the top-level directories, as those are where they 2334335640Shselasky # expect it to be. 2335335640Shselasky # 2336335640Shselasky install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC} 2337335640Shselasky RUNTIME DESTINATION bin 2338335640Shselasky LIBRARY DESTINATION lib 2339335640Shselasky ARCHIVE DESTINATION lib) 2340335640Shselasky if(NOT MINGW) 2341335640Shselasky install(FILES $<TARGET_FILE_DIR:${LIBRARY_NAME_STATIC}>/${LIBRARY_NAME_STATIC}.pdb 2342335640Shselasky DESTINATION bin OPTIONAL) 2343335640Shselasky if(BUILD_SHARED_LIBS) 2344335640Shselasky install(FILES $<TARGET_PDB_FILE:${LIBRARY_NAME}> 2345335640Shselasky DESTINATION bin OPTIONAL) 2346335640Shselasky endif(BUILD_SHARED_LIBS) 2347335640Shselasky endif(NOT MINGW) 2348335640Shselasky endif(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8) 2349335640Shselaskyelse(WIN32) 2350356341Scy install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC} DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}) 2351335640Shselaskyendif(WIN32) 2352335640Shselasky 2353335640Shselaskyinstall(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/pcap/ DESTINATION include/pcap) 2354335640Shselaskyinstall(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pcap.h DESTINATION include) 2355356341Scyinstall(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pcap-bpf.h DESTINATION include) 2356356341Scyinstall(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pcap-namedb.h DESTINATION include) 2357335640Shselasky 2358335640Shselasky# On UN*X, and on Windows when not using MSVC, generate libpcap.pc and 2359335640Shselasky# pcap-config and process man pages and arrange that they be installed. 2360335640Shselaskyif(NOT MSVC) 2361335640Shselasky set(PACKAGE_NAME ${LIBRARY_NAME}) 2362335640Shselasky set(prefix ${CMAKE_INSTALL_PREFIX}) 2363335640Shselasky set(exec_prefix "\${prefix}") 2364335640Shselasky set(includedir "\${prefix}/include") 2365335640Shselasky set(libdir "\${exec_prefix}/lib") 2366335640Shselasky if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR 2367335640Shselasky CMAKE_SYSTEM_NAME STREQUAL "NetBSD" OR 2368335640Shselasky CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR 2369335640Shselasky CMAKE_SYSTEM_NAME STREQUAL "DragonFly BSD" OR 2370335640Shselasky CMAKE_SYSTEM_NAME STREQUAL "Linux" OR 2371335640Shselasky CMAKE_SYSTEM_NAME STREQUAL "OSF1") 2372335640Shselasky # 2373335640Shselasky # Platforms where the linker is the GNU linker 2374335640Shselasky # or accepts command-line arguments like 2375335640Shselasky # those the GNU linker accepts. 2376335640Shselasky # 2377335640Shselasky set(V_RPATH_OPT "-Wl,-rpath,") 2378335640Shselasky elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_VERSION MATCHES "5[.][0-9.]*") 2379335640Shselasky # 2380335640Shselasky # SunOS 5.x. 2381335640Shselasky # 2382335640Shselasky # XXX - this assumes GCC is using the Sun linker, 2383335640Shselasky # rather than the GNU linker. 2384335640Shselasky # 2385335640Shselasky set(V_RPATH_OPT "-Wl,-R,") 2386335640Shselasky else() 2387335640Shselasky # 2388335640Shselasky # No option needed to set the RPATH. 2389335640Shselasky # 2390335640Shselasky set(V_RPATH_OPT "") 2391335640Shselasky endif() 2392335640Shselasky set(LIBS "") 2393335640Shselasky foreach(LIB ${PCAP_LINK_LIBRARIES}) 2394335640Shselasky set(LIBS "${LIBS} -l${LIB}") 2395335640Shselasky endforeach(LIB) 2396356341Scy configure_file(${CMAKE_CURRENT_SOURCE_DIR}/pcap-config.in ${CMAKE_CURRENT_BINARY_DIR}/pcap-config @ONLY) 2397356341Scy configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpcap.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libpcap.pc @ONLY) 2398335640Shselasky install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/pcap-config DESTINATION bin) 2399335640Shselasky install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpcap.pc DESTINATION lib/pkgconfig) 2400335640Shselasky 2401335640Shselasky # 2402335640Shselasky # Man pages. 2403335640Shselasky # 2404335640Shselasky # For each section of the manual for which we have man pages 2405335640Shselasky # that require macro expansion, do the expansion. 2406335640Shselasky # 2407335640Shselasky set(MAN1 "") 2408335640Shselasky foreach(MANPAGE ${MAN1_NOEXPAND}) 2409356341Scy set(MAN1 ${MAN1} ${CMAKE_CURRENT_SOURCE_DIR}/${MANPAGE}) 2410335640Shselasky endforeach(MANPAGE) 2411335640Shselasky install(FILES ${MAN1} DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) 2412335640Shselasky 2413335640Shselasky set(MAN3PCAP "") 2414335640Shselasky foreach(MANPAGE ${MAN3PCAP_NOEXPAND}) 2415356341Scy set(MAN3PCAP ${MAN3PCAP} ${CMAKE_CURRENT_SOURCE_DIR}/${MANPAGE}) 2416335640Shselasky endforeach(MANPAGE) 2417335640Shselasky foreach(TEMPLATE_MANPAGE ${MAN3PCAP_EXPAND}) 2418335640Shselasky string(REPLACE ".in" "" MANPAGE ${TEMPLATE_MANPAGE}) 2419356341Scy configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY) 2420335640Shselasky set(MAN3PCAP ${MAN3PCAP} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE}) 2421335640Shselasky endforeach(TEMPLATE_MANPAGE) 2422335640Shselasky install(FILES ${MAN3PCAP} DESTINATION ${CMAKE_INSTALL_MANDIR}/man3) 2423335640Shselasky install_manpage_symlink(pcap_datalink_val_to_name.3pcap pcap_datalink_val_to_description.3pcap ${CMAKE_INSTALL_MANDIR}/man3) 2424335640Shselasky install_manpage_symlink(pcap_dump_open.3pcap pcap_dump_fopen.3pcap ${CMAKE_INSTALL_MANDIR}/man3) 2425335640Shselasky install_manpage_symlink(pcap_findalldevs.3pcap pcap_freealldevs.3pcap ${CMAKE_INSTALL_MANDIR}/man3) 2426335640Shselasky install_manpage_symlink(pcap_geterr.3pcap pcap_perror.3pcap ${CMAKE_INSTALL_MANDIR}/man3) 2427335640Shselasky install_manpage_symlink(pcap_inject.3pcap pcap_sendpacket.3pcap ${CMAKE_INSTALL_MANDIR}/man3) 2428335640Shselasky install_manpage_symlink(pcap_list_datalinks.3pcap pcap_free_datalinks.3pcap ${CMAKE_INSTALL_MANDIR}/man3) 2429335640Shselasky install_manpage_symlink(pcap_list_tstamp_types.3pcap pcap_free_tstamp_types.3pcap ${CMAKE_INSTALL_MANDIR}/man3) 2430335640Shselasky install_manpage_symlink(pcap_loop.3pcap pcap_dispatch.3pcap ${CMAKE_INSTALL_MANDIR}/man3) 2431335640Shselasky install_manpage_symlink(pcap_major_version.3pcap pcap_minor_version.3pcap ${CMAKE_INSTALL_MANDIR}/man3) 2432335640Shselasky install_manpage_symlink(pcap_next_ex.3pcap pcap_next.3pcap ${CMAKE_INSTALL_MANDIR}/man3) 2433335640Shselasky install_manpage_symlink(pcap_open_dead.3pcap pcap_open_dead_with_tstamp_precision.3pcap ${CMAKE_INSTALL_MANDIR}/man3) 2434335640Shselasky install_manpage_symlink(pcap_open_offline.3pcap pcap_open_offline_with_tstamp_precision.3pcap ${CMAKE_INSTALL_MANDIR}/man3) 2435335640Shselasky install_manpage_symlink(pcap_open_offline.3pcap pcap_fopen_offline.3pcap ${CMAKE_INSTALL_MANDIR}/man3) 2436335640Shselasky install_manpage_symlink(pcap_open_offline.3pcap pcap_fopen_offline_with_tstamp_precision.3pcap ${CMAKE_INSTALL_MANDIR}/man3) 2437335640Shselasky install_manpage_symlink(pcap_tstamp_type_val_to_name.3pcap pcap_tstamp_type_val_to_description.3pcap ${CMAKE_INSTALL_MANDIR}/man3) 2438335640Shselasky install_manpage_symlink(pcap_setnonblock.3pcap pcap_getnonblock.3pcap ${CMAKE_INSTALL_MANDIR}/man3) 2439335640Shselasky 2440335640Shselasky set(MANFILE "") 2441335640Shselasky foreach(TEMPLATE_MANPAGE ${MANFILE_EXPAND}) 2442335640Shselasky string(REPLACE ".manfile.in" ".${MAN_FILE_FORMATS}" MANPAGE ${TEMPLATE_MANPAGE}) 2443356341Scy configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY) 2444335640Shselasky set(MANFILE ${MANFILE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE}) 2445335640Shselasky endforeach(TEMPLATE_MANPAGE) 2446335640Shselasky install(FILES ${MANFILE} DESTINATION ${CMAKE_INSTALL_MANDIR}/man${MAN_FILE_FORMATS}) 2447335640Shselasky 2448335640Shselasky set(MANMISC "") 2449335640Shselasky foreach(TEMPLATE_MANPAGE ${MANMISC_EXPAND}) 2450335640Shselasky string(REPLACE ".manmisc.in" ".${MAN_MISC_INFO}" MANPAGE ${TEMPLATE_MANPAGE}) 2451356341Scy configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY) 2452335640Shselasky set(MANMISC ${MANMISC} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE}) 2453335640Shselasky endforeach(TEMPLATE_MANPAGE) 2454335640Shselasky install(FILES ${MANMISC} DESTINATION ${CMAKE_INSTALL_MANDIR}/man${MAN_MISC_INFO}) 2455335640Shselaskyendif(NOT MSVC) 2456335640Shselasky 2457335640Shselasky# uninstall target 2458335640Shselaskyconfigure_file( 2459335640Shselasky "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" 2460335640Shselasky "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" 2461335640Shselasky IMMEDIATE @ONLY) 2462335640Shselasky 2463335640Shselaskyadd_custom_target(uninstall 2464335640Shselasky COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) 2465