xref: /netbsd-src/external/bsd/tcpdump/dist/CMakeLists.txt (revision c41df9f6167ea7cd2f761f0a97783c8267cb8847)
1d881c474Schristosif(WIN32)
2d881c474Schristos    #
3d881c474Schristos    # We need 3.12 or later, so that we can set policy CMP0074; see
4d881c474Schristos    # below.
5*c41df9f6Schristos    #
6d881c474Schristos    cmake_minimum_required(VERSION 3.12)
7d881c474Schristoselse(WIN32)
8d881c474Schristos    #
9*c41df9f6Schristos    # For now:
10d881c474Schristos    #
11*c41df9f6Schristos    #  if this is a version of CMake less than 3.5, require only
12*c41df9f6Schristos    #  2.8.12, just in case somebody is configuring with CMake
13*c41df9f6Schristos    #  on a "long-term support" version # of some OS and that
14*c41df9f6Schristos    #  version supplies an older version of CMake;
15d881c474Schristos    #
16*c41df9f6Schristos    #  otherwise, require 3.5, so we don't get messages warning
17*c41df9f6Schristos    #  that support for versions of CMake lower than 3.5 is
18*c41df9f6Schristos    #  deprecated.
19*c41df9f6Schristos    #
20*c41df9f6Schristos    if(CMAKE_VERSION VERSION_LESS "3.5")
21d881c474Schristos        cmake_minimum_required(VERSION 2.8.12)
22*c41df9f6Schristos    else()
23*c41df9f6Schristos        cmake_minimum_required(VERSION 3.5)
24*c41df9f6Schristos    endif()
25d881c474Schristosendif(WIN32)
26d881c474Schristos
27d881c474Schristos#
28d881c474Schristos# We want find_path() and find_library() to honor {packagename}_ROOT,
29d881c474Schristos# as that appears to be the standard way to say "hey, look here for
30d881c474Schristos# this package" from the command line.
31d881c474Schristos#
32d881c474Schristosif(POLICY CMP0074)
33d881c474Schristos    cmake_policy(SET CMP0074 NEW)
34d881c474Schristosendif()
35d881c474Schristos
36d881c474Schristos#
37d881c474Schristos# OK, this is a pain.
38d881c474Schristos#
39d881c474Schristos# When building on NetBSD, with a libpcap installed from pkgsrc,
40d881c474Schristos# a -Wl,-rpath,/usr/pkg/lib option is added to the options when
41d881c474Schristos# linking tcpdump.  This puts /usr/pkg/lib into the run-time path.
42d881c474Schristos#
43d881c474Schristos# However, by default, CMake adds a rule to the install CMake script
44d881c474Schristos# a CMake command (using an undocumented subcommand of file()) that
45d881c474Schristos# strips /usr/pkg/lib *out* of the run-time path; the message in the
46d881c474Schristos# output for the "install" target is
47d881c474Schristos#
48d881c474Schristos#    -- Set runtime path of "{target-directory}/tcpdump" to ""
49d881c474Schristos#
50d881c474Schristos# I am not certain what the rationale is for doing this, but a
51d881c474Schristos# *consequence* of this is that, when you run the installed tcpdump,
52d881c474Schristos# it fails to find libpcap.so:
53d881c474Schristos#
54d881c474Schristos#    $ {target-directory}/tcpdump -h
55d881c474Schristos#    {target-directory}/tcpdump: Shared object "libpcap.so.0" not found
56d881c474Schristos#
57d881c474Schristos# It also appears to be the case that, on Ubuntu 22.04, FreeBSD 12,
58d881c474Schristos# DragonFly BSD 5.8, OpenBSD 6.6, and Solaris 11.4,
59d881c474Schristos#
60d881c474Schristos# On Ubuntu and Solaris, even if you have a libpcap in /usr/local, you
61d881c474Schristos# have to provide not only -I/usr/local/include and -L/usr/local/lib,
62d881c474Schristos# you also must provide -Wl,-rpath,/usr/local/lib in order to have
63d881c474Schristos# the run-time linker look in /usr/local/lib for libpcap.  If it's not
64d881c474Schristos# specified, then, if the shared library major version number of the
65d881c474Schristos# libpcap in /usr/lib is the same as the shared major version number
66d881c474Schristos# of the libpcap in /usr/local/lib, the run-time linker will find the
67d881c474Schristos# libpcap in /usr/lib; if the versions are different, the run-time
68d881c474Schristos# linker will fail to find the libpcap in /usr/lib, so the program will
69d881c474Schristos# fail to run.
70d881c474Schristos#
71d881c474Schristos# We suppress this by setting CMAKE_INSTALL_RPATH_USE_LINK_PATH to TRUE;
72d881c474Schristos# as the documentation for that variable says:
73d881c474Schristos#
74d881c474Schristos#    Add paths to linker search and installed rpath.
75d881c474Schristos#
76d881c474Schristos#    CMAKE_INSTALL_RPATH_USE_LINK_PATH is a boolean that if set to True
77d881c474Schristos#    will append to the runtime search path (rpath) of installed
78d881c474Schristos#    binaries any directories outside the project that are in the linker
79d881c474Schristos#    search path or contain linked library files. The directories are
80d881c474Schristos#    appended after the value of the INSTALL_RPATH target property.
81d881c474Schristos#
82d881c474Schristos# If, for whatever reason, directories in which we search for external
83d881c474Schristos# libraries, other than the standard system library directories, are
84d881c474Schristos# added to the executable's rpath in the build process, we most
85*c41df9f6Schristos# definitely want them in the installed image's rpath if they are
86d881c474Schristos# necessary in order to find the libraries at run time.
87d881c474Schristos#
88d881c474Schristosset(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
89d881c474Schristos
90d881c474Schristosset(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
91d881c474Schristos
92d881c474Schristos#
93*c41df9f6Schristos# We explicitly indicate what languages are used in tcpdump to avoid
94*c41df9f6Schristos# checking for a C++ compiler.
95*c41df9f6Schristos#
96*c41df9f6Schristos# One reason to avoid that check is that there's no need to waste
97*c41df9f6Schristos# configuration time performing it.
98*c41df9f6Schristos#
99*c41df9f6Schristos# Another reason is that:
100d881c474Schristos#
101d881c474Schristos# CMake will try to determine the sizes of some data types, including
102d881c474Schristos# void *, early in the process of configuration; apparently, it's done
103d881c474Schristos# as part of processing the project() command.
104d881c474Schristos#
105d881c474Schristos# At least as of CMake 2.8.6, it does so by checking the size of
106d881c474Schristos# "void *" in C, setting CMAKE_C_SIZEOF_DATA_PTR based on that,
107d881c474Schristos# setting CMAKE_SIZEOF_VOID_P to that, and then checking the size
108d881c474Schristos# of "void *" in C++, setting CMAKE_CXX_SIZEOF_DATA_PTR based on
109d881c474Schristos# that, and then setting CMAKE_SIZEOF_VOID_P to *that*.
110d881c474Schristos#
111d881c474Schristos# The compile tests include whatever C flags may have been provided
112d881c474Schristos# to CMake in the CFLAGS and CXXFLAGS environment variables.
113d881c474Schristos#
114d881c474Schristos# If you set an architecture flag such as -m32 or -m64 in CFLAGS
115d881c474Schristos# but *not* in CXXFLAGS, the size for C++ will win, and hilarity
116d881c474Schristos# will ensue.
117d881c474Schristos#
118d881c474Schristos# Or if, at least on Solaris, you have a newer version of GCC
119d881c474Schristos# installed, but *not* a newer version of G++, and you have Oracle
120d881c474Schristos# Studio installed, it will find GCC, which will default to building
121d881c474Schristos# 64-bit, and Oracle Studio's C++ compiler, which will default to
122d881c474Schristos# building 32-bit, the size for C++ will win, and, again, hilarity
123d881c474Schristos# will ensue.
124d881c474Schristos#
125d881c474Schristosproject(tcpdump C)
126d881c474Schristos
127d881c474Schristos#
128*c41df9f6Schristos# Export the size of void * as SIZEOF_VOID_P so that it can be
129*c41df9f6Schristos# tested with #if.
130*c41df9f6Schristos#
131*c41df9f6Schristosset(SIZEOF_VOID_P "${CMAKE_SIZEOF_VOID_P}")
132*c41df9f6Schristos
133*c41df9f6Schristos#
134*c41df9f6Schristos# Show the bit width for which we're compiling.
135*c41df9f6Schristos# This can help debug problems if you're dealing with a compiler that
136*c41df9f6Schristos# defaults to generating 32-bit code even when running on a 64-bit
137*c41df9f6Schristos# platform, and where that platform may provide only 64-bit versions of
138*c41df9f6Schristos# libraries that we might use (looking at *you*, Oracle Studio!).
139*c41df9f6Schristos#
140*c41df9f6Schristosif(CMAKE_SIZEOF_VOID_P EQUAL 4)
141*c41df9f6Schristos  message(STATUS "Building 32-bit")
142*c41df9f6Schristoselseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
143*c41df9f6Schristos  message(STATUS "Building 64-bit")
144*c41df9f6Schristosendif()
145*c41df9f6Schristos
146*c41df9f6Schristos#
147*c41df9f6Schristos# Solaris pkg-config is annoying.  For at least one package (D-Bus, I'm
148*c41df9f6Schristos# looking at *you*!), there are separate include files for 32-bit and
149*c41df9f6Schristos# 64-bit builds (I guess using "unsigned long long" as a 64-bit integer
150*c41df9f6Schristos# type on a 64-bit build is like crossing the beams or something), and
151*c41df9f6Schristos# there are two separate .pc files, so if we're doing a 32-bit build we
152*c41df9f6Schristos# should make sure we look in /usr/lib/pkgconfig for .pc files and if
153*c41df9f6Schristos# we're doing a 64-bit build we should make sure we look in
154*c41df9f6Schristos# /usr/lib/amd64/pkgconfig for .pc files.
155*c41df9f6Schristos#
156*c41df9f6Schristosif(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_VERSION MATCHES "5[.][0-9.]*")
157*c41df9f6Schristos    #
158*c41df9f6Schristos    # Note: string(REPLACE) does not appear to support using ENV{...}
159*c41df9f6Schristos    # as an argument, so we set a variable and then use set() to set
160*c41df9f6Schristos    # the environment variable.
161*c41df9f6Schristos    #
162*c41df9f6Schristos    if(CMAKE_SIZEOF_VOID_P EQUAL 8)
163*c41df9f6Schristos        #
164*c41df9f6Schristos        # 64-bit build.  If /usr/lib/pkgconfig appears in the path,
165*c41df9f6Schristos        # prepend /usr/lib/amd64/pkgconfig to it; otherwise,
166*c41df9f6Schristos        # put /usr/lib/amd64 at the end.
167*c41df9f6Schristos        #
168*c41df9f6Schristos        if((NOT DEFINED ENV{PKG_CONFIG_PATH}) OR "$ENV{PKG_CONFIG_PATH}" EQUAL "")
169*c41df9f6Schristos            #
170*c41df9f6Schristos            # Not set, or empty.  Set it to /usr/lib/amd64/pkgconfig.
171*c41df9f6Schristos            #
172*c41df9f6Schristos            set(fixed_path "/usr/lib/amd64/pkgconfig")
173*c41df9f6Schristos        elseif("$ENV{PKG_CONFIG_PATH}" MATCHES "/usr/lib/pkgconfig")
174*c41df9f6Schristos            #
175*c41df9f6Schristos            # It contains /usr/lib/pkgconfig.  Prepend
176*c41df9f6Schristos            # /usr/lib/amd64/pkgconfig to /usr/lib/pkgconfig.
177*c41df9f6Schristos            #
178*c41df9f6Schristos            string(REPLACE "/usr/lib/pkgconfig"
179*c41df9f6Schristos                "/usr/lib/amd64/pkgconfig:/usr/lib/pkgconfig"
180*c41df9f6Schristos                fixed_path "$ENV{PKG_CONFIG_PATH}")
181*c41df9f6Schristos        else()
182*c41df9f6Schristos            #
183*c41df9f6Schristos            # Not empty, but doesn't contain /usr/lib/pkgconfig.
184*c41df9f6Schristos            # Append /usr/lib/amd64/pkgconfig to it.
185*c41df9f6Schristos            #
186*c41df9f6Schristos            set(fixed_path "$ENV{PKG_CONFIG_PATH}:/usr/lib/amd64/pkgconfig")
187*c41df9f6Schristos        endif()
188*c41df9f6Schristos        set(ENV{PKG_CONFIG_PATH} "${fixed_path}")
189*c41df9f6Schristos    elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
190*c41df9f6Schristos        #
191*c41df9f6Schristos        # 32-bit build.  If /usr/amd64/lib/pkgconfig appears in the path,
192*c41df9f6Schristos        # prepend /usr/lib/pkgconfig to it.
193*c41df9f6Schristos        #
194*c41df9f6Schristos        if("$ENV{PKG_CONFIG_PATH}" MATCHES "/usr/lib/amd64/pkgconfig")
195*c41df9f6Schristos            #
196*c41df9f6Schristos            # It contains /usr/lib/amd64/pkgconfig.  Prepend
197*c41df9f6Schristos            # /usr/lib/pkgconfig to /usr/lib/amd64/pkgconfig.
198*c41df9f6Schristos            #
199*c41df9f6Schristos            string(REPLACE "/usr/lib/amd64/pkgconfig"
200*c41df9f6Schristos                "/usr/lib/pkgconfig:/usr/lib/amd64/pkgconfig"
201*c41df9f6Schristos                fixed_path "$ENV{PKG_CONFIG_PATH}")
202*c41df9f6Schristos            set(ENV{PKG_CONFIG_PATH} "${fixed_path}")
203*c41df9f6Schristos        endif()
204*c41df9f6Schristos    endif()
205*c41df9f6Schristosendif()
206*c41df9f6Schristos
207*c41df9f6Schristos#
208d881c474Schristos# For checking if a compiler flag works and adding it if it does.
209d881c474Schristos#
210d881c474Schristosinclude(CheckCCompilerFlag)
211d881c474Schristosmacro(check_and_add_compiler_option _option)
212d881c474Schristos    message(STATUS "Checking C compiler flag ${_option}")
213d881c474Schristos    string(REPLACE "=" "-" _temp_option_variable ${_option})
214d881c474Schristos    string(REGEX REPLACE "^-" "" _option_variable ${_temp_option_variable})
215d881c474Schristos    check_c_compiler_flag("${_option}" ${_option_variable})
216d881c474Schristos    if(${${_option_variable}})
217d881c474Schristos        set(C_ADDITIONAL_FLAGS "${C_ADDITIONAL_FLAGS} ${_option}")
218d881c474Schristos    endif()
219d881c474Schristosendmacro()
220d881c474Schristos
221d881c474Schristos#
222d881c474Schristos# If we're building with Visual Studio, we require Visual Studio 2015,
223d881c474Schristos# in order to get sufficient C99 compatibility.  Check for that.
224d881c474Schristos#
225d881c474Schristos# If not, try the appropriate flag for the compiler to enable C99
226d881c474Schristos# features.
227d881c474Schristos#
228d881c474Schristosset(C_ADDITIONAL_FLAGS "")
229d881c474Schristosif(MSVC)
230d881c474Schristos    if(MSVC_VERSION LESS 1900)
231d881c474Schristos        message(FATAL_ERROR "Visual Studio 2015 or later is required")
232d881c474Schristos    endif()
233d881c474Schristos
234d881c474Schristos    #
235d881c474Schristos    # Treat source files as being in UTF-8 with MSVC if it's not using
236d881c474Schristos    # the Clang front end.
237d881c474Schristos    # We assume that UTF-8 source is OK with other compilers and with
238d881c474Schristos    # MSVC if it's using the Clang front end.
239d881c474Schristos    #
240d881c474Schristos    if(NOT ${CMAKE_C_COMPILER} MATCHES "clang*")
241d881c474Schristos        set(C_ADDITIONAL_FLAGS "${C_ADDITIONAL_FLAGS} /utf-8")
242d881c474Schristos    endif(NOT ${CMAKE_C_COMPILER} MATCHES "clang*")
243d881c474Schristoselse(MSVC)
244d881c474Schristos    #
245d881c474Schristos    # Try to enable as many C99 features as we can.
246d881c474Schristos    # At minimum, we want C++/C99-style // comments.
247d881c474Schristos    #
248d881c474Schristos    # Newer versions of compilers might default to supporting C99, but
249d881c474Schristos    # older versions may require a special flag.
250d881c474Schristos    #
251d881c474Schristos    # Prior to CMake 3.1, setting CMAKE_C_STANDARD will not have any effect,
252d881c474Schristos    # so, unless and until we require CMake 3.1 or later, we have to do it
253d881c474Schristos    # ourselves on pre-3.1 CMake, so we just do it ourselves on all versions
254d881c474Schristos    # of CMake.
255d881c474Schristos    #
256d881c474Schristos    # Note: with CMake 3.1 through 3.5, the only compilers for which CMake
257d881c474Schristos    # handles CMAKE_C_STANDARD are GCC and Clang.  3.6 adds support only
258d881c474Schristos    # for Intel C; 3.9 adds support for PGI C, Sun C, and IBM XL C, and
259d881c474Schristos    # 3.10 adds support for Cray C and IAR C, but no version of CMake has
260d881c474Schristos    # support for HP C.  Therefore, even if we use CMAKE_C_STANDARD with
261d881c474Schristos    # compilers for which CMake supports it, we may still have to do it
262d881c474Schristos    # ourselves on other compilers.
263d881c474Schristos    #
264d881c474Schristos    # See the CMake documentation for the CMAKE_<LANG>_COMPILER_ID variables
265d881c474Schristos    # for a list of compiler IDs.
266d881c474Schristos    #
267d881c474Schristos    # XXX - this just tests whether the option works and adds it if it does.
268d881c474Schristos    # We don't test whether it's necessary in order to get the C99 features
269d881c474Schristos    # that we use; if we ever have a user who tries to compile with a compiler
270d881c474Schristos    # that can't be made to support those features, we can add a test to make
271d881c474Schristos    # sure we actually *have* C99 support.
272d881c474Schristos    #
273d881c474Schristos    if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR
274d881c474Schristos       CMAKE_C_COMPILER_ID MATCHES "Clang")
275d881c474Schristos        check_and_add_compiler_option("-std=gnu99")
276d881c474Schristos    elseif(CMAKE_C_COMPILER_ID MATCHES "XL")
277d881c474Schristos        #
278d881c474Schristos        # We want support for extensions picked up for GNU C compatibility,
279d881c474Schristos        # so we use -qlanglvl=extc99.
280d881c474Schristos        #
281d881c474Schristos        check_and_add_compiler_option("-qlanglvl=extc99")
282d881c474Schristos    elseif(CMAKE_C_COMPILER_ID MATCHES "HP")
283d881c474Schristos        check_and_add_compiler_option("-AC99")
284d881c474Schristos    elseif(CMAKE_C_COMPILER_ID MATCHES "Sun")
285d881c474Schristos        check_and_add_compiler_option("-xc99")
286d881c474Schristos    elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
287d881c474Schristos        check_and_add_compiler_option("-c99")
288d881c474Schristos    endif()
289d881c474Schristosendif(MSVC)
290d881c474Schristos
291d881c474Schristosset(LIBRARY_NAME netdissect)
292d881c474Schristos
293d881c474Schristos###################################################################
294d881c474Schristos#   Parameters
295d881c474Schristos###################################################################
296d881c474Schristos
297d881c474Schristosoption(WITH_SMI "Build with libsmi, if available" ON)
298d881c474Schristosoption(WITH_CRYPTO "Build with OpenSSL/libressl libcrypto, if available" ON)
299d881c474Schristosoption(WITH_CAPSICUM "Build with Capsicum security functions, if available" ON)
300d881c474Schristosoption(WITH_CAP_NG "Use libcap-ng, if available" ON)
301d881c474Schristosoption(ENABLE_SMB "Build with the SMB dissector" OFF)
302d881c474Schristos
303d881c474Schristos#
304d881c474Schristos# String parameters.  Neither of them are set, initially; only if the
305d881c474Schristos# user explicitly configures them are they set.
306d881c474Schristos#
307d881c474Schristos# WITH_CHROOT is STRING, not PATH, as the directory need not exist
308d881c474Schristos# when CMake is run.
309d881c474Schristos#
310d881c474Schristosset(WITH_CHROOT CACHE STRING
311d881c474Schristos    "Directory to which to chroot when dropping privileges")
312d881c474Schristosset(WITH_USER CACHE STRING
313d881c474Schristos    "User to whom to set the UID when dropping privileges")
314d881c474Schristos
315d881c474Schristos#
316d881c474Schristos# By default, build universal with the appropriate set of architectures
317d881c474Schristos# for the OS on which we're doing the build.
318d881c474Schristos#
319d881c474Schristosif(APPLE AND "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "")
320d881c474Schristos    #
321d881c474Schristos    # Get the major version of Darwin.
322d881c474Schristos    #
323d881c474Schristos    string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MAJOR "${CMAKE_SYSTEM_VERSION}")
324d881c474Schristos
325d881c474Schristos    if(SYSTEM_VERSION_MAJOR EQUAL 9)
326d881c474Schristos        #
327d881c474Schristos        # Leopard.  Build for x86 and 32-bit PowerPC, with
328d881c474Schristos        # x86 first.  (That's what Apple does.)
329d881c474Schristos        #
330d881c474Schristos        set(CMAKE_OSX_ARCHITECTURES "i386;ppc")
331d881c474Schristos    elseif(SYSTEM_VERSION_MAJOR EQUAL 10)
332d881c474Schristos        #
333d881c474Schristos        # Snow Leopard.  Build for x86-64 and x86, with
334d881c474Schristos        # x86-64 first.  (That's what Apple does.)
335d881c474Schristos        #
336d881c474Schristos        set(CMAKE_OSX_ARCHITECTURES "x86_64;i386")
337d881c474Schristos    endif()
338d881c474Schristosendif()
339d881c474Schristos
340d881c474Schristos###################################################################
341d881c474Schristos#   Versioning
342d881c474Schristos###################################################################
343d881c474Schristos
344d881c474Schristos# Get, parse, format and set tcpdump's version string from
345d881c474Schristos# [tcpdump_root]/VERSION for later use.
346d881c474Schristos
347d881c474Schristos# Get MAJOR, MINOR, PATCH & SUFFIX
348d881c474Schristosfile(STRINGS ${tcpdump_SOURCE_DIR}/VERSION
349d881c474Schristos    PACKAGE_VERSION
350d881c474Schristos    LIMIT_COUNT 1 # Read only the first line
351d881c474Schristos)
352d881c474Schristos
353d881c474Schristos######################################
354d881c474Schristos# Project settings
355d881c474Schristos######################################
356d881c474Schristos
357d881c474Schristosinclude_directories(
358d881c474Schristos    ${CMAKE_CURRENT_BINARY_DIR}
359d881c474Schristos    ${tcpdump_SOURCE_DIR}
360d881c474Schristos)
361d881c474Schristos
362d881c474Schristosif(MSVC)
363d881c474Schristos    add_definitions(-D__STDC__)
364d881c474Schristos    add_definitions(-D_CRT_SECURE_NO_WARNINGS)
365d881c474Schristosendif(MSVC)
366d881c474Schristos
367d881c474Schristosif(MSVC)
368d881c474Schristos    if (USE_STATIC_RT)
369d881c474Schristos        MESSAGE(STATUS "Use STATIC runtime")
370d881c474Schristos        set(NAME_RT MT)
371d881c474Schristos        set (CMAKE_CXX_FLAGS_MINSIZEREL     "${CMAKE_CXX_FLAGS_MINSIZEREL} /MT")
372d881c474Schristos        set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MT")
373d881c474Schristos        set (CMAKE_CXX_FLAGS_RELEASE        "${CMAKE_CXX_FLAGS_RELEASE} /MT")
374d881c474Schristos        set (CMAKE_CXX_FLAGS_DEBUG          "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
375d881c474Schristos
376d881c474Schristos        set (CMAKE_C_FLAGS_MINSIZEREL       "${CMAKE_C_FLAGS_MINSIZEREL} /MT")
377d881c474Schristos        set (CMAKE_C_FLAGS_RELWITHDEBINFO   "${CMAKE_C_FLAGS_RELWITHDEBINFO} /MT")
378d881c474Schristos        set (CMAKE_C_FLAGS_RELEASE          "${CMAKE_C_FLAGS_RELEASE} /MT")
379d881c474Schristos        set (CMAKE_C_FLAGS_DEBUG            "${CMAKE_C_FLAGS_DEBUG} /MTd")
380d881c474Schristos    else (USE_STATIC_RT)
381d881c474Schristos        MESSAGE(STATUS "Use DYNAMIC runtime")
382d881c474Schristos        set(NAME_RT MD)
383d881c474Schristos        set (CMAKE_CXX_FLAGS_MINSIZEREL     "${CMAKE_CXX_FLAGS_MINSIZEREL} /MD")
384d881c474Schristos        set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MD")
385d881c474Schristos        set (CMAKE_CXX_FLAGS_RELEASE        "${CMAKE_CXX_FLAGS_RELEASE} /MD")
386d881c474Schristos        set (CMAKE_CXX_FLAGS_DEBUG          "${CMAKE_CXX_FLAGS_DEBUG} /MDd")
387d881c474Schristos
388d881c474Schristos        set (CMAKE_C_FLAGS_MINSIZEREL       "${CMAKE_C_FLAGS_MINSIZEREL} /MD")
389d881c474Schristos        set (CMAKE_C_FLAGS_RELWITHDEBINFO   "${CMAKE_C_FLAGS_RELWITHDEBINFO} /MD")
390d881c474Schristos        set (CMAKE_C_FLAGS_RELEASE          "${CMAKE_C_FLAGS_RELEASE} /MD")
391d881c474Schristos        set (CMAKE_C_FLAGS_DEBUG            "${CMAKE_C_FLAGS_DEBUG} /MDd")
392d881c474Schristos   endif (USE_STATIC_RT)
393d881c474Schristosendif(MSVC)
394d881c474Schristos
395d881c474Schristos###################################################################
396d881c474Schristos#   Detect available platform features
397d881c474Schristos###################################################################
398d881c474Schristos
399d881c474Schristosinclude(CMakePushCheckState)
400d881c474Schristosinclude(CheckIncludeFile)
401d881c474Schristosinclude(CheckIncludeFiles)
402d881c474Schristosinclude(CheckFunctionExists)
403d881c474Schristosinclude(CheckLibraryExists)
404d881c474Schristosinclude(CheckSymbolExists)
405d881c474Schristosinclude(CheckStructHasMember)
406d881c474Schristosinclude(CheckVariableExists)
407d881c474Schristosinclude(CheckTypeSize)
408d881c474Schristos
409d881c474Schristos#
410*c41df9f6Schristos# Get the size of a time_t, to know whether it's 32-bit or 64-bit.
411*c41df9f6Schristos#
412*c41df9f6Schristoscmake_push_check_state()
413*c41df9f6Schristosset(CMAKE_EXTRA_INCLUDE_FILES time.h)
414*c41df9f6Schristoscheck_type_size("time_t" SIZEOF_TIME_T)
415*c41df9f6Schristoscmake_pop_check_state()
416*c41df9f6Schristos
417*c41df9f6Schristos#
418d881c474Schristos# Header files.
419d881c474Schristos#
420d881c474Schristoscheck_include_file(rpc/rpc.h HAVE_RPC_RPC_H)
421d881c474Schristoscheck_include_file(net/if.h HAVE_NET_IF_H)
422d881c474Schristosif(HAVE_RPC_RPC_H)
423d881c474Schristos    check_include_files("rpc/rpc.h;rpc/rpcent.h" HAVE_RPC_RPCENT_H)
424d881c474Schristosendif(HAVE_RPC_RPC_H)
425d881c474Schristos
426d881c474Schristos#
427d881c474Schristos# Functions.
428d881c474Schristos#
429d881c474Schristoscheck_function_exists(strlcat HAVE_STRLCAT)
430d881c474Schristoscheck_function_exists(strlcpy HAVE_STRLCPY)
431d881c474Schristoscheck_function_exists(strdup HAVE_STRDUP)
432d881c474Schristoscheck_function_exists(strsep HAVE_STRSEP)
433d881c474Schristos
434d881c474Schristos#
435d881c474Schristos# Find library needed for gethostbyaddr.
436d881c474Schristos# NOTE: if you hand check_library_exists as its last argument a variable
437d881c474Schristos# that's been set, it skips the test, so we need different variables.
438d881c474Schristos#
439d881c474Schristosset(TCPDUMP_LINK_LIBRARIES "")
440d881c474Schristosif(WIN32)
441d881c474Schristos    #
442d881c474Schristos    # We need winsock2.h and ws2tcpip.h.
443d881c474Schristos    #
444d881c474Schristos    cmake_push_check_state()
445d881c474Schristos    set(CMAKE_REQUIRED_LIBRARIES ws2_32)
446d881c474Schristos    check_symbol_exists(gethostbyaddr "winsock2.h;ws2tcpip.h" LIBWS2_32_HAS_GETHOSTBYADDR)
447d881c474Schristos    cmake_pop_check_state()
448d881c474Schristos    if(LIBWS2_32_HAS_GETHOSTBYADDR)
449d881c474Schristos        set(TCPDUMP_LINK_LIBRARIES ws2_32 ${TCPDUMP_LINK_LIBRARIES})
450d881c474Schristos    else(LIBWS2_32_HAS_GETHOSTBYADDR)
451d881c474Schristos        message(FATAL_ERROR "gethostbyaddr is required, but wasn't found")
452d881c474Schristos    endif(LIBWS2_32_HAS_GETHOSTBYADDR)
453d881c474Schristoselse(WIN32)
454d881c474Schristos    check_function_exists(gethostbyaddr STDLIBS_HAVE_GETHOSTBYADDR)
455d881c474Schristos    if(NOT STDLIBS_HAVE_GETHOSTBYADDR)
456d881c474Schristos        check_library_exists(socket gethostbyaddr "" LIBSOCKET_HAS_GETHOSTBYADDR)
457d881c474Schristos        if(LIBSOCKET_HAS_GETHOSTBYADDR)
458d881c474Schristos            set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} socket)
459d881c474Schristos        else(LIBSOCKET_HAS_GETHOSTBYADDR)
460d881c474Schristos            check_library_exists(nsl gethostbyaddr "" LIBNSL_HAS_GETHOSTBYADDR)
461d881c474Schristos            if(LIBNSL_HAS_GETHOSTBYADDR)
462d881c474Schristos                set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} nsl)
463d881c474Schristos            else(LIBNSL_HAS_GETHOSTBYADDR)
464*c41df9f6Schristos                check_library_exists(network gethostbyaddr "" LIBNETWORK_HAS_GETHOSTBYADDR)
465*c41df9f6Schristos                if(LIBNETWORK_HAS_GETHOSTBYADDR)
466*c41df9f6Schristos                    set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} network)
467*c41df9f6Schristos                else(LIBNETWORK_HAS_GETHOSTBYADDR)
468d881c474Schristos                    message(FATAL_ERROR "gethostbyaddr is required, but wasn't found")
469*c41df9f6Schristos                endif(LIBNETWORK_HAS_GETHOSTBYADDR)
470d881c474Schristos            endif(LIBNSL_HAS_GETHOSTBYADDR)
471d881c474Schristos        endif(LIBSOCKET_HAS_GETHOSTBYADDR)
472d881c474Schristos    endif(NOT STDLIBS_HAVE_GETHOSTBYADDR)
473d881c474Schristosendif(WIN32)
474d881c474Schristos
475d881c474Schristos#
476d881c474Schristos# This may require additional libraries.
477d881c474Schristos#
478d881c474Schristoscmake_push_check_state()
479d881c474Schristosset(CMAKE_REQUIRED_LIBRARIES ${TCPDUMP_LINK_LIBRARIES})
480d881c474Schristoscheck_function_exists(getservent STDLIBS_HAVE_GETSERVENT)
481d881c474Schristosif(STDLIBS_HAVE_GETSERVENT)
482d881c474Schristos    set(HAVE_GETSERVENT TRUE)
483d881c474Schristoselse(STDLIBS_HAVE_GETSERVENT)
484d881c474Schristos    #
485d881c474Schristos    # Some platforms may need -lsocket for getservent.
486d881c474Schristos    #
487d881c474Schristos    set(CMAKE_REQUIRED_LIBRARIES socket ${TCPDUMP_LINK_LIBRARIES})
488d881c474Schristos    check_function_exists(getservent LIBSOCKET_HAS_GETSERVENT)
489d881c474Schristos    if(LIBSOCKET_HAS_GETSERVENT)
490d881c474Schristos        set(HAVE_GETSERVENT TRUE)
491d881c474Schristos        set(TCPDUMP_LINK_LIBRARIES socket ${TCPDUMP_LINK_LIBRARIES})
492d881c474Schristos    endif(LIBSOCKET_HAS_GETSERVENT)
493d881c474Schristosendif(STDLIBS_HAVE_GETSERVENT)
494d881c474Schristoscmake_pop_check_state()
495d881c474Schristos
496d881c474Schristos#
497*c41df9f6Schristos# Make sure we have snprintf(); we require it.
498*c41df9f6Schristos# We use check_symbol_exists(), as it isn't necessarily an external
499*c41df9f6Schristos# function - in Visual Studio, for example, it is an inline function
500*c41df9f6Schristos# calling an external function.
501d881c474Schristos#
502d881c474Schristoscheck_symbol_exists(snprintf "stdio.h" HAVE_SNPRINTF)
503d881c474Schristosif(NOT HAVE_SNPRINTF)
504d881c474Schristos    message(FATAL_ERROR "snprintf() is required but wasn't found")
505d881c474Schristosendif()
506d881c474Schristos
507*c41df9f6Schristos#
508*c41df9f6Schristos# Require a proof of suitable snprintf(3), same as in Autoconf.
509*c41df9f6Schristos#
510*c41df9f6Schristosinclude(CheckCSourceRuns)
511*c41df9f6Schristoscheck_c_source_runs("
512*c41df9f6Schristos#include <stdio.h>
513*c41df9f6Schristos#include <string.h>
514*c41df9f6Schristos#include <inttypes.h>
515*c41df9f6Schristos#include <sys/types.h>
516*c41df9f6Schristos
517*c41df9f6Schristosint main()
518*c41df9f6Schristos{
519*c41df9f6Schristos  char buf[100];
520*c41df9f6Schristos  uint64_t t = (uint64_t)1 << 32;
521*c41df9f6Schristos
522*c41df9f6Schristos  snprintf(buf, sizeof(buf), \"%zu\", sizeof(buf));
523*c41df9f6Schristos  if (strncmp(buf, \"100\", sizeof(buf)))
524*c41df9f6Schristos    return 1;
525*c41df9f6Schristos
526*c41df9f6Schristos  snprintf(buf, sizeof(buf), \"%zd\", -sizeof(buf));
527*c41df9f6Schristos  if (strncmp(buf, \"-100\", sizeof(buf)))
528*c41df9f6Schristos    return 2;
529*c41df9f6Schristos
530*c41df9f6Schristos  snprintf(buf, sizeof(buf), \"%\" PRId64, -t);
531*c41df9f6Schristos  if (strncmp(buf, \"-4294967296\", sizeof(buf)))
532*c41df9f6Schristos    return 3;
533*c41df9f6Schristos
534*c41df9f6Schristos  snprintf(buf, sizeof(buf), \"0o%\" PRIo64, t);
535*c41df9f6Schristos  if (strncmp(buf, \"0o40000000000\", sizeof(buf)))
536*c41df9f6Schristos    return 4;
537*c41df9f6Schristos
538*c41df9f6Schristos  snprintf(buf, sizeof(buf), \"0x%\" PRIx64, t);
539*c41df9f6Schristos  if (strncmp(buf, \"0x100000000\", sizeof(buf)))
540*c41df9f6Schristos    return 5;
541*c41df9f6Schristos
542*c41df9f6Schristos  snprintf(buf, sizeof(buf), \"%\" PRIu64, t);
543*c41df9f6Schristos  if (strncmp(buf, \"4294967296\", sizeof(buf)))
544*c41df9f6Schristos    return 6;
545*c41df9f6Schristos
546*c41df9f6Schristos  return 0;
547*c41df9f6Schristos}
548*c41df9f6Schristos
549*c41df9f6Schristos"
550*c41df9f6Schristos    SUITABLE_SNPRINTF
551*c41df9f6Schristos)
552*c41df9f6Schristosif(NOT SUITABLE_SNPRINTF)
553*c41df9f6Schristos    message(FATAL_ERROR
554*c41df9f6Schristos"The snprintf(3) implementation in this libc is not suitable,
555*c41df9f6Schristostcpdump would not work correctly even if it managed to compile."
556*c41df9f6Schristos    )
557*c41df9f6Schristosendif()
558*c41df9f6Schristos
559d881c474Schristoscheck_function_exists(getopt_long HAVE_GETOPT_LONG)
560d881c474Schristoscheck_function_exists(setlinebuf HAVE_SETLINEBUF)
561d881c474Schristos#
562d881c474Schristos# For Windows,  don't need to waste time checking for fork() or vfork().
563d881c474Schristos#
564d881c474Schristosif(NOT WIN32)
565d881c474Schristos    check_function_exists(fork HAVE_FORK)
566d881c474Schristos    check_function_exists(vfork HAVE_VFORK)
567d881c474Schristosendif(NOT WIN32)
568d881c474Schristos
569d881c474Schristos#
570d881c474Schristos# Some platforms may need -lnsl for getrpcbynumber.
571d881c474Schristos#
572d881c474Schristoscmake_push_check_state()
573d881c474Schristosset(CMAKE_REQUIRED_LIBRARIES ${TCPDUMP_LINK_LIBRARIES})
574d881c474Schristoscheck_function_exists(getrpcbynumber STDLIBS_HAVE_GETRPCBYNUMBER)
575d881c474Schristosif(STDLIBS_HAVE_GETRPCBYNUMBER)
576d881c474Schristos    set(HAVE_GETRPCBYNUMBER TRUE)
577d881c474Schristoselse(STDLIBS_HAVE_GETRPCBYNUMBER)
578d881c474Schristos    set(CMAKE_REQUIRED_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} nsl)
579d881c474Schristos    check_function_exists(getrpcbynumber LIBNSL_HAS_GETRPCBYNUMBER)
580d881c474Schristos    if(LIBNSL_HAS_GETRPCBYNUMBER)
581d881c474Schristos        set(HAVE_GETRPCBYNUMBER TRUE)
582d881c474Schristos        set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} nsl)
583d881c474Schristos    endif(LIBNSL_HAS_GETRPCBYNUMBER)
584d881c474Schristosendif(STDLIBS_HAVE_GETRPCBYNUMBER)
585d881c474Schristoscmake_pop_check_state()
586d881c474Schristos
587d881c474Schristos#
588d881c474Schristos# This requires the libraries we require, as ether_ntohost might be
589d881c474Schristos# in one of those libraries.  That means we have to do this after
590d881c474Schristos# we check for those libraries.
591d881c474Schristos#
592d881c474Schristos# You are in a twisty little maze of UN*Xes, all different.
593d881c474Schristos# Some might not have ether_ntohost().
594d881c474Schristos# Some might have it and declare it in <net/ethernet.h>.
595d881c474Schristos# Some might have it and declare it in <netinet/ether.h>
596d881c474Schristos# Some might have it and declare it in <sys/ethernet.h>.
597d881c474Schristos# Some might have it and declare it in <arpa/inet.h>.
598d881c474Schristos# Some might have it and declare it in <netinet/if_ether.h>.
599d881c474Schristos# Some might have it and not declare it in any header file.
600d881c474Schristos#
601d881c474Schristos# Before you is a C compiler.
602d881c474Schristos#
603d881c474Schristoscmake_push_check_state()
604d881c474Schristosset(CMAKE_REQUIRED_LIBRARIES ${TCPDUMP_LINK_LIBRARIES})
605d881c474Schristoscheck_function_exists(ether_ntohost HAVE_ETHER_NTOHOST)
606d881c474Schristosif(HAVE_ETHER_NTOHOST)
607d881c474Schristos    #
608d881c474Schristos    # OK, we have ether_ntohost().  We don't check whether it's buggy,
609d881c474Schristos    # as we assume any system that has CMake is likely to be new enough
610d881c474Schristos    # that, if it has ether_ntohost(), whatever bug is checked for in
611d881c474Schristos    # autotools is fixed; we just decide to use it.
612d881c474Schristos    #
613d881c474Schristos    set(USE_ETHER_NTOHOST TRUE)
614d881c474Schristos
615d881c474Schristos    #
616d881c474Schristos    # Is it declared in <net/ethernet.h>?
617d881c474Schristos    #
618d881c474Schristos    # This test fails if we don't have <net/ethernet.h> or if we do
619d881c474Schristos    # but it doesn't declare ether_ntohost().
620d881c474Schristos    #
621d881c474Schristos    check_symbol_exists(ether_ntohost net/ethernet.h NET_ETHERNET_H_DECLARES_ETHER_NTOHOST)
622d881c474Schristos    if(NET_ETHERNET_H_DECLARES_ETHER_NTOHOST)
623d881c474Schristos        #
624d881c474Schristos        # Yes - we have it declared.
625d881c474Schristos        #
626d881c474Schristos        set(HAVE_DECL_ETHER_NTOHOST TRUE)
627d881c474Schristos    endif()
628d881c474Schristos    #
629d881c474Schristos    # Did that succeed?
630d881c474Schristos    #
631d881c474Schristos    if(NOT HAVE_DECL_ETHER_NTOHOST)
632d881c474Schristos        #
633d881c474Schristos        # No - how about <netinet/ether.h>, as on Linux?
634d881c474Schristos        #
635d881c474Schristos        # This test fails if we don't have <netinet/ether.h>
636d881c474Schristos        # or if we do but it doesn't declare ether_ntohost().
637d881c474Schristos        #
638d881c474Schristos        check_symbol_exists(ether_ntohost netinet/ether.h NETINET_ETHER_H_DECLARES_ETHER_NTOHOST)
639d881c474Schristos        if(NETINET_ETHER_H_DECLARES_ETHER_NTOHOST)
640d881c474Schristos            #
641d881c474Schristos            # Yes - we have it declared.
642d881c474Schristos            #
643d881c474Schristos            set(HAVE_DECL_ETHER_NTOHOST TRUE)
644d881c474Schristos        endif()
645d881c474Schristos    endif()
646d881c474Schristos    #
647d881c474Schristos    # Did that succeed?
648d881c474Schristos    #
649d881c474Schristos    if(NOT HAVE_DECL_ETHER_NTOHOST)
650d881c474Schristos        #
651d881c474Schristos        # No - how about <sys/ethernet.h>, as on Solaris 10 and later?
652d881c474Schristos        #
653d881c474Schristos        # This test fails if we don't have <sys/ethernet.h>
654d881c474Schristos        # or if we do but it doesn't declare ether_ntohost().
655d881c474Schristos        #
656d881c474Schristos        check_symbol_exists(ether_ntohost sys/ethernet.h SYS_ETHERNET_H_DECLARES_ETHER_NTOHOST)
657d881c474Schristos        if(SYS_ETHERNET_H_DECLARES_ETHER_NTOHOST)
658d881c474Schristos            #
659d881c474Schristos            # Yes - we have it declared.
660d881c474Schristos            #
661d881c474Schristos            set(HAVE_DECL_ETHER_NTOHOST TRUE)
662d881c474Schristos        endif()
663d881c474Schristos    endif()
664d881c474Schristos    #
665d881c474Schristos    # Did that succeed?
666d881c474Schristos    #
667d881c474Schristos    if(NOT HAVE_DECL_ETHER_NTOHOST)
668d881c474Schristos        #
669d881c474Schristos        # No, how about <arpa/inet.h>, as on AIX?
670d881c474Schristos        #
671d881c474Schristos        # This test fails if we don't have <arpa/inet.h>
672d881c474Schristos        # or if we do but it doesn't declare ether_ntohost().
673d881c474Schristos        #
674d881c474Schristos        check_symbol_exists(ether_ntohost arpa/inet.h ARPA_INET_H_DECLARES_ETHER_NTOHOST)
675d881c474Schristos        if(ARPA_INET_H_DECLARES_ETHER_NTOHOST)
676d881c474Schristos            #
677d881c474Schristos            # Yes - we have it declared.
678d881c474Schristos            #
679d881c474Schristos            set(HAVE_DECL_ETHER_NTOHOST TRUE)
680d881c474Schristos        endif()
681d881c474Schristos    endif()
682d881c474Schristos    #
683d881c474Schristos    # Did that succeed?
684d881c474Schristos    #
685d881c474Schristos    if(NOT HAVE_DECL_ETHER_NTOHOST)
686d881c474Schristos        #
687d881c474Schristos        # No, how about <netinet/if_ether.h>?
688d881c474Schristos        # On some platforms, it requires <net/if.h> and
689d881c474Schristos        # <netinet/in.h>, and we always include it with
690d881c474Schristos        # both of them, so test it with both of them.
691d881c474Schristos        #
692d881c474Schristos        # This test fails if we don't have <netinet/if_ether.h>
693d881c474Schristos        # and the headers we include before it, or if we do but
694d881c474Schristos        # <netinet/if_ether.h> doesn't declare ether_ntohost().
695d881c474Schristos        #
696d881c474Schristos        check_symbol_exists(ether_ntohost "sys/types.h;sys/socket.h;net/if.h;netinet/in.h;netinet/if_ether.h" NETINET_IF_ETHER_H_DECLARES_ETHER_NTOHOST)
697d881c474Schristos        if(NETINET_IF_ETHER_H_DECLARES_ETHER_NTOHOST)
698d881c474Schristos            #
699d881c474Schristos            # Yes - we have it declared.
700d881c474Schristos            #
701d881c474Schristos            set(HAVE_DECL_ETHER_NTOHOST TRUE)
702d881c474Schristos        endif()
703d881c474Schristos    endif()
704d881c474Schristos    #
705d881c474Schristos    # After all that, is ether_ntohost() declared?
706d881c474Schristos    #
707d881c474Schristos    if(NOT HAVE_DECL_ETHER_NTOHOST)
708d881c474Schristos        #
709d881c474Schristos        # No, we'll have to declare it ourselves.
710d881c474Schristos        # Do we have "struct ether_addr" if we include<netinet/if_ether.h>?
711d881c474Schristos        #
712d881c474Schristos        check_struct_has_member("struct ether_addr" octet "sys/types.h;sys/socket.h;net/if.h;netinet/in.h;netinet/if_ether.h" HAVE_STRUCT_ETHER_ADDR)
713d881c474Schristos    endif()
714d881c474Schristosendif()
715d881c474Schristoscmake_pop_check_state()
716d881c474Schristos
717d881c474Schristos#
718d881c474Schristos# Data types.
719d881c474Schristos#
720d881c474Schristos# XXX - there's no check_struct() macro that's like check_struct_has_member()
721d881c474Schristos# except that it only checks for the existence of the structure type,
722d881c474Schristos# so we use check_struct_has_member() and look for ss_family.
723d881c474Schristos#
724d881c474Schristos
725d881c474Schristos#
726d881c474Schristos# Check for IPv6 support.
727d881c474Schristos# We just check for AF_INET6 and struct in6_addr.
728d881c474Schristos#
729d881c474Schristoscmake_push_check_state()
730d881c474Schristosif(WIN32)
731d881c474Schristos    set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h ws2tcpip.h)
732d881c474Schristos    check_symbol_exists(AF_INET6 "sys/types.h;ws2tcpip.h" HAVE_AF_INET6)
733d881c474Schristoselse(WIN32)
734d881c474Schristos    set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h sys/socket.h netinet/in.h)
735d881c474Schristos    check_symbol_exists(AF_INET6 "sys/types.h;sys/socket.h;netinet/in.h" HAVE_AF_INET6)
736d881c474Schristosendif(WIN32)
737d881c474Schristoscheck_type_size("struct in6_addr" HAVE_STRUCT_IN6_ADDR)
738d881c474Schristoscmake_pop_check_state()
739d881c474Schristosif(HAVE_AF_INET6 AND HAVE_STRUCT_IN6_ADDR)
740d881c474Schristos    set(HAVE_OS_IPV6_SUPPORT TRUE)
741d881c474Schristosendif(HAVE_AF_INET6 AND HAVE_STRUCT_IN6_ADDR)
742d881c474Schristos
743d881c474Schristos######################################
744d881c474Schristos# External dependencies
745d881c474Schristos######################################
746d881c474Schristos
747d881c474Schristos#
748d881c474Schristos# libpcap/WinPcap/Npcap.
749d881c474Schristos# First, find it.
750d881c474Schristos#
751d881c474Schristosfind_package(PCAP REQUIRED)
752d881c474Schristosinclude_directories(${PCAP_INCLUDE_DIRS})
753d881c474Schristos
754d881c474Schristoscmake_push_check_state()
755d881c474Schristos
756d881c474Schristos#
757d881c474Schristos# Now check headers.
758d881c474Schristos#
759d881c474Schristosset(CMAKE_REQUIRED_INCLUDES ${PCAP_INCLUDE_DIRS})
760d881c474Schristos
761d881c474Schristos#
762d881c474Schristos# Check whether we have pcap/pcap-inttypes.h.
763d881c474Schristos# If we do, we use that to get the C99 types defined.
764d881c474Schristos#
765d881c474Schristoscheck_include_file(pcap/pcap-inttypes.h HAVE_PCAP_PCAP_INTTYPES_H)
766d881c474Schristos
767d881c474Schristos#
768*c41df9f6Schristos# At compile time HAVE_PCAP_FINDALLDEVS depends on HAVE_PCAP_IF_T.
769*c41df9f6Schristos#
770*c41df9f6Schristoscmake_push_check_state()
771*c41df9f6Schristosset(CMAKE_EXTRA_INCLUDE_FILES pcap.h)
772*c41df9f6Schristoscheck_type_size(pcap_if_t PCAP_IF_T)
773*c41df9f6Schristoscmake_pop_check_state()
774*c41df9f6Schristos
775*c41df9f6Schristos#
776d881c474Schristos# Check for various functions in libpcap/WinPcap/Npcap.
777d881c474Schristos#
778d881c474Schristoscmake_push_check_state()
779d881c474Schristosset(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARIES})
780d881c474Schristos
781d881c474Schristos#
782d881c474Schristos# Check for "pcap_list_datalinks()" and use a substitute version if
783d881c474Schristos# it's not present.  If it is present, check for "pcap_free_datalinks()";
784d881c474Schristos# if it's not present, we don't replace it for now.  (We could do so
785d881c474Schristos# on UN*X, but not on Windows, where hilarity ensues if a program
786d881c474Schristos# built with one version of the MSVC support library tries to free
787d881c474Schristos# something allocated by a library built with another version of
788d881c474Schristos# the MSVC support library.)
789d881c474Schristos#
790d881c474Schristoscheck_function_exists(pcap_list_datalinks HAVE_PCAP_LIST_DATALINKS)
791d881c474Schristosif(HAVE_PCAP_LIST_DATALINKS)
792d881c474Schristos    check_function_exists(pcap_free_datalinks HAVE_PCAP_FREE_DATALINKS)
793d881c474Schristosendif(HAVE_PCAP_LIST_DATALINKS)
794d881c474Schristos
795d881c474Schristos#
796d881c474Schristos# Check for "pcap_datalink_name_to_val()", and use a substitute
797d881c474Schristos# version if it's not present.  If it is present, check for
798d881c474Schristos# "pcap_datalink_val_to_description()", and if we don't have it,
799d881c474Schristos# use a substitute version.
800d881c474Schristos#
801d881c474Schristoscheck_function_exists(pcap_datalink_name_to_val HAVE_PCAP_DATALINK_NAME_TO_VAL)
802d881c474Schristosif(HAVE_PCAP_DATALINK_NAME_TO_VAL)
803d881c474Schristos    check_function_exists(pcap_datalink_val_to_description HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION)
804d881c474Schristosendif(HAVE_PCAP_DATALINK_NAME_TO_VAL)
805d881c474Schristos
806d881c474Schristos#
807d881c474Schristos# Check for "pcap_set_datalink()"; you can't substitute for it if
808d881c474Schristos# it's absent (it has hooks into libpcap), so just define the
809d881c474Schristos# HAVE_ value if it's there.
810d881c474Schristos#
811d881c474Schristoscheck_function_exists(pcap_set_datalink HAVE_PCAP_SET_DATALINK)
812d881c474Schristos
813d881c474Schristos#
814d881c474Schristos# Check for "pcap_breakloop()"; you can't substitute for it if
815d881c474Schristos# it's absent (it has hooks into the live capture routines),
816d881c474Schristos# so just define the HAVE_ value if it's there.
817d881c474Schristos#
818d881c474Schristoscheck_function_exists(pcap_breakloop HAVE_PCAP_BREAKLOOP)
819d881c474Schristos
820d881c474Schristos#
821d881c474Schristos# Check for "pcap_dump_ftell()"; we use a substitute version
822d881c474Schristos# if it's not present.
823d881c474Schristos#
824d881c474Schristoscheck_function_exists(pcap_dump_ftell HAVE_PCAP_DUMP_FTELL)
825d881c474Schristos
826d881c474Schristos#
827d881c474Schristos# Do we have the new open API?  Check for pcap_create() and for
828d881c474Schristos# pcap_statustostr(), and assume that, if we have both of them,
829d881c474Schristos# we also have pcap_activate() and the other new routines
830d881c474Schristos# introduced in libpcap 1.0.0.  (We check for pcap_statustostr()
831d881c474Schristos# as well, because WinPcap 4.1.3 screwed up and exported pcap_create()
832d881c474Schristos# but not other routines such as pcap_statustostr(), even though it
833d881c474Schristos# defined them and even though you really want pcap_statustostr() to
834d881c474Schristos# get strings corresponding to some of the status returns from the
835d881c474Schristos# new routines.)
836d881c474Schristos#
837d881c474Schristoscheck_function_exists(pcap_statustostr HAVE_PCAP_STATUSTOSTR)
838d881c474Schristos#
839d881c474Schristos# If we don't have pcap_statustostr(), don't check for pcap_create(),
840d881c474Schristos# so we pretend we don't have it.
841d881c474Schristos#
842d881c474Schristosif(HAVE_PCAP_STATUSTOSTR)
843d881c474Schristos    check_function_exists(pcap_create HAVE_PCAP_CREATE)
844d881c474Schristosendif(HAVE_PCAP_STATUSTOSTR)
845d881c474Schristosif(HAVE_PCAP_CREATE)
846d881c474Schristos    #
847d881c474Schristos    # OK, do we have pcap_set_tstamp_type?  If so, assume we have
848d881c474Schristos    # pcap_list_tstamp_types and pcap_free_tstamp_types as well.
849d881c474Schristos    #
850d881c474Schristos    check_function_exists(pcap_set_tstamp_type HAVE_PCAP_SET_TSTAMP_TYPE)
851d881c474Schristos
852d881c474Schristos    #
853d881c474Schristos    # And do we have pcap_set_tstamp_precision?  If so, we assume
854d881c474Schristos    # we also have pcap_open_offline_with_tstamp_precision.
855d881c474Schristos    #
856d881c474Schristos    check_function_exists(pcap_set_tstamp_precision HAVE_PCAP_SET_TSTAMP_PRECISION)
857d881c474Schristosendif(HAVE_PCAP_CREATE)
858d881c474Schristos
859d881c474Schristos#
860d881c474Schristos# Check for a miscellaneous collection of functions which we use
861d881c474Schristos# if we have them.
862d881c474Schristos#
863d881c474Schristoscheck_function_exists(pcap_findalldevs HAVE_PCAP_FINDALLDEVS)
864d881c474Schristoscheck_function_exists(pcap_dump_flush HAVE_PCAP_DUMP_FLUSH)
865d881c474Schristoscheck_function_exists(pcap_lib_version HAVE_PCAP_LIB_VERSION)
866d881c474Schristosif(NOT HAVE_PCAP_LIB_VERSION)
867d881c474Schristos    # Check for the pcap_version string variable and set HAVE_PCAP_VERSION
868d881c474Schristosendif(NOT HAVE_PCAP_LIB_VERSION)
869d881c474Schristoscheck_function_exists(pcap_setdirection HAVE_PCAP_SETDIRECTION)
870d881c474Schristoscheck_function_exists(pcap_set_immediate_mode HAVE_PCAP_SET_IMMEDIATE_MODE)
871d881c474Schristoscheck_function_exists(pcap_dump_ftell64 HAVE_PCAP_DUMP_FTELL64)
872*c41df9f6Schristos#
873*c41df9f6Schristos# macOS Sonoma's libpcap includes stub versions of the remote-
874*c41df9f6Schristos# capture APIs.  They are exported as "weakly linked symbols".
875*c41df9f6Schristos#
876*c41df9f6Schristos# Xcode 15 offers only a macOS Sonoma SDK, which has a .tbd
877*c41df9f6Schristos# file for libpcap that claims it includes those APIs.  (Newer
878*c41df9f6Schristos# versions of macOS don't provide the system shared libraries,
879*c41df9f6Schristos# they only provide the dyld shared cache containing those
880*c41df9f6Schristos# libraries, so the OS provides SDKs that include a .tbd file
881*c41df9f6Schristos# to use when linking.)
882*c41df9f6Schristos#
883*c41df9f6Schristos# This means that check_function_exists() will think that
884*c41df9f6Schristos# the remote-capture APIs are present, including pcap_open()
885*c41df9f6Schristos# and pcap_findalldevs_ex().
886*c41df9f6Schristos#
887*c41df9f6Schristos# However, they are *not* present in macOS Ventura and earlier,
888*c41df9f6Schristos# which means that building on Ventura with Xcode 15 produces
889*c41df9f6Schristos# executables that fail to start because one of those APIs
890*c41df9f6Schristos# isn't found in the system libpcap.
891*c41df9f6Schristos#
892*c41df9f6Schristos# Protecting calls to those APIs with __builtin_available()
893*c41df9f6Schristos# does not prevent this, because the libpcap header files
894*c41df9f6Schristos# in the Sonoma SDK mark them as being first available
895*c41df9f6Schristos# in macOS 10.13, just like all the other routines introduced
896*c41df9f6Schristos# in libpcap 1.9, even though they're only available if libpcap
897*c41df9f6Schristos# is built with remote capture enabled or stub routines are
898*c41df9f6Schristos# provided.  (A fix to enable this has been checked into the
899*c41df9f6Schristos# libpcap repository, and may end up in a later version of
900*c41df9f6Schristos# the SDK.)
901*c41df9f6Schristos#
902*c41df9f6Schristos# Given all that, and given that the versions of the
903*c41df9f6Schristos# remote-capture APIs in Sonoma are stubs that always fail,
904*c41df9f6Schristos# there doesn't seem to be any point in checking for pcap_open()
905*c41df9f6Schristos# and pcap_findalldevs_ex() if we're linking against the Apple libpcap.
906*c41df9f6Schristos#
907*c41df9f6Schristos# However, if we're *not* linking against the Apple libpcap,
908*c41df9f6Schristos# we should check for it, so that we can use it if it's present.
909*c41df9f6Schristos#
910*c41df9f6Schristos# So we check for pcap_open() and pcap_findalldevs_ex() if 1) this isn't
911*c41df9f6Schristos# macOS or 2) the the libpcap we found is not a system library, meaning
912*c41df9f6Schristos# that its path begins neither with /usr/lib (meaning it's a system
913*c41df9f6Schristos# dylib) nor /Application/Xcode.app (meaning it's a file in
914*c41df9f6Schristos# the Xcode SDK).
915*c41df9f6Schristos#
916*c41df9f6Schristosif(NOT APPLE OR NOT
917*c41df9f6Schristos   (PCAP_LIBRARIES MATCHES "/usr/lib/.*" OR
918*c41df9f6Schristos    PCAP_LIBRARIES MATCHES "/Application/Xcode.app/.*"))
919d881c474Schristos    check_function_exists(pcap_open HAVE_PCAP_OPEN)
920d881c474Schristos    check_function_exists(pcap_findalldevs_ex HAVE_PCAP_FINDALLDEVS_EX)
921*c41df9f6Schristosendif()
922d881c474Schristos
923d881c474Schristos#
924d881c474Schristos# On Windows, check for pcap_wsockinit(); if we don't have it, check for
925d881c474Schristos# wsockinit().
926d881c474Schristos#
927d881c474Schristosif(WIN32)
928d881c474Schristos    check_function_exists(pcap_wsockinit HAVE_PCAP_WSOCKINIT)
929d881c474Schristos    if(NOT HAVE_PCAP_WSOCKINIT)
930d881c474Schristos        check_function_exists(wsockinit HAVE_WSOCKINIT)
931d881c474Schristos    endif(NOT HAVE_PCAP_WSOCKINIT)
932d881c474Schristosendif(WIN32)
933d881c474Schristos
934d881c474Schristos#
935d881c474Schristos# Check for special debugging functions
936d881c474Schristos#
937d881c474Schristoscheck_function_exists(pcap_set_parser_debug HAVE_PCAP_SET_PARSER_DEBUG)
938d881c474Schristosif(NOT HAVE_PCAP_SET_PARSER_DEBUG)
939d881c474Schristos    # Check whether libpcap defines pcap_debug or yydebug
940d881c474Schristos    check_variable_exists(pcap_debug HAVE_PCAP_DEBUG)
941d881c474Schristos    if(NOT HAVE_PCAP_DEBUG)
942d881c474Schristos        check_variable_exists(yydebug HAVE_YYDEBUG)
943d881c474Schristos    endif(NOT HAVE_PCAP_DEBUG)
944d881c474Schristosendif(NOT HAVE_PCAP_SET_PARSER_DEBUG)
945d881c474Schristos
946d881c474Schristoscheck_function_exists(pcap_set_optimizer_debug HAVE_PCAP_SET_OPTIMIZER_DEBUG)
947d881c474Schristoscheck_function_exists(bpf_dump HAVE_BPF_DUMP)
948d881c474Schristos
949d881c474Schristoscmake_pop_check_state()
950d881c474Schristos
951d881c474Schristos#
952d881c474Schristos# We have libpcap.
953d881c474Schristos#
954d881c474Schristosinclude_directories(SYSTEM ${PCAP_INCLUDE_DIRS})
955d881c474Schristosset(TCPDUMP_LINK_LIBRARIES ${PCAP_LIBRARIES} ${TCPDUMP_LINK_LIBRARIES})
956d881c474Schristos
957d881c474Schristos#
958d881c474Schristos# Optional libraries.
959d881c474Schristos#
960d881c474Schristos
961d881c474Schristos#
962d881c474Schristos# libsmi.
963d881c474Schristos#
964d881c474Schristosif(WITH_SMI)
965d881c474Schristos    find_package(SMI)
966d881c474Schristos    if(SMI_FOUND)
967d881c474Schristos        include_directories(SYSTEM ${SMI_INCLUDE_DIRS})
968d881c474Schristos        set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} ${SMI_LIBRARIES})
969d881c474Schristos        set(USE_LIBSMI ON)
970d881c474Schristos    endif(SMI_FOUND)
971d881c474Schristosendif(WITH_SMI)
972d881c474Schristos
973d881c474Schristos#
974d881c474Schristos# OpenSSL/libressl libcrypto.
975d881c474Schristos#
976d881c474Schristosif(WITH_CRYPTO)
977d881c474Schristos    find_package(CRYPTO)
978d881c474Schristos    if(CRYPTO_FOUND)
979d881c474Schristos        #
980d881c474Schristos        # 1) do we have EVP_CIPHER_CTX_new?
981d881c474Schristos        # If so, we use it to allocate an EVP_CIPHER_CTX, as
982d881c474Schristos        # EVP_CIPHER_CTX may be opaque; otherwise, we allocate
983d881c474Schristos        # it ourselves.
984d881c474Schristos        #
985d881c474Schristos        cmake_push_check_state()
986d881c474Schristos        set(CMAKE_REQUIRED_LIBRARIES "${CRYPTO_LIBRARIES}")
987d881c474Schristos
988d881c474Schristos        check_function_exists(EVP_CIPHER_CTX_new HAVE_EVP_CIPHER_CTX_NEW)
989d881c474Schristos
990d881c474Schristos        #
991d881c474Schristos        # 2) do we have EVP_DecryptInit_ex()?
992d881c474Schristos        # If so, we use it, because we need to be able to make two
993d881c474Schristos        # "initialize the cipher" calls, one with the cipher and key,
994d881c474Schristos        # and one with the IV, and, as of OpenSSL 1.1, You Can't Do That
995d881c474Schristos        # with EVP_DecryptInit(), because a call to EVP_DecryptInit() will
996d881c474Schristos        # unconditionally clear the context, and if you don't supply a
997d881c474Schristos        # cipher, it'll clear the cipher, rendering the context unusable
998d881c474Schristos        # and causing a crash.
999d881c474Schristos        #
1000d881c474Schristos        check_function_exists(EVP_DecryptInit_ex HAVE_EVP_DECRYPTINIT_EX)
1001d881c474Schristos
1002d881c474Schristos        cmake_pop_check_state()
1003d881c474Schristos
1004d881c474Schristos        #
1005d881c474Schristos        # We have libcrypto.
1006d881c474Schristos        #
1007d881c474Schristos        include_directories(SYSTEM ${CRYPTO_INCLUDE_DIRS})
1008d881c474Schristos        set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} ${CRYPTO_LIBRARIES})
1009d881c474Schristos        set(HAVE_LIBCRYPTO ON)
1010d881c474Schristos    endif(CRYPTO_FOUND)
1011d881c474Schristosendif(WITH_CRYPTO)
1012d881c474Schristos
1013d881c474Schristos#
1014d881c474Schristos# Capsicum sandboxing.
1015d881c474Schristos# Some of this is in the system library, some of it is in other libraries.
1016d881c474Schristos#
1017d881c474Schristosif(WITH_CAPSICUM)
1018d881c474Schristos    check_include_files("sys/capsicum.h" HAVE_SYS_CAPSICUM_H)
1019d881c474Schristos    if(HAVE_SYS_CAPSICUM_H)
1020d881c474Schristos        check_function_exists(cap_enter HAVE_CAP_ENTER)
1021d881c474Schristos        check_function_exists(cap_rights_limit HAVE_CAP_RIGHTS_LIMIT)
1022d881c474Schristos        check_function_exists(cap_ioctls_limit HAVE_CAP_IOCTLS_LIMIT)
1023d881c474Schristos        check_function_exists(openat HAVE_OPENAT)
1024d881c474Schristos        if(HAVE_CAP_ENTER AND HAVE_CAP_RIGHTS_LIMIT AND
1025d881c474Schristos           HAVE_CAP_IOCTLS_LIMIT AND HAVE_OPENAT)
1026d881c474Schristos            #
1027d881c474Schristos            # OK, we have the functions we need to support Capsicum.
1028d881c474Schristos            #
1029d881c474Schristos            set(HAVE_CAPSICUM TRUE)
1030d881c474Schristos
1031d881c474Schristos            #
1032d881c474Schristos            # OK, can we use Casper?
1033d881c474Schristos            #
1034d881c474Schristos            check_library_exists(casper cap_init "" HAVE_CAP_INIT)
1035d881c474Schristos            if(HAVE_CAP_INIT)
1036d881c474Schristos                cmake_push_check_state()
1037d881c474Schristos                set(CMAKE_REQUIRED_LIBRARIES casper)
1038d881c474Schristos                check_library_exists(cap_dns cap_gethostbyaddr "" HAVE_CAP_GETHOSTBYADDR)
1039d881c474Schristos                cmake_pop_check_state()
1040d881c474Schristos                if(HAVE_CAP_GETHOSTBYADDR)
1041d881c474Schristos                    set(HAVE_CASPER TRUE)
1042d881c474Schristos                    set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} casper cap_dns)
1043d881c474Schristos                endif(HAVE_CAP_GETHOSTBYADDR)
1044d881c474Schristos            endif(HAVE_CAP_INIT)
1045d881c474Schristos        endif(HAVE_CAP_ENTER AND HAVE_CAP_RIGHTS_LIMIT AND
1046d881c474Schristos              HAVE_CAP_IOCTLS_LIMIT AND HAVE_OPENAT)
1047d881c474Schristos    endif(HAVE_SYS_CAPSICUM_H)
1048d881c474Schristosendif(WITH_CAPSICUM)
1049d881c474Schristos
1050d881c474Schristos#
1051d881c474Schristos# libcap-ng.
1052d881c474Schristos#
1053d881c474Schristosif(WITH_CAP_NG)
1054d881c474Schristos    check_include_file(cap-ng.h HAVE_CAP_NG_H)
1055d881c474Schristos    check_library_exists(cap-ng capng_change_id "" HAVE_LIBCAP_NG)
1056d881c474Schristos    if(HAVE_LIBCAP_NG)
1057d881c474Schristos        set(TCPDUMP_LINK_LIBRARIES ${TCPDUMP_LINK_LIBRARIES} cap-ng)
1058d881c474Schristos    endif(HAVE_LIBCAP_NG)
1059d881c474Schristosendif(WITH_CAP_NG)
1060d881c474Schristos
1061d881c474Schristos###################################################################
1062d881c474Schristos#   Warning options
1063d881c474Schristos###################################################################
1064d881c474Schristos
1065d881c474Schristos#
1066d881c474Schristos# Check and add warning options if we have a .devel file.
1067d881c474Schristos#
1068d881c474Schristosif(EXISTS ${CMAKE_SOURCE_DIR}/.devel OR EXISTS ${CMAKE_BINARY_DIR}/.devel)
1069d881c474Schristos    #
1070d881c474Schristos    # Warning options.
1071d881c474Schristos    #
1072d881c474Schristos    if(MSVC AND NOT ${CMAKE_C_COMPILER} MATCHES "clang*")
1073d881c474Schristos        #
1074d881c474Schristos        # MSVC, with Microsoft's front end and code generator.
1075d881c474Schristos        # "MSVC" is also set for Microsoft's compiler with a Clang
1076d881c474Schristos        # front end and their code generator ("Clang/C2"), so we
1077d881c474Schristos        # check for clang.exe and treat that differently.
1078d881c474Schristos        #
1079d881c474Schristos        check_and_add_compiler_option(-Wall)
1080d881c474Schristos        #
1081d881c474Schristos        # Disable some pointless warnings that /Wall turns on.
1082d881c474Schristos        #
1083d881c474Schristos        # Unfortunately, MSVC does not appear to have an equivalent
1084d881c474Schristos        # to "__attribute__((unused))" to mark a particular function
1085d881c474Schristos        # parameter as being known to be unused, so that the compiler
1086d881c474Schristos        # won't warn about it (for example, the function might have
1087d881c474Schristos        # that parameter because a pointer to it is being used, and
1088d881c474Schristos        # the signature of that function includes that parameter).
1089d881c474Schristos        # C++ lets you give a parameter a type but no name, but C
1090d881c474Schristos        # doesn't have that.
1091d881c474Schristos        #
1092d881c474Schristos        check_and_add_compiler_option(-wd4100)
1093d881c474Schristos        #
1094d881c474Schristos        # In theory, we care whether somebody uses f() rather than
1095d881c474Schristos        # f(void) to declare a function with no arguments, but, in
1096d881c474Schristos        # practice, there are places in the Windows header files
1097d881c474Schristos        # that appear to do that, so we squelch that warning.
1098d881c474Schristos        #
1099d881c474Schristos        check_and_add_compiler_option(-wd4255)
1100d881c474Schristos        #
1101d881c474Schristos        # Windows FD_SET() generates this, so we suppress it.
1102d881c474Schristos        #
1103d881c474Schristos        check_and_add_compiler_option(-wd4548)
1104d881c474Schristos        #
1105d881c474Schristos        # Perhaps testing something #defined to be 0 with #ifdef is an
1106d881c474Schristos        # error, and it should be tested with #if, but perhaps it's
1107d881c474Schristos        # not, and Microsoft does that in its headers, so we squelch
1108d881c474Schristos        # that warning.
1109d881c474Schristos        #
1110d881c474Schristos        check_and_add_compiler_option(-wd4574)
1111d881c474Schristos        #
1112d881c474Schristos        # The Windows headers also test not-defined values in #if, so
1113d881c474Schristos        # we don't want warnings about that, either.
1114d881c474Schristos        #
1115d881c474Schristos        check_and_add_compiler_option(-wd4668)
1116d881c474Schristos        #
1117d881c474Schristos        # We do *not* care whether some function is, or isn't, going to be
1118d881c474Schristos        # expanded inline.
1119d881c474Schristos        #
1120d881c474Schristos        check_and_add_compiler_option(-wd4710)
1121d881c474Schristos        check_and_add_compiler_option(-wd4711)
1122d881c474Schristos        #
1123d881c474Schristos        # We do *not* care whether we're adding padding bytes after
1124d881c474Schristos        # structure members.
1125d881c474Schristos        #
1126d881c474Schristos        check_and_add_compiler_option(-wd4820)
1127d881c474Schristos        #
1128d881c474Schristos        # We do *not* care about every single place the compiler would
1129d881c474Schristos        # have inserted Spectre mitigation if only we had told it to
1130d881c474Schristos        # do so with /Qspectre.  I guess the theory is that it's seeing
1131d881c474Schristos        # bounds checks that would prevent out-of-bounds loads and that
1132d881c474Schristos        # those out-of-bounds loads could be done speculatively and that
1133d881c474Schristos        # the Spectre attack could detect the value of the out-of-bounds
1134d881c474Schristos        # data *if* it's within our address space, but unless I'm
1135d881c474Schristos        # missing something I don't see that as being any form of
1136d881c474Schristos        # security hole.
1137d881c474Schristos        #
1138d881c474Schristos        # XXX - add /Qspectre if that is really worth doing.
1139d881c474Schristos        #
1140d881c474Schristos        check_and_add_compiler_option(-wd5045)
1141d881c474Schristos        #
1142d881c474Schristos        # We do *not* care whether a structure had padding added at
1143d881c474Schristos        # the end because of __declspec(align) - *we* don't use
1144d881c474Schristos        # __declspec(align), because the only structures whose layout
1145*c41df9f6Schristos        # we precisely specify are those that get overlaid on packet
1146d881c474Schristos        # data, and in those every element is an array of octets so
1147*c41df9f6Schristos        # that we have full control over the size and alignment, and,
1148d881c474Schristos        # apparently, jmp_buf has such a declaration on x86, meaning
1149d881c474Schristos        # that everything that includes netdissect.h, i.e. almost every
1150d881c474Schristos        # file in tcpdump, gets a warning.
1151d881c474Schristos        #
1152d881c474Schristos        check_and_add_compiler_option(-wd4324)
1153d881c474Schristos    else()
1154d881c474Schristos        #
1155d881c474Schristos        # Other compilers, including MSVC with a Clang front end and
1156d881c474Schristos        # Microsoft's code generator.  We currently treat them as if
1157d881c474Schristos        # they might support GCC-style -W options.
1158d881c474Schristos        #
1159d881c474Schristos        check_and_add_compiler_option(-W)
1160d881c474Schristos        check_and_add_compiler_option(-Wall)
1161d881c474Schristos        check_and_add_compiler_option(-Wassign-enum)
1162d881c474Schristos        check_and_add_compiler_option(-Wcast-qual)
1163d881c474Schristos        check_and_add_compiler_option(-Wmissing-prototypes)
1164d881c474Schristos        check_and_add_compiler_option(-Wmissing-variable-declarations)
1165d881c474Schristos        check_and_add_compiler_option(-Wold-style-definition)
1166*c41df9f6Schristos        if(NOT CMAKE_C_COMPILER_ID MATCHES "Sun")
1167*c41df9f6Schristos            # In Sun C versions that implement GCC compatibility "-Wpedantic"
1168*c41df9f6Schristos            # means the same as "-pedantic".  The latter is mutually exclusive
1169*c41df9f6Schristos            # with several other options.  One of those is "-xc99", which has
1170*c41df9f6Schristos            # already been set for Sun C above.
1171d881c474Schristos            check_and_add_compiler_option(-Wpedantic)
1172*c41df9f6Schristos        endif()
1173d881c474Schristos        check_and_add_compiler_option(-Wpointer-arith)
1174d881c474Schristos        check_and_add_compiler_option(-Wpointer-sign)
1175d881c474Schristos        check_and_add_compiler_option(-Wshadow)
1176d881c474Schristos        check_and_add_compiler_option(-Wsign-compare)
1177d881c474Schristos        check_and_add_compiler_option(-Wstrict-prototypes)
1178*c41df9f6Schristos        check_and_add_compiler_option(-Wundef)
1179d881c474Schristos        check_and_add_compiler_option(-Wunreachable-code-return)
1180d881c474Schristos        check_and_add_compiler_option(-Wused-but-marked-unused)
1181d881c474Schristos        check_and_add_compiler_option(-Wwrite-strings)
1182d881c474Schristos    endif()
1183d881c474Schristosendif()
1184d881c474Schristos
1185d881c474Schristos#
1186d881c474Schristos# Extra compiler options for the build matrix scripts to request -Werror or
1187d881c474Schristos# its equivalent if required.  The CMake variable name cannot be CFLAGS
1188d881c474Schristos# because that is already used for a different purpose in CMake.  Example
1189d881c474Schristos# usage: cmake -DEXTRA_CFLAGS='-Wall -Wextra -Werror' ...
1190d881c474Schristos#
1191d881c474Schristosif(NOT "${EXTRA_CFLAGS}" STREQUAL "")
1192*c41df9f6Schristos    # The meaning of EXTRA_CFLAGS is "use the exact specified options, or the
1193*c41df9f6Schristos    # build risks failing to fail", not "try every specified option, omit those
1194*c41df9f6Schristos    # that do not work and use the rest".  Thus use add_compile_options(), not
1195*c41df9f6Schristos    # foreach()/check_and_add_compiler_option().  Another reason to do that is
1196*c41df9f6Schristos    # that the effect lasts in testprogs/ and testprogs/fuzz/.
1197*c41df9f6Schristos    string(REPLACE " " ";" _extra_cflags_list ${EXTRA_CFLAGS})
1198*c41df9f6Schristos    add_compile_options(${_extra_cflags_list})
1199d881c474Schristos    message(STATUS "Added extra compile options (${EXTRA_CFLAGS})")
1200d881c474Schristosendif()
1201d881c474Schristos
1202d881c474Schristos######################################
1203d881c474Schristos# Input files
1204d881c474Schristos######################################
1205d881c474Schristos
1206d881c474Schristosif(ENABLE_SMB)
1207d881c474Schristos    #
1208d881c474Schristos    # We allow the SMB dissector to be omitted.
1209d881c474Schristos    #
1210d881c474Schristos    set(LOCALSRC ${LOCALSRC}
1211d881c474Schristos        print-smb.c
1212d881c474Schristos        smbutil.c)
1213d881c474Schristosendif(ENABLE_SMB)
1214d881c474Schristos
1215d881c474Schristosset(NETDISSECT_SOURCE_LIST_C
1216d881c474Schristos    addrtoname.c
1217d881c474Schristos    addrtostr.c
1218d881c474Schristos    af.c
1219d881c474Schristos    ascii_strcasecmp.c
1220d881c474Schristos    checksum.c
1221d881c474Schristos    cpack.c
1222d881c474Schristos    gmpls.c
1223d881c474Schristos    in_cksum.c
1224d881c474Schristos    ipproto.c
1225d881c474Schristos    l2vpn.c
1226d881c474Schristos    machdep.c
1227d881c474Schristos    netdissect.c
1228d881c474Schristos    netdissect-alloc.c
1229d881c474Schristos    nlpid.c
1230d881c474Schristos    oui.c
1231d881c474Schristos    ntp.c
1232d881c474Schristos    parsenfsfh.c
1233d881c474Schristos    print.c
1234d881c474Schristos    print-802_11.c
1235d881c474Schristos    print-802_15_4.c
1236d881c474Schristos    print-ah.c
1237d881c474Schristos    print-ahcp.c
1238d881c474Schristos    print-aodv.c
1239d881c474Schristos    print-aoe.c
1240d881c474Schristos    print-ap1394.c
1241d881c474Schristos    print-arcnet.c
1242d881c474Schristos    print-arista.c
1243d881c474Schristos    print-arp.c
1244d881c474Schristos    print-ascii.c
1245d881c474Schristos    print-atalk.c
1246d881c474Schristos    print-atm.c
1247d881c474Schristos    print-babel.c
1248d881c474Schristos    print-bcm-li.c
1249d881c474Schristos    print-beep.c
1250d881c474Schristos    print-bfd.c
1251d881c474Schristos    print-bgp.c
1252d881c474Schristos    print-bootp.c
1253d881c474Schristos    print-brcmtag.c
1254d881c474Schristos    print-bt.c
1255d881c474Schristos    print-calm-fast.c
1256d881c474Schristos    print-carp.c
1257d881c474Schristos    print-cdp.c
1258d881c474Schristos    print-cfm.c
1259d881c474Schristos    print-chdlc.c
1260d881c474Schristos    print-cip.c
1261d881c474Schristos    print-cnfp.c
1262d881c474Schristos    print-dccp.c
1263d881c474Schristos    print-decnet.c
1264d881c474Schristos    print-dhcp6.c
1265d881c474Schristos    print-domain.c
1266d881c474Schristos    print-dsa.c
1267d881c474Schristos    print-dtp.c
1268d881c474Schristos    print-dvmrp.c
1269d881c474Schristos    print-eap.c
1270d881c474Schristos    print-egp.c
1271d881c474Schristos    print-eigrp.c
1272d881c474Schristos    print-enc.c
1273d881c474Schristos    print-esp.c
1274d881c474Schristos    print-ether.c
1275d881c474Schristos    print-fddi.c
1276d881c474Schristos    print-forces.c
1277d881c474Schristos    print-fr.c
1278d881c474Schristos    print-frag6.c
1279d881c474Schristos    print-ftp.c
1280d881c474Schristos    print-geneve.c
1281d881c474Schristos    print-geonet.c
1282d881c474Schristos    print-gre.c
1283d881c474Schristos    print-hncp.c
1284d881c474Schristos    print-hsrp.c
1285d881c474Schristos    print-http.c
1286d881c474Schristos    print-icmp.c
1287d881c474Schristos    print-icmp6.c
1288d881c474Schristos    print-igmp.c
1289d881c474Schristos    print-igrp.c
1290d881c474Schristos    print-ip-demux.c
1291d881c474Schristos    print-ip.c
1292d881c474Schristos    print-ip6.c
1293d881c474Schristos    print-ip6opts.c
1294d881c474Schristos    print-ipcomp.c
1295d881c474Schristos    print-ipfc.c
1296d881c474Schristos    print-ipnet.c
1297d881c474Schristos    print-ipoib.c
1298d881c474Schristos    print-ipx.c
1299d881c474Schristos    print-isakmp.c
1300d881c474Schristos    print-isoclns.c
1301d881c474Schristos    print-juniper.c
1302d881c474Schristos    print-krb.c
1303d881c474Schristos    print-l2tp.c
1304d881c474Schristos    print-lane.c
1305d881c474Schristos    print-ldp.c
1306d881c474Schristos    print-lisp.c
1307d881c474Schristos    print-llc.c
1308d881c474Schristos    print-lldp.c
1309d881c474Schristos    print-lmp.c
1310d881c474Schristos    print-loopback.c
1311d881c474Schristos    print-lspping.c
1312d881c474Schristos    print-lwapp.c
1313d881c474Schristos    print-lwres.c
1314d881c474Schristos    print-m3ua.c
1315d881c474Schristos    print-macsec.c
1316d881c474Schristos    print-mobile.c
1317d881c474Schristos    print-mobility.c
1318d881c474Schristos    print-mpcp.c
1319d881c474Schristos    print-mpls.c
1320d881c474Schristos    print-mptcp.c
1321d881c474Schristos    print-msdp.c
1322d881c474Schristos    print-msnlb.c
1323d881c474Schristos    print-nflog.c
1324d881c474Schristos    print-nfs.c
1325d881c474Schristos    print-nsh.c
1326d881c474Schristos    print-ntp.c
1327d881c474Schristos    print-null.c
1328d881c474Schristos    print-olsr.c
1329d881c474Schristos    print-openflow-1.0.c
1330d881c474Schristos    print-openflow-1.3.c
1331d881c474Schristos    print-openflow.c
1332d881c474Schristos    print-ospf.c
1333d881c474Schristos    print-ospf6.c
1334d881c474Schristos    print-otv.c
1335d881c474Schristos    print-pflog.c
1336d881c474Schristos    print-pgm.c
1337d881c474Schristos    print-pim.c
1338d881c474Schristos    print-pktap.c
1339d881c474Schristos    print-ppi.c
1340d881c474Schristos    print-ppp.c
1341d881c474Schristos    print-pppoe.c
1342d881c474Schristos    print-pptp.c
1343d881c474Schristos    print-ptp.c
1344d881c474Schristos    print-radius.c
1345d881c474Schristos    print-raw.c
1346d881c474Schristos    print-realtek.c
1347d881c474Schristos    print-resp.c
1348d881c474Schristos    print-rip.c
1349d881c474Schristos    print-ripng.c
1350d881c474Schristos    print-rpki-rtr.c
1351d881c474Schristos    print-rsvp.c
1352d881c474Schristos    print-rt6.c
1353d881c474Schristos    print-rtsp.c
1354d881c474Schristos    print-rx.c
1355d881c474Schristos    print-sctp.c
1356d881c474Schristos    print-sflow.c
1357d881c474Schristos    print-sip.c
1358d881c474Schristos    print-sl.c
1359d881c474Schristos    print-sll.c
1360d881c474Schristos    print-slow.c
1361d881c474Schristos    print-smtp.c
1362d881c474Schristos    print-snmp.c
1363d881c474Schristos    print-someip.c
1364d881c474Schristos    print-ssh.c
1365d881c474Schristos    print-stp.c
1366d881c474Schristos    print-sunatm.c
1367d881c474Schristos    print-sunrpc.c
1368d881c474Schristos    print-symantec.c
1369d881c474Schristos    print-syslog.c
1370d881c474Schristos    print-tcp.c
1371d881c474Schristos    print-telnet.c
1372d881c474Schristos    print-tftp.c
1373d881c474Schristos    print-timed.c
1374d881c474Schristos    print-tipc.c
1375d881c474Schristos    print-token.c
1376d881c474Schristos    print-udld.c
1377d881c474Schristos    print-udp.c
1378d881c474Schristos    print-unsupported.c
1379d881c474Schristos    print-usb.c
1380d881c474Schristos    print-vjc.c
1381d881c474Schristos    print-vqp.c
1382d881c474Schristos    print-vrrp.c
1383d881c474Schristos    print-vsock.c
1384d881c474Schristos    print-vtp.c
1385d881c474Schristos    print-vxlan-gpe.c
1386d881c474Schristos    print-vxlan.c
1387d881c474Schristos    print-wb.c
1388d881c474Schristos    print-whois.c
1389d881c474Schristos    print-zep.c
1390d881c474Schristos    print-zephyr.c
1391d881c474Schristos    print-zeromq.c
1392d881c474Schristos    ${LOCALSRC}
1393d881c474Schristos    signature.c
1394d881c474Schristos    strtoaddr.c
1395d881c474Schristos    util-print.c
1396d881c474Schristos)
1397d881c474Schristos
1398d881c474Schristos#
1399d881c474Schristos# Replace missing functions
1400d881c474Schristos#
1401d881c474Schristosforeach(FUNC strlcat strlcpy strdup strsep getservent getopt_long)
1402d881c474Schristos    string(TOUPPER ${FUNC} FUNC_UPPERCASE)
1403d881c474Schristos    set(HAVE_FUNC_UPPERCASE HAVE_${FUNC_UPPERCASE})
1404d881c474Schristos    if(NOT ${HAVE_FUNC_UPPERCASE})
1405d881c474Schristos        set(NETDISSECT_SOURCE_LIST_C ${NETDISSECT_SOURCE_LIST_C} missing/${FUNC}.c)
1406d881c474Schristos    endif()
1407d881c474Schristosendforeach()
1408d881c474Schristos
1409d881c474Schristosadd_library(netdissect STATIC
1410d881c474Schristos    ${NETDISSECT_SOURCE_LIST_C}
1411d881c474Schristos)
1412d881c474Schristosif(NOT C_ADDITIONAL_FLAGS STREQUAL "")
1413d881c474Schristos    set_target_properties(netdissect PROPERTIES COMPILE_FLAGS ${C_ADDITIONAL_FLAGS})
1414d881c474Schristosendif()
1415d881c474Schristos
1416d881c474Schristosset(TCPDUMP_SOURCE_LIST_C fptype.c tcpdump.c)
1417d881c474Schristos
1418d881c474Schristosif(NOT HAVE_BPF_DUMP)
1419d881c474Schristos    set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} bpf_dump.c)
1420d881c474Schristosendif(NOT HAVE_BPF_DUMP)
1421d881c474Schristosif(NOT HAVE_PCAP_DUMP_FTELL)
1422d881c474Schristos    set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} missing/pcap_dump_ftell.c)
1423d881c474Schristosendif(NOT HAVE_PCAP_DUMP_FTELL)
1424d881c474Schristos
1425d881c474Schristosif(NOT HAVE_PCAP_LIST_DATALINKS)
1426d881c474Schristos    set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} missing/datalinks.c)
1427d881c474Schristosendif(NOT HAVE_PCAP_LIST_DATALINKS)
1428d881c474Schristos
1429d881c474Schristosif((NOT HAVE_PCAP_DATALINK_NAME_TO_VAL) OR (NOT HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION))
1430d881c474Schristos    set(TCPDUMP_SOURCE_LIST_C ${TCPDUMP_SOURCE_LIST_C} missing/dlnames.c)
1431d881c474Schristosendif((NOT HAVE_PCAP_DATALINK_NAME_TO_VAL) OR (NOT HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION))
1432d881c474Schristos
1433d881c474Schristosset(PROJECT_SOURCE_LIST_C ${NETDISSECT_SOURCE_LIST_C} ${TCPDUMP_SOURCE_LIST_C})
1434d881c474Schristos
1435d881c474Schristosfile(GLOB PROJECT_SOURCE_LIST_H
1436d881c474Schristos    *.h
1437d881c474Schristos)
1438d881c474Schristos
1439d881c474Schristos#
1440d881c474Schristos# Assume, by default, no support for shared libraries and V7/BSD
1441d881c474Schristos# convention for man pages (devices in section 4, file formats in
1442d881c474Schristos# section 5, miscellaneous info in section 7, administrative commands
1443d881c474Schristos# and daemons in section 8).  Individual cases can override this.
1444d881c474Schristos# Individual cases can override this.
1445d881c474Schristos#
1446d881c474Schristosset(MAN_FILE_FORMATS 5)
1447d881c474Schristosset(MAN_MISC_INFO 7)
1448d881c474Schristosif(CMAKE_SYSTEM_NAME STREQUAL "AIX")
1449d881c474Schristos    # Workaround to enable certain features
1450d881c474Schristos    set(_SUN TRUE)
1451d881c474Schristoselseif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
1452d881c474Schristos    #
1453d881c474Schristos    # Use System V conventions for man pages.
1454d881c474Schristos    #
1455d881c474Schristos    set(MAN_FILE_FORMATS 4)
1456d881c474Schristos    set(MAN_MISC_INFO 5)
1457d881c474Schristoselseif(CMAKE_SYSTEM_NAME STREQUAL "IRIX" OR CMAKE_SYSTEM_NAME STREQUAL "IRIX64")
1458d881c474Schristos    #
1459d881c474Schristos    # Use IRIX conventions for man pages; they're the same as the
1460d881c474Schristos    # System V conventions, except that they use section 8 for
1461d881c474Schristos    # administrative commands and daemons.
1462d881c474Schristos    #
1463d881c474Schristos    set(MAN_FILE_FORMATS 4)
1464d881c474Schristos    set(MAN_MISC_INFO 5)
1465d881c474Schristoselseif(CMAKE_SYSTEM_NAME STREQUAL "OSF1")
1466d881c474Schristos    #
1467d881c474Schristos    # DEC OSF/1, a/k/a Digital UNIX, a/k/a Tru64 UNIX.
1468d881c474Schristos    # Use Tru64 UNIX conventions for man pages; they're the same as the
1469d881c474Schristos    # System V conventions except that they use section 8 for
1470d881c474Schristos    # administrative commands and daemons.
1471d881c474Schristos    #
1472d881c474Schristos    set(MAN_FILE_FORMATS 4)
1473d881c474Schristos    set(MAN_MISC_INFO 5)
1474d881c474Schristoselseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_VERSION MATCHES "5[.][0-9.]*")
1475d881c474Schristos    #
1476d881c474Schristos    # SunOS 5.x.
1477d881c474Schristos    #
1478d881c474Schristos    if(CMAKE_SYSTEM_VERSION STREQUAL "5.12")
1479d881c474Schristos    else()
1480d881c474Schristos        #
1481d881c474Schristos        # Use System V conventions for man pages.
1482d881c474Schristos        #
1483d881c474Schristos        set(MAN_FILE_FORMATS 4)
1484d881c474Schristos        set(MAN_MISC_INFO 5)
1485d881c474Schristos    endif()
1486d881c474Schristosendif()
1487d881c474Schristos
1488d881c474Schristossource_group("Source Files" FILES ${PROJECT_SOURCE_LIST_C})
1489d881c474Schristossource_group("Header Files" FILES ${PROJECT_SOURCE_LIST_H})
1490d881c474Schristos
1491d881c474Schristos######################################
1492d881c474Schristos# Register targets
1493d881c474Schristos######################################
1494d881c474Schristos
1495d881c474Schristosadd_executable(tcpdump ${TCPDUMP_SOURCE_LIST_C})
1496d881c474Schristosif(NOT C_ADDITIONAL_FLAGS STREQUAL "")
1497d881c474Schristos    set_target_properties(tcpdump PROPERTIES COMPILE_FLAGS ${C_ADDITIONAL_FLAGS})
1498d881c474Schristosendif()
1499d881c474Schristostarget_link_libraries(tcpdump netdissect ${TCPDUMP_LINK_LIBRARIES})
1500d881c474Schristos
1501d881c474Schristos######################################
1502d881c474Schristos# Write out the config.h file
1503d881c474Schristos######################################
1504d881c474Schristos
1505d881c474Schristosconfigure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
1506d881c474Schristos
1507d881c474Schristos######################################
1508d881c474Schristos# Install tcpdump and man pages
1509d881c474Schristos######################################
1510d881c474Schristos
1511d881c474Schristos#
1512d881c474Schristos# "Define GNU standard installation directories", which actually
1513d881c474Schristos# are also defined, to some degree, by autotools, and at least
1514d881c474Schristos# some of which are general UN*X conventions.
1515d881c474Schristos#
1516d881c474Schristosinclude(GNUInstallDirs)
1517d881c474Schristos
1518d881c474Schristosset(MAN1_EXPAND tcpdump.1.in)
1519d881c474Schristos
1520d881c474Schristosif(WIN32)
1521d881c474Schristos    # XXX TODO where to install on Windows?
1522d881c474Schristoselse(WIN32)
1523d881c474Schristos    install(TARGETS tcpdump DESTINATION bin)
1524d881c474Schristosendif(WIN32)
1525d881c474Schristos
1526d881c474Schristos# On UN*X, and on Windows when not using MSVC, process man pages and
1527d881c474Schristos# arrange that they be installed.
1528d881c474Schristosif(NOT MSVC)
1529d881c474Schristos    #
1530d881c474Schristos    # Man pages.
1531d881c474Schristos    #
1532d881c474Schristos    # For each section of the manual for which we have man pages
1533d881c474Schristos    # that require macro expansion, do the expansion.
1534d881c474Schristos    #
1535d881c474Schristos    set(MAN1 "")
1536d881c474Schristos    foreach(TEMPLATE_MANPAGE ${MAN1_EXPAND})
1537d881c474Schristos        string(REPLACE ".in" "" MANPAGE ${TEMPLATE_MANPAGE})
1538d881c474Schristos        configure_file(${CMAKE_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY)
1539d881c474Schristos        set(MAN1 ${MAN1} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE})
1540d881c474Schristos    endforeach(TEMPLATE_MANPAGE)
1541d881c474Schristos    install(FILES ${MAN1} DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
1542d881c474Schristosendif(NOT MSVC)
1543d881c474Schristos
1544d881c474Schristos# uninstall target
1545d881c474Schristosconfigure_file(
1546d881c474Schristos    "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
1547d881c474Schristos    "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
1548d881c474Schristos    IMMEDIATE @ONLY)
1549d881c474Schristos
1550d881c474Schristosadd_custom_target(uninstall
1551d881c474Schristos    COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
1552d881c474Schristos
1553d881c474Schristos#
1554d881c474Schristos# Tcpdump tests
1555d881c474Schristos# We try to find the Perl interpreter and, if we do, we have the check
1556d881c474Schristos# rule run tests/TESTrun with it, because just trying to run the TESTrun
1557d881c474Schristos# script as a command won't work on Windows.
1558d881c474Schristos#
1559d881c474Schristosfind_program(PERL perl)
1560d881c474Schristosif(PERL)
1561d881c474Schristos    message(STATUS "Found perl at ${PERL}")
1562d881c474Schristos    add_custom_target(check
1563d881c474Schristos        COMMAND ${PERL} ${CMAKE_SOURCE_DIR}/tests/TESTrun)
1564d881c474Schristoselse()
1565d881c474Schristos    message(STATUS "Didn't find perl")
1566d881c474Schristosendif()
1567