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