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