Back up to the beginning of the file if we don't have a gzip header.
[gd/wireshark/.git] / CMakeLists.txt
1 # CMakeLists.txt
2 #
3 # Wireshark - Network traffic analyzer
4 # By Gerald Combs <gerald@wireshark.org>
5 # Copyright 1998 Gerald Combs
6 #
7 # SPDX-License-Identifier: GPL-2.0-or-later
8 #
9
10 if(WIN32)
11         # Needed for add_custom_command() WORKING_DIRECTORY generator expressions
12         cmake_minimum_required(VERSION 3.13)
13 else()
14         cmake_minimum_required(VERSION 3.5)
15 endif()
16 if(POLICY CMP0074)
17         cmake_policy(SET CMP0074 NEW)
18 endif()
19 if(POLICY CMP0083)
20         cmake_policy(SET CMP0083 NEW)
21 endif()
22
23 if(WIN32)
24         set(_project_name Wireshark)
25 else()
26         set(_project_name wireshark)
27 endif()
28
29 project(${_project_name} C CXX)
30
31 # Updated by tools/make-version.pl
32 set(GIT_REVISION 0)
33 set(PROJECT_MAJOR_VERSION 3)
34 set(PROJECT_MINOR_VERSION 3)
35 set(PROJECT_PATCH_VERSION 0)
36 set(PROJECT_BUILD_VERSION ${GIT_REVISION})
37 set(PROJECT_VERSION_EXTENSION "")
38
39 if(DEFINED ENV{WIRESHARK_VERSION_EXTRA})
40         set(PROJECT_VERSION_EXTENSION "$ENV{WIRESHARK_VERSION_EXTRA}")
41 endif()
42
43 set(PROJECT_VERSION "${PROJECT_MAJOR_VERSION}.${PROJECT_MINOR_VERSION}.${PROJECT_PATCH_VERSION}${PROJECT_VERSION_EXTENSION}")
44
45 set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
46
47 include( CMakeOptions.txt )
48
49 # We require minimum C++11
50 set(CMAKE_CXX_STANDARD 11)
51 set(CMAKE_CXX_STANDARD_REQUIRED ON)
52 set(CMAKE_CXX_EXTENSIONS OFF)
53
54 message(STATUS "Generating build using CMake ${CMAKE_VERSION}")
55
56 #Where to find local cmake scripts
57 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
58
59 # If our target platform is enforced by our generator, set
60 # WIRESHARK_TARGET_PLATFORM accordingly. Otherwise use
61 # %WIRESHARK_TARGET_PLATFORM%.
62
63 if(WIN32)
64         find_package(PowerShell REQUIRED)
65
66         if(CMAKE_CL_64 OR CMAKE_GENERATOR MATCHES "Win64")
67                 set(WIRESHARK_TARGET_PLATFORM win64)
68         elseif(CMAKE_GENERATOR MATCHES "Visual Studio")
69                 set(WIRESHARK_TARGET_PLATFORM win32)
70         else()
71                 set(WIRESHARK_TARGET_PLATFORM $ENV{WIRESHARK_TARGET_PLATFORM})
72         endif()
73
74         if(WIRESHARK_TARGET_PLATFORM MATCHES "win64")
75                 set(WIRESHARK_TARGET_PROCESSOR_ARCHITECTURE amd64)
76         else()
77                 set(WIRESHARK_TARGET_PROCESSOR_ARCHITECTURE x86)
78         endif()
79
80         # Sanity check
81         if(DEFINED ENV{PLATFORM})
82                 string(TOLOWER $ENV{PLATFORM} _vs_platform)
83         else()
84                 set(_vs_platform "[undefined]") # x86
85         endif()
86         if(
87                 (_vs_platform STREQUAL "x64" AND NOT WIRESHARK_TARGET_PLATFORM STREQUAL "win64")
88                 OR
89                 (_vs_platform STREQUAL "[undefined]" AND NOT WIRESHARK_TARGET_PLATFORM STREQUAL "win32")
90         )
91                 message(FATAL_ERROR "The PLATFORM environment variable (${_vs_platform})"
92                         " doesn't match the generator platform (${WIRESHARK_TARGET_PLATFORM})")
93         endif()
94         message(STATUS "Building for ${WIRESHARK_TARGET_PLATFORM} using ${CMAKE_GENERATOR}")
95
96         # Determine where the 3rd party libraries will be
97         if( DEFINED ENV{WIRESHARK_LIB_DIR} )
98                 # The buildbots set WIRESHARK_LIB_DIR but not WIRESHARK_BASE_DIR.
99                 file( TO_CMAKE_PATH "$ENV{WIRESHARK_LIB_DIR}" _PROJECT_LIB_DIR )
100         elseif( DEFINED ENV{WIRESHARK_BASE_DIR} )
101                 file( TO_CMAKE_PATH "$ENV{WIRESHARK_BASE_DIR}" _WS_BASE_DIR )
102                 set( _PROJECT_LIB_DIR "${_WS_BASE_DIR}/wireshark-${WIRESHARK_TARGET_PLATFORM}-libs" )
103         else()
104                 # Don't know what to do
105                 message(FATAL_ERROR "Neither WIRESHARK_BASE_DIR or WIRESHARK_LIB_DIR are defined")
106         endif()
107
108         # Download third-party libraries
109         file (TO_NATIVE_PATH ${CMAKE_SOURCE_DIR}/tools/win-setup.ps1 _win_setup)
110         file (TO_NATIVE_PATH ${_PROJECT_LIB_DIR} _ws_lib_dir)
111
112         # Is it possible to have a one-time, non-cached option in CMake? If
113         # so, we could add a "-DFORCE_WIN_SETUP" which passes -Force to
114         # win-setup.ps1.
115         execute_process(
116                 COMMAND ${POWERSHELL_COMMAND} "\"${_win_setup}\"" -Destination "${_ws_lib_dir}" -Platform ${WIRESHARK_TARGET_PLATFORM}
117                 RESULT_VARIABLE _win_setup_failed
118         )
119         if(_win_setup_failed)
120                 message(FATAL_ERROR "Windows setup (win-setup.ps1) failed.")
121         endif()
122
123         set(EXTRA_INSTALLER_DIR ${_ws_lib_dir})
124
125         # XXX Add a dependency on ${_ws_lib_dir}/current_tag.txt?
126
127         # Prepopulate some ConfigureChecks values. Compilation checks
128         # on Windows can be slow.
129         set(HAVE_FCNTL_H TRUE)
130         set(HAVE_FLOORL TRUE)
131 endif(WIN32)
132
133 include(UseCustomIncludes)
134 ADD_CUSTOM_CMAKE_INCLUDE()
135
136 # This cannot be implemented via option(...)
137 if( NOT CMAKE_BUILD_TYPE )
138         set( CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
139                 "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
140                 FORCE)
141 endif()
142 message(STATUS "CMake build type: ${CMAKE_BUILD_TYPE}")
143
144 # Ensure that all executables and libraries end up in the same directory. Actual
145 # files might end up in a configuration subdirectory, e.g. run/Debug or
146 # run/Release. We try to set DATAFILE_DIR to actual location below.
147 if(NOT ARCHIVE_OUTPUT_PATH)
148         set(ARCHIVE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/run CACHE INTERNAL
149                    "Single output directory for building all archives.")
150 endif()
151 if(NOT EXECUTABLE_OUTPUT_PATH)
152         set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/run CACHE INTERNAL
153                    "Single output directory for building all executables.")
154 endif()
155 if(NOT LIBRARY_OUTPUT_PATH)
156         set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/run CACHE INTERNAL
157                    "Single output directory for building all libraries.")
158 endif()
159
160 #
161 # The release mode (CMAKE_BUILD_TYPE=release) defines NDEBUG for
162 # the Unix Makefile generator.
163 #
164
165 # Defines CMAKE_INSTALL_BINDIR, CMAKE_INSTALL_DATADIR, etc ...
166 if(WIN32)
167         # Override some values on Windows, to match the existing
168         # convention of installing everything to a single root folder.
169         set(CMAKE_INSTALL_BINDIR ".")
170         set(CMAKE_INSTALL_LIBDIR ".")
171         set(CMAKE_INSTALL_INCLUDEDIR "include")
172         set(CMAKE_INSTALL_DATADIR ".")
173         set(CMAKE_INSTALL_DOCDIR ".")
174 else()
175         # By default INSTALL_DATADIR is set to INSTALL_DATAROOTDIR, set the
176         # proper value here.
177         set(CMAKE_INSTALL_DATADIR "share/${PROJECT_NAME}"
178                 CACHE PATH "Read-only architecture-independent data"
179         )
180 endif()
181 include(GNUInstallDirs)
182
183 set(PROJECT_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}")
184
185 # Make sure our executables can can load our libraries if we install into
186 # a non-default directory on Unix-like systems other than macOS.
187 # https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling
188 set(LIBRARY_INSTALL_RPATH "")
189 set(EXECUTABLE_INSTALL_RPATH "")
190 set(EXTCAP_INSTALL_RPATH "")
191 if(NOT (WIN32 OR APPLE OR USE_STATIC))
192         # Try to set a RPATH for installed binaries if the library directory is
193         # not already included in the default search list.
194         list(FIND CMAKE_C_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_FULL_LIBDIR}" IS_SYSTEM_DIR)
195         if(IS_SYSTEM_DIR EQUAL -1)
196                 # Some systems support $ORIGIN in RPATH to enable relocatable
197                 # binaries. In other cases, only absolute paths can be used.
198                 # https://www.lekensteyn.nl/rpath.html
199                 if(CMAKE_SYSTEM_NAME MATCHES "^(Linux|SunOS|FreeBSD)$")
200                         set(_enable_rpath_origin TRUE)
201                         if(BUILD_dumpcap AND ENABLE_PCAP)
202                                 # dumpcap will most likely be installed with
203                                 # capabilities or setuid. Relative RPATHs that
204                                 # resolve to non-standard library directories
205                                 # are ignored for such binaries and since we
206                                 # cannot achieve relocatable builds, just
207                                 # disable it by default.
208                                 set(_enable_rpath_origin FALSE)
209                         endif()
210                         # Provide a knob to optionally force absolute rpaths,
211                         # to support old/buggy systems and as a user preference
212                         # for hardening.
213                         set(ENABLE_RPATH_ORIGIN ${_enable_rpath_origin} CACHE BOOL
214                                 "Use $ORIGIN with INSTALL_RPATH")
215                         mark_as_advanced(ENABLE_RPATH_ORIGIN)
216                 else()
217                         set(ENABLE_RPATH_ORIGIN FALSE)
218                 endif()
219                 if(ENABLE_RPATH_ORIGIN)
220                         set(LIBRARY_INSTALL_RPATH     "$ORIGIN")
221                         set(EXECUTABLE_INSTALL_RPATH  "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")
222                         set(EXTCAP_INSTALL_RPATH      "$ORIGIN/../..")
223                 else()
224                         set(LIBRARY_INSTALL_RPATH     "${CMAKE_INSTALL_FULL_LIBDIR}")
225                         set(EXECUTABLE_INSTALL_RPATH  "${CMAKE_INSTALL_FULL_LIBDIR}")
226                         set(EXTCAP_INSTALL_RPATH      "${CMAKE_INSTALL_FULL_LIBDIR}")
227                 endif()
228                 # Include non-standard external libraries by default in RPATH.
229                 if(NOT DEFINED CMAKE_INSTALL_RPATH_USE_LINK_PATH)
230                         set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
231                 endif()
232         endif()
233 endif()
234
235 # Ensure that executables in the build directory always have the same RPATH.
236 # This ensures relocatable binaries and reproducible builds (invariant of the
237 # build directory location). (Requires CMake 3.14)
238 set(CMAKE_BUILD_RPATH_USE_ORIGIN ON)
239
240 if(WIN32)
241     # Linking with wsetargv.obj enables "wildcard expansion" of
242     # command-line arguments.
243     set(WILDCARD_OBJ wsetargv.obj)
244 endif(WIN32)
245
246 # Banner shown at top right of Qt welcome screen.
247 if(DEFINED ENV{WIRESHARK_VERSION_FLAVOR})
248         set(VERSION_FLAVOR "$ENV{WIRESHARK_VERSION_FLAVOR}")
249 else()
250         set(VERSION_FLAVOR "Development Build")
251 endif()
252
253 # These are required in .rc files and manifests
254 set(VERSION_MAJOR ${PROJECT_MAJOR_VERSION})
255 set(VERSION_MINOR ${PROJECT_MINOR_VERSION})
256 set(VERSION_MICRO ${PROJECT_PATCH_VERSION})
257 set(VERSION_BUILD ${PROJECT_BUILD_VERSION})
258 set(RC_VERSION ${PROJECT_MAJOR_VERSION},${PROJECT_MINOR_VERSION},${PROJECT_PATCH_VERSION},${PROJECT_BUILD_VERSION})
259
260 message(STATUS "V: ${PROJECT_VERSION}, MaV: ${PROJECT_MAJOR_VERSION}, MiV: ${PROJECT_MINOR_VERSION}, PL: ${PROJECT_PATCH_VERSION}, EV: ${PROJECT_VERSION_EXTENSION}.")
261
262 include(UseLemon)
263 include(UseMakePluginReg)
264 include(UseMakeTaps)
265 include(UseExecutableResources)
266 include(UseAsn2Wrs)
267
268 # The following snippet has been taken from
269 # https://github.com/USESystemEngineeringBV/cmake-eclipse-helper/wiki/HowToWorkaroundIndexer
270 # The eclipse indexer otherwise assumes __cplusplus=199711L which will lead to broken
271 # lookup tables for the epan libraries
272 # Check if CXX flags have been set to c++11 -> Setup Eclipse Indexer correctly!
273 # Also setup the project slightly different
274 if(CMAKE_EXTRA_GENERATOR MATCHES "Eclipse CDT4")
275         SET(CXX_ENABLED 0)
276         LIST(LENGTH CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS LIST_LEN)
277         if(LIST_LEN GREATER 0)
278                 SET(CXX_ENABLED 1)
279         endif()
280         SET(C_ENABLED 0)
281         LIST(LENGTH CMAKE_EXTRA_GENERATOR_C_SYSTEM_DEFINED_MACROS LIST_LEN)
282         if(LIST_LEN GREATER 0)
283                 SET(C_ENABLED 1)
284         endif()
285         if(C_ENABLED EQUAL 1 AND CXX_ENABLED EQUAL 1)
286                 # Combined project (C and CXX). This will confuse the indexer. For that reason
287                 # we unsert set the __cplusplus variable for the indexer
288                 list(FIND CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS "__cplusplus" GEN_MACRO_INDEX)
289                 if(GEN_MACRO_INDEX GREATER -1)
290                         list(REMOVE_AT CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS ${GEN_MACRO_INDEX})
291                         list(REMOVE_AT CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS ${GEN_MACRO_INDEX})
292                 endif()
293                 SET(CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS ${CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS} CACHE INTERNAL "")
294         elseif((CXX_ENABLED EQUAL 1) AND (CMAKE_CXX_FLAGS MATCHES ".*-std=c\\+\\+11.*"))
295                 #add_definitions (-D__cplusplus=201103L)
296                 # CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS
297                 list(FIND CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS "199711L" GEN_MACRO_INDEX)
298                 if(GEN_MACRO_INDEX GREATER -1)
299                         list(REMOVE_AT CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS ${GEN_MACRO_INDEX})
300                         list(INSERT CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS ${GEN_MACRO_INDEX} "201103L")
301                         SET(CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS ${CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS} CACHE INTERNAL "")
302                 endif()
303         endif()
304 endif()
305
306 include_directories(
307         ${CMAKE_BINARY_DIR}
308         ${CMAKE_SOURCE_DIR}
309 )
310
311 if( DUMPCAP_INSTALL_OPTION STREQUAL "suid" )
312         set( DUMPCAP_SETUID "SETUID" )
313 else()
314         set( DUMPCAP_SETUID )
315 endif()
316 if( NOT CMAKE_SYSTEM_NAME STREQUAL "Linux" AND
317         DUMPCAP_INSTALL_OPTION STREQUAL "capabilities" )
318         message( WARNING "Capabilities are only supported on Linux" )
319         set( DUMPCAP_INSTALL_OPTION )
320 endif()
321
322 set(OSS_FUZZ OFF CACHE BOOL "Whether building for oss-fuzz")
323 mark_as_advanced(OSS_FUZZ)
324 if(OSS_FUZZ)
325         if(ENABLE_FUZZER)
326                 # In oss-fuzz mode, the fuzzing engine can be afl or libFuzzer.
327                 message(FATAL_ERROR "Cannot force libFuzzer when using oss-fuzz")
328         endif()
329         # Must not depend on external dependencies so statically link all libs.
330         set(USE_STATIC ON)
331 endif()
332
333 if(USE_STATIC)
334         set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
335 endif()
336
337 #
338 # Linking can consume a lot of memory, especially when built with ASAN and
339 # static libraries (like oss-fuzz) or Debug mode. With Ninja, the number of
340 # parallel linker processes is constrained by job parallelism (-j), but this can
341 # be reduced further by setting "job pools" to a lower number.
342 #
343 if(CMAKE_MAKE_PROGRAM MATCHES "ninja" AND OSS_FUZZ)
344         # Assume oss-fuzz linker jobs do not require more than 1.2G per task
345         set(per_job_memory_mb 1200)
346         cmake_host_system_information(RESULT total_memory_mb QUERY TOTAL_PHYSICAL_MEMORY)
347         math(EXPR parallel_link_jobs "${total_memory_mb} / ${per_job_memory_mb}")
348         if(parallel_link_jobs LESS 1)
349                 set(parallel_link_jobs 1)
350         endif()
351         set_property(GLOBAL APPEND PROPERTY JOB_POOLS link_job_pool=${parallel_link_jobs})
352         set(CMAKE_JOB_POOL_LINK link_job_pool)
353         message(STATUS "Ninja job pool size: ${parallel_link_jobs}")
354 endif()
355
356 # Always enable position-independent code when compiling, even for
357 # executables, so you can build position-independent executables.
358 # -pie is added below for non-MSVC, but requires objects to be built with
359 # -fPIC/-fPIE (so set CMAKE_POSITION_INDEPENDENT_CODE to enable that).
360 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
361
362 # Path to our generated executables (or wrapper scripts)
363 if(WIN32)
364         set(WS_PROGRAM_PATH ./run/$<CONFIG>)
365 else()
366         set(WS_PROGRAM_PATH ./run)
367 endif()
368
369 if( CMAKE_C_COMPILER_ID MATCHES "MSVC")
370         if ((MSVC_VERSION LESS "1900") OR (MSVC_VERSION GREATER_EQUAL "2000"))
371                 message(FATAL_ERROR "You are using an unsupported version of MSVC")
372         endif()
373
374         add_definitions(
375                 /DWIN32_LEAN_AND_MEAN
376                 /D_CRT_SECURE_NO_DEPRECATE
377                 # NOMINMAX keeps windows.h from defining "min" and "max" via windef.h.
378                 # This avoids conflicts with the C++ standard library.
379                 /DNOMINMAX
380                 # -DPSAPI_VERSION=1                 Programs that must run on earlier versions of Windows as well as Windows 7 and later
381                 #                                   versions should always call this function as GetProcessMemoryInfo. To ensure correct
382                 #                                   resolution of symbols, add Psapi.lib to the TARGETLIBS macro and compile the program
383                 #                                   with -DPSAPI_VERSION=1.To use run-time dynamic linking, load Psapi.dll.
384                 #                                   https://docs.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getprocessmemoryinfo
385                 # -D_ALLOW_KEYWORD_MACROS           For VS2012 onwards the, C++ STL does not permit macro redefinitions of keywords
386                 #                                   (see https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2012/bb531344(v=vs.110))
387                 #                                   This definition prevents the complaint about the redefinition of inline by WinPCap
388                 #                                   in pcap-stdinc.h when compiling C++ files, e.g. the Qt UI
389                 /DPSAPI_VERSION=1
390                 /D_ALLOW_KEYWORD_MACROS
391         )
392
393         if(NOT WIRESHARK_TARGET_PLATFORM STREQUAL "win64")
394                 add_definitions("/D_BIND_TO_CURRENT_CRT_VERSION=1")
395         endif()
396
397         set(LOCAL_CFLAGS
398                 /MP
399         )
400
401         set(WS_LINK_FLAGS "/LARGEADDRESSAWARE /MANIFEST:NO /INCREMENTAL:NO /RELEASE")
402
403         # To do: Add /external:... See https://devblogs.microsoft.com/cppblog/broken-warnings-theory/
404         #
405         # /Zo                               Enhanced debugging of optimised code
406         # /utf-8                            Set Source and Executable character sets to UTF-8
407         #                                   VS2015(MSVC14): On by default when /Zi or /Z7 used.
408         # /guard:cf                         Control Flow Guard (compile and link).
409         #                                   See https://docs.microsoft.com/en-us/windows/win32/secbp/control-flow-guard
410         #                                   Note: This requires CMake 3.9.0 or newer.
411         #                                   https://gitlab.kitware.com/cmake/cmake/commit/f973d49ab9d4c59b93f6dac812a94bb130200836
412         # /Qspectre                         Speculative execution attack mitigation
413         #                                   See https://devblogs.microsoft.com/cppblog/spectre-mitigations-in-msvc/
414         list(APPEND LOCAL_CFLAGS /Zo /utf-8 /guard:cf)
415         set(WS_LINK_FLAGS "${WS_LINK_FLAGS} /guard:cf")
416         # /Qspectre is not available for VS2015 or older VS2017. Test for its availability.
417         set(WIRESHARK_COMMON_FLAGS /Qspectre)
418
419         if(ENABLE_CODE_ANALYSIS)
420                 list(APPEND LOCAL_CFLAGS /analyze:WX-)
421         endif()
422
423         # Additional compiler warnings to be treated as "Level 3"
424         # when compiling Wireshark sources. (Selected from "level 4" warnings).
425         ## 4295: array is too small to include a terminating null character
426         ## 4100: unreferenced formal parameter
427         ## 4189: local variable is initialized but not referenced
428         # Disable warnings about about use of flexible array members:
429         ## 4200: nonstandard extension used : zero-sized array in struct/union
430         list(APPEND LOCAL_CFLAGS /w34295 /w34100 /w34189 /wd4200)
431
432         # We've matched these to specific compiler versions using the
433         # checks above. There's no need to pass them to check_c_compiler_flag
434         # or check_cxx_compiler_flag, which can be slow.
435         string(REPLACE ";" " " _flags "${LOCAL_CFLAGS}")
436         set(CMAKE_C_FLAGS "${_flags} ${CMAKE_C_FLAGS}")
437         set(CMAKE_CXX_FLAGS "${_flags} ${CMAKE_CXX_FLAGS}")
438
439 else() # ! MSVC
440         if(APPLE)
441                 set(MIN_MACOS_VERSION 10.6) # Arbitrary.
442                 if(CMAKE_OSX_DEPLOYMENT_TARGET)
443                         if(CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS MIN_MACOS_VERSION)
444                                 message(FATAL_ERROR "We don't support building for macOS < ${MIN_MACOS_VERSION}")
445                         endif()
446                         set(MIN_MACOS_VERSION ${CMAKE_OSX_DEPLOYMENT_TARGET})
447                         message(STATUS "Building for Mac OS X/OS X/macOS ${CMAKE_OSX_DEPLOYMENT_TARGET}")
448                 endif()
449         elseif(CMAKE_OSX_DEPLOYMENT_TARGET)
450                 message(FATAL_ERROR "CMAKE_OSX_DEPLOYMENT_TARGET only applies when building for macOS")
451         endif()
452
453         #
454         # Do whatever is necessary to enable as much C99 support as
455         # possible in the C compiler.  Newer versions of compilers
456         # might default to supporting C99, but older versions may
457         # require a special flag.
458         #
459         # We do not want strict C99 support, as we may also want to
460         # use compiler extensions.
461         #
462         # Prior to CMake 3.1, setting CMAKE_C_STANDARD will not have
463         # any effect, so, unless and until we require CMake 3.1 or
464         # later, we have to do it ourselves on pre-3.1 CMake, so we
465         # just do it ourselves on all versions of CMake.
466         #
467         # Note: with CMake 3.1 through 3.5, the only compilers for
468         # which CMake handles CMAKE_C_STANDARD are GCC and Clang.
469         # 3.6 adds support only for Intel C; 3.9 adds support for
470         # PGI C, Sun C, and IBM XL C, and 3.10 adds support for
471         # Cray C and IAR C, but no version of CMake has support for
472         # HP C.  Therefore, even if we use CMAKE_C_STANDARD with
473         # compilers for which CMake supports it, we may still have
474         # to do it ourselves on other compilers.
475         #
476         # In addition, CMake 3.5.2 seems to think that GCC versions
477         # less than 4.4 don't support -std=gnu99, which we need in
478         # order to get support for "for (int i = 0; i < n; i++) ;",
479         # which is another reason not to rely on CMake's CMAKE_C_STANDARD
480         # support.
481         #
482         # See the CMake documentation for the CMAKE_<LANG>_COMPILER_ID
483         # variables for a list of compiler IDs.
484         #
485         # We don't worry about MSVC; it doesn't have such a flag -
486         # either it doesn't support the C99 features we need at all,
487         # or it supports them regardless of the compiler flag.
488         #
489         # XXX - we add the flag for a given compiler to CMAKE_C_FLAGS,
490         # so we test whether it works and add it if we do.  We don't
491         # test whether it's necessary in order to get the C99 features
492         # that we use; if we ever have a user who tries to compile with
493         # a compiler that can't be made to support those features, we
494         # can add a test to make sure we actually *have* C99 support.
495         #
496         if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR
497            CMAKE_C_COMPILER_ID MATCHES "Clang")
498                 #
499                 # We use -std=gnu99 rather than -std=c99 because, for
500                 # some older compilers such as GCC 4.4.7, -std=gnu99
501                 # is required to avoid errors about C99 constructs
502                 # such as "for (int i = 0; i < n; i++) ;".
503                 #
504                 set(CMAKE_C_FLAGS "-std=gnu99 ${CMAKE_C_FLAGS}")
505         elseif(CMAKE_C_COMPILER_ID MATCHES "XL")
506                 #
507                 # We want support for extensions picked up for
508                 # GNU C compatibility, so we use -qlanglvl=extc99.
509                 #
510                 set(CMAKE_C_FLAGS "-qlanglvl=extc99 ${CMAKE_C_FLAGS}")
511         elseif(CMAKE_C_COMPILER_ID MATCHES "HP")
512                 #
513                 # We also need to add -Wp,-H200000 to handle some large
514                 # #defines we have; that flag is not necessary for the
515                 # C++ compiler unless the "legacy" C++ preprocessor is
516                 # being used (+legacy_cpp).  We don't want the legacy
517                 # preprocessor if it's not the default, so we just add
518                 # -Wp,-H200000 to the C flags.  (If there are older
519                 # versions of aC++ that only support the legacy
520                 # preprocessor, and require that we boost the table
521                 # size, we'd have to check whether -Wp,-H200000 is
522                 # supported by the C++ compiler and add it only if it is.)
523                 #
524                 set(CMAKE_C_FLAGS "-AC99 -Wp,-H200000 $WS_CFLAGS ${CMAKE_C_FLAGS}")
525         elseif(CMAKE_C_COMPILER_ID MATCHES "Sun")
526                 #
527                 # We also crank up the warning level.
528                 #
529                 set(CMAKE_C_FLAGS "-xc99 -v ${CMAKE_C_FLAGS}")
530         elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
531                 set(CMAKE_C_FLAGS "-c99 ${CMAKE_C_FLAGS}")
532         endif()
533
534         if(CMAKE_C_COMPILER_ID MATCHES "Clang")
535                 set(WIRESHARK_COMMON_FLAGS ${WIRESHARK_COMMON_FLAGS}
536                         # avoid "argument unused during compilation" warnings
537                         # (for example, when getting the -gsplit-dwarf option or
538                         # when combining -fwrapv with -fno-strict-overflow)
539                         -Qunused-arguments
540                 )
541         else()
542                 set(WIRESHARK_COMMON_FLAGS ${WIRESHARK_COMMON_FLAGS}
543                         -fexcess-precision=fast
544                 )
545         endif()
546
547         list(APPEND WIRESHARK_COMMON_FLAGS
548                 # The following are for C and C++
549                 # -O<X> and -g get set by the CMAKE_BUILD_TYPE
550                 -Wall
551                 -Wextra
552                 -Wendif-labels
553                 -Wpointer-arith
554                 -Wformat-security
555                 -fwrapv
556                 -fno-strict-overflow
557                 -Wvla
558                 -Waddress
559                 -Wattributes
560                 -Wdiv-by-zero
561                 -Wignored-qualifiers
562                 -Wpragmas
563                 -Wno-overlength-strings
564                 -Wno-long-long
565                 -Wheader-guard
566                 -Wcomma
567                 -Wshorten-64-to-32
568         )
569
570         #
571         # Code that may be worth looking into (coding practices)
572         #
573         if((NOT ENABLE_ASAN) AND (NOT ENABLE_TSAN) AND (NOT ENABLE_UBSAN) AND (NOT DISABLE_FRAME_LARGER_THAN_WARNING))
574                 #
575                 # Only do this if none of ASan, TSan, and UBSan are
576                 # enabled; the instrumentation they add increases
577                 # the stack usage - we only care about stack
578                 # usage in normal operation.
579                 #
580                 set(WIRESHARK_COMMON_FLAGS ${WIRESHARK_COMMON_FLAGS}
581                         -Wframe-larger-than=32768
582                 )
583         endif()
584
585         list(APPEND WIRESHARK_C_ONLY_FLAGS
586                 # The following are C only, not C++
587                 -Wc++-compat
588                 -Wunused-const-variable
589                 #
590                 # XXX - some versions of GCC, including the one in at
591                 # least some Xcode versions that come with Mac OS X
592                 # 10.5, complain about variables in function and
593                 # function pointer *declarations* shadowing other
594                 # variables.  The autoconf script checked for that; we
595                 # don't.
596                 -Wshadow
597                 -Wold-style-definition
598                 -Wstrict-prototypes
599                 #
600                 # Some versions of GCC, such as 4.3.2 and 4.4.5,
601                 # generate logical-op warnings when strchr() is given a
602                 # constant string.  The autoconf script checked for that;
603                 # we don't.
604                 #
605                 -Wlogical-op
606                 -Wjump-misses-init
607                 #
608                 # Implicit function declarations are an error in C++ and most
609                 # likely a programming error in C. Turn -Wimplicit-int and
610                 # -Wimplicit-function-declaration into an error by default.
611                 #
612                 -Werror=implicit
613         )
614
615         #
616         # The universal zero initializer (in C: struct s x = { 0 };) for
617         # structures with multiple members is perfectly legal, but some older
618         # compilers warn about it. Silence those older compilers.
619         #
620         if((CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "5.1") OR
621            (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "6.0") OR
622            (CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "10.0"))
623                 if(NOT CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_VERSION VERSION_LESS "4.7")
624                         list(APPEND WIRESHARK_C_ONLY_FLAGS -Wno-missing-field-initializers)
625                 endif()
626                 # Silence warnings for initialization of nested structs like
627                 # struct { struct { int a, b; } s; int c; } v = { 0 };
628                 list(APPEND WIRESHARK_C_ONLY_FLAGS -Wno-missing-braces)
629         endif()
630
631
632         list(APPEND WIRESHARK_CXX_ONLY_FLAGS
633                 -Wextra-semi
634         )
635
636         #
637         # These are not enabled by default, because the warnings they
638         # produce are very hard or impossible to eliminate.
639         #
640         if(ENABLE_EXTRA_COMPILER_WARNINGS)   # This overrides -Werror
641                 list(APPEND WIRESHARK_COMMON_FLAGS
642                         # The following are for C and C++
643                         -Wpedantic
644                         #
645                         # As we use variadic macros, we don't want warnings
646                         # about them, even with -Wpedantic.
647                         #
648                         -Wno-variadic-macros
649                         #
650                         # Various code blocks this one.
651                         #
652                         -Woverflow
653                         -fstrict-overflow -Wstrict-overflow=4
654                         #
655                         # Due to various places where APIs we don't control
656                         # require us to cast away constness, we can probably
657                         # never enable this one with -Werror.
658                         #
659                         -Wcast-qual
660                         #
661                         # Some generated ASN.1 dissectors block this one;
662                         # multiple function declarations for the same
663                         # function are being generated.
664                         #
665                         -Wredundant-decls
666                         #
667                         # All the registration functions block these for now.
668                         #
669                         -Wmissing-prototypes
670                         -Wmissing-declarations
671                         #
672                         # A bunch of "that might not work on SPARC" code blocks
673                         # this one for now; some of it is code that *will* work
674                         # on SPARC, such as casts of "struct sockaddr *" to
675                         # "struct sockaddr_in *", which are required by some
676                         # APIs such as getifaddrs().
677                         #
678                         -Wcast-align
679                         #
680                         # Works only with Clang
681                         #
682                         -Wunreachable-code
683                         #
684                         # Works only with Clang but generates a lot of warnings
685                         # (about glib library not using Doxygen)
686                         #
687                         -Wdocumentation
688                         #
689                         # Works only with GCC 7
690                         #
691                         -Wduplicated-branches
692                         #
693                         # No longer supported by El Capitan clang on C++
694                         # XXX - is this one of those where CMake's check
695                         # doesn't fail, so it won't reject this?
696                         #
697                         -fno-delete-null-pointer-checks
698                 )
699
700                 #
701                 # Some loops are safe, but it's hard to convince the compiler of
702                 # that. Always disable the warning on GCC 7 due to a bug that
703                 # cause lots of false positives.
704                 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81408
705                 #
706                 if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_C_COMPILER_VERSION MATCHES "^7\\.")
707                         list(APPEND WIRESHARK_COMMON_FLAGS -Wunsafe-loop-optimizations)
708                 endif()
709
710                 list(APPEND WIRESHARK_C_ONLY_FLAGS
711                         # The following are C only, not C++
712                         #
713                         # Due to various places where APIs we don't control
714                         # require us to cast away constness, we can probably
715                         # never enable this one with -Werror.
716                         #
717                         -Wbad-function-cast
718                 )
719
720                 list(APPEND WIRESHARK_CXX_ONLY_FLAGS
721                 )
722         else()
723                 #
724                 # -Wpointer-sign is a default test we get with -Wall and
725                 # -W, but for some reason we were suppressing it -
726                 # unconditionally.  Suppress it only without the extra
727                 # warnings, so we can at least see how much we get.
728                 # (This would have caught at least one error - the one
729                 # in change https://code.wireshark.org/review/33234,
730                 # which would have suggested that the wrong
731                 # proto_tree_add_ret_ call was being used.)
732                 #
733                 list(APPEND WIRESHARK_C_ONLY_FLAGS
734                         -Wno-pointer-sign
735                 )
736         endif()
737
738         add_definitions(
739                 -DG_DISABLE_DEPRECATED
740                 -DG_DISABLE_SINGLE_INCLUDES
741         )
742
743         set(WIRESHARK_LD_FLAGS
744                 # See also CheckCLinkerFlag.cmake
745                 -Wl,--as-needed
746                 # -flto
747                 # -fwhopr
748                 # -fwhole-program
749         )
750 endif() # ! MSVC
751
752 # Counterhack to work around some cache magic in CHECK_C_SOURCE_COMPILES
753 include(CheckCCompilerFlag)
754 include(CheckCXXCompilerFlag)
755
756 if(ENABLE_STATIC)
757         set(BUILD_SHARED_LIBS 0)
758 else()
759         set(BUILD_SHARED_LIBS 1)
760 endif()
761
762 function(test_compiler_flag _lang _this_flag _valid_flags_var)
763         string(MAKE_C_IDENTIFIER "${_lang}${_this_flag}_VALID" _flag_var)
764         set(_test_flags "${${_valid_flags_var}} ${_this_flag}")
765         if(_lang STREQUAL "C")
766                 check_c_compiler_flag("${_test_flags}" ${_flag_var})
767         elseif(_lang STREQUAL "CXX")
768                 check_cxx_compiler_flag("${_test_flags}" ${_flag_var})
769         else()
770                 message(FATAL_ERROR "Language must be C or CXX")
771         endif()
772         if (${_flag_var})
773                 set(${_valid_flags_var} "${_test_flags}" PARENT_SCOPE)
774         endif()
775 endfunction()
776
777 foreach(THIS_FLAG ${WIRESHARK_COMMON_FLAGS} ${WIRESHARK_C_ONLY_FLAGS})
778         test_compiler_flag(C ${THIS_FLAG} ADDED_CMAKE_C_FLAGS)
779 endforeach()
780 set(CMAKE_C_FLAGS "${ADDED_CMAKE_C_FLAGS} ${CMAKE_C_FLAGS}")
781
782 foreach(THIS_FLAG ${WIRESHARK_COMMON_FLAGS} ${WIRESHARK_CXX_ONLY_FLAGS})
783         test_compiler_flag(CXX ${THIS_FLAG} ADDED_CMAKE_CXX_FLAGS)
784 endforeach()
785 set(CMAKE_CXX_FLAGS "${ADDED_CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS}")
786
787 # Strips the source and build directory prefix from the __FILE__ macro to ensure
788 # reproducible builds. Supported since GCC 8, Clang support is pending.
789 if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang")
790         # If the build dir is within the source dir, CMake will use something
791         # like ../epan/dfilter/semcheck.c. Map these relative paths in addition
792         # to CMAKE_BINARY_DIR since compile_commands.json uses absolute paths.
793         file(RELATIVE_PATH _relative_source_dir "${CMAKE_BINARY_DIR}" "${CMAKE_SOURCE_DIR}")
794         string(REGEX REPLACE "/$" "" _relative_source_dir "${_relative_source_dir}")
795
796         check_c_compiler_flag(-fmacro-prefix-map=old=new C_fmacro_prefix_map_old_new_VALID)
797         check_cxx_compiler_flag(-fmacro-prefix-map=old=new CXX_fmacro_prefix_map_old_new_VALID)
798         foreach(_lang C CXX)
799                 if(${_lang}_fmacro_prefix_map_old_new_VALID)
800                         set(_flags CMAKE_${_lang}_FLAGS)
801                         set(${_flags} "${${_flags}} -fmacro-prefix-map=${CMAKE_SOURCE_DIR}/=")
802                         set(${_flags} "${${_flags}} -fmacro-prefix-map=${CMAKE_BINARY_DIR}/=")
803                         if(_relative_source_dir MATCHES "\\.\\.$")
804                                 set(${_flags} "${${_flags}} -fmacro-prefix-map=${_relative_source_dir}/=")
805                         endif()
806                 endif()
807         endforeach()
808 endif()
809
810 include(CMakePushCheckState)
811
812 if(ENABLE_ASAN)
813         cmake_push_check_state()
814         set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=address")
815         check_c_compiler_flag(-fsanitize=address C__fsanitize_address_VALID)
816         check_cxx_compiler_flag(-fsanitize=address CXX__fsanitize_address_VALID)
817         cmake_pop_check_state()
818         if(NOT C__fsanitize_address_VALID OR NOT CXX__fsanitize_address_VALID)
819                 message(FATAL_ERROR "ENABLE_ASAN was requested, but not supported!")
820         endif()
821         set(CMAKE_C_FLAGS "-fsanitize=address ${CMAKE_C_FLAGS}")
822         set(CMAKE_CXX_FLAGS "-fsanitize=address ${CMAKE_CXX_FLAGS}")
823         # Disable ASAN for build-time tools, e.g. lemon
824         check_c_compiler_flag(-fno-sanitize=all C__fno_sanitize_all_VALID)
825         if(C__fno_sanitize_all_VALID)
826                 set(NO_SANITIZE_CFLAGS "-fno-sanitize=all")
827                 set(NO_SANITIZE_LDFLAGS "-fno-sanitize=all")
828         endif()
829 endif()
830
831 if(ENABLE_TSAN)
832         # Available since Clang >= 3.2 and GCC >= 4.8
833         cmake_push_check_state()
834         set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=thread")
835         check_c_compiler_flag(-fsanitize=thread C__fsanitize_thread_VALID)
836         check_cxx_compiler_flag(-fsanitize=thread CXX__fsanitize_thread_VALID)
837         cmake_pop_check_state()
838         if(NOT C__fsanitize_thread_VALID OR NOT CXX__fsanitize_thread_VALID)
839                 message(FATAL_ERROR "ENABLE_TSAN was requested, but not supported!")
840         endif()
841         set(CMAKE_C_FLAGS "-fsanitize=thread ${CMAKE_C_FLAGS}")
842         set(CMAKE_CXX_FLAGS "-fsanitize=thread ${CMAKE_CXX_FLAGS}")
843         set(WS_LINK_FLAGS "-fsanitize=thread ${WS_LINK_FLAGS}")
844 endif()
845
846 if(ENABLE_UBSAN)
847         # Available since Clang >= 3.3 and GCC >= 4.9
848         cmake_push_check_state()
849         set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=undefined")
850         check_c_compiler_flag(-fsanitize=undefined C__fsanitize_undefined_VALID)
851         check_cxx_compiler_flag(-fsanitize=undefined CXX__fsanitize_undefined_VALID)
852         cmake_pop_check_state()
853         if(NOT C__fsanitize_undefined_VALID OR NOT CXX__fsanitize_undefined_VALID)
854                 message(FATAL_ERROR "ENABLE_UBSAN was requested, but not supported!")
855         endif()
856         set(CMAKE_C_FLAGS "-fsanitize=undefined ${CMAKE_C_FLAGS}")
857         set(CMAKE_CXX_FLAGS "-fsanitize=undefined ${CMAKE_CXX_FLAGS}")
858 endif()
859
860 if(ENABLE_FUZZER)
861         # Available since Clang >= 6
862         # Will enable coverage flags which can be used by the fuzzshark target.
863         cmake_push_check_state()
864         set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=fuzzer-no-link")
865         check_c_compiler_flag(-fsanitize=fuzzer C__fsanitize_fuzzer_no_link_VALID)
866         check_cxx_compiler_flag(-fsanitize=fuzzer CXX__fsanitize_fuzzer_no_link_VALID)
867         cmake_pop_check_state()
868         if(NOT C__fsanitize_fuzzer_no_link_VALID OR NOT CXX__fsanitize_fuzzer_no_link_VALID)
869                 message(FATAL_ERROR "ENABLE_FUZZER was requested, but not supported!")
870         endif()
871         set(CMAKE_C_FLAGS "-fsanitize=fuzzer-no-link ${CMAKE_C_FLAGS}")
872         set(CMAKE_CXX_FLAGS "-fsanitize=fuzzer-no-link ${CMAKE_CXX_FLAGS}")
873 endif()
874
875 set(WERROR_COMMON_FLAGS "")
876 if(NOT DISABLE_WERROR AND NOT ENABLE_EXTRA_COMPILER_WARNINGS)
877         if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
878                 set(WERROR_COMMON_FLAGS "/WX")
879         else()
880                 #
881                 # If a warning has been enabled by -Wall or -W,
882                 # and have specified -Werror, there appears to be
883                 # no way, in Apple's llvm-gcc, to prevent that
884                 # particular warning from giving an error - not
885                 # with a pragma, not with -Wno-{warning}, and not
886                 # with -Wno-error={warning}.
887                 #
888                 # Therefore, with that compiler, we just disable
889                 # -Werror.
890                 #
891                 if ((NOT APPLE) OR CMAKE_C_COMPILER_ID MATCHES "Clang")
892                         check_c_compiler_flag(-Werror WERROR)
893                         if (WERROR)
894                                 set(WERROR_COMMON_FLAGS "-Werror")
895                         endif()
896                 endif()
897         endif()
898 endif()
899
900 #
901 # Try to have the compiler default to hiding symbols, so that only
902 # symbols explicitly exported with WS_DLL_PUBLIC will be visible
903 # outside (shared) libraries; that way, more UN*X builds will catch
904 # failures to export symbols, rather than having that fail only on
905 # Windows.
906 #
907 # We don't need that with MSVC, as that's the default.
908 #
909 if( NOT CMAKE_C_COMPILER_ID MATCHES "MSVC")
910         #
911         # Try the GCC-and-compatible -fvisibility-hidden first.
912         #
913         check_c_compiler_flag(-fvisibility=hidden FVHIDDEN)
914         if(FVHIDDEN)
915                 set(CMAKE_C_FLAGS "-fvisibility=hidden ${CMAKE_C_FLAGS}")
916         else()
917                 #
918                 # OK, try the Sun^WOracle C -xldscope=hidden
919                 #
920                 check_c_compiler_flag(-xldscope=hidden XLDSCOPEHIDDEN)
921                 if(XLDSCOPEHIDDEN)
922                         set(CMAKE_C_FLAGS "-xldscope=hidden ${CMAKE_C_FLAGS}")
923                 else()
924                         #
925                         # Anything else?
926                         # If there is anything else, we might want to
927                         # make a list of options to try, and try them
928                         # in a loop.
929                         #
930                         message(WARNING "Hiding shared library symbols is not supported by the compiler."
931                                 " All shared library symbols will be exported.")
932                 endif()
933         endif()
934 endif()
935
936 include(CheckCLinkerFlag)
937
938 if(NOT CMAKE_C_COMPILER_ID MATCHES "MSVC" AND NOT OSS_FUZZ)
939         #
940         # The -pie linker option produces a position-independent executable.
941         # Some Linux distributions have this enabled by default in the compiler,
942         # so setting it here will be superfluous though.
943         #
944         # Note that linking with static libraries that are not position
945         # independent may fail, the user can set CMAKE_EXE_LINKER_FLAGS=-no-pie
946         # as a workaround.
947         #
948         if(CMAKE_VERSION VERSION_LESS "3.14")
949                 check_c_linker_flag(-pie LINK_pie_VALID)
950                 if(LINK_pie_VALID)
951                         set(CMAKE_EXE_LINKER_FLAGS "-pie ${CMAKE_EXE_LINKER_FLAGS}")
952                 endif()
953         else()
954                 include(CheckPIESupported)
955                 check_pie_supported()
956         endif()
957 endif()
958
959 foreach(THIS_FLAG ${WIRESHARK_LD_FLAGS})
960         string(MAKE_C_IDENTIFIER "LINK${THIS_FLAG}_VALID" _flag_var)
961         check_c_linker_flag(${THIS_FLAG} ${_flag_var})
962         if (${_flag_var})
963                 set(WS_LINK_FLAGS "${WS_LINK_FLAGS} ${THIS_FLAG}")
964         endif()
965 endforeach()
966 message(STATUS "Linker flags: ${WS_LINK_FLAGS}")
967
968 if(APPLE AND EXISTS /usr/local/opt/gettext)
969         # GLib on macOS requires libintl. Homebrew installs gettext (and
970         # libintl) in /usr/local/opt/gettext
971         include_directories(/usr/local/opt/gettext/include)
972         link_directories(/usr/local/opt/gettext/lib)
973 endif()
974
975 # Resets cache variables if the <PackageName>_LIBRARY has become invalid.
976 # Call it before a find_package(<PackageName> ...) invocation that uses
977 # find_library(<PackageName>_LIBRARY ...).
978 #
979 # Usage: reset_find_package(<PackageName> [<extra variables to clear>])
980 function(reset_find_package _package_name)
981         set(variables
982                 # find_library / find_package
983                 ${_package_name}_LIBRARY
984                 ${_package_name}_INCLUDE_DIR
985                 # mark_as_advanced
986                 ${_package_name}_LIBRARIES
987                 ${_package_name}_INCLUDE_DIRS
988                 # Others
989                 ${_package_name}_DLL_DIR
990                 ${_package_name}_DLLS
991                 ${_package_name}_DLL
992                 ${_package_name}_PDB
993                 ${ARGN}
994         )
995         if(NOT ${_package_name}_LIBRARY OR EXISTS ${${_package_name}_LIBRARY})
996                 # Cache variable is already missing or cache entry is valid.
997                 return()
998         endif()
999         message(STATUS "Package ${_package_name} has changed, clearing cache.")
1000         foreach(_var IN LISTS variables)
1001                 unset(${_var} CACHE)
1002         endforeach()
1003 endfunction()
1004
1005 # ws_find_package(<PackageName>
1006 #             <CMakeOptions.txt boolean variable>
1007 #             <cmakeconfig.h.in macro definition>
1008 #             [remaining find_package() arguments])
1009 macro(ws_find_package _package_name _enable_package _package_cmakedefine)
1010         if(${_enable_package})
1011                 # Clear outdated cache variables if not already.
1012                 reset_find_package(${_package_name})
1013                 find_package(${_package_name} ${ARGN})
1014                 if(${_package_name}_FOUND)
1015                         set(${_package_cmakedefine} 1)
1016                 endif()
1017         endif()
1018 endmacro()
1019
1020 # The minimum package list
1021 find_package(Git)
1022 reset_find_package(GLIB2 GLIB2_MAIN_INCLUDE_DIR GLIB2_INTERNAL_INCLUDE_DIR)
1023 find_package(GLIB2 "2.32.0" REQUIRED)
1024 include_directories(SYSTEM ${GLIB2_INCLUDE_DIRS})
1025 reset_find_package(GMODULE2)
1026 find_package(GMODULE2)
1027 reset_find_package(GTHREAD2)
1028 find_package(GTHREAD2 REQUIRED)
1029 reset_find_package(GCRYPT GCRYPT_ERROR_LIBRARY)
1030 find_package(GCRYPT "1.4.2" REQUIRED)
1031 # C Asynchronous resolver
1032 reset_find_package(CARES)
1033 find_package(CARES "1.5.0" REQUIRED)
1034 find_package(LEX REQUIRED)
1035 find_package(YACC REQUIRED)
1036 find_package(Perl REQUIRED)
1037
1038 if(CMAKE_VERSION VERSION_LESS "3.12")
1039         # Locate the Python interpreter. Finds the wrong (Python 2) version if:
1040         # - PATH contains python3.6, but not python3 (3.4). Affects RHEL7+EPEL.
1041         # - Path contains C:\Python27 but not C:\Python37 (which is installed,
1042         #   but not present in PATH).
1043         find_package(PythonInterp 3.4 REQUIRED)
1044 else()
1045         find_package(Python3 3.4 REQUIRED)
1046         # Several files (including LocatePythonModule) still use the old name
1047         # from FindPythonInterp, let's stick to it for now.
1048         set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
1049 endif()
1050
1051 if (NOT WIN32)
1052         find_package(Gettext)
1053         find_package(M REQUIRED)
1054 endif()
1055
1056 if(BUILD_sshdump OR BUILD_ciscodump)
1057         set(ENABLE_LIBSSH ON)
1058 else()
1059         set(ENABLE_LIBSSH OFF)
1060 endif()
1061 ws_find_package(LIBSSH ENABLE_LIBSSH HAVE_LIBSSH "0.6")
1062
1063 ws_find_package(PCAP ENABLE_PCAP HAVE_LIBPCAP)
1064 ws_find_package(AIRPCAP ENABLE_AIRPCAP HAVE_AIRPCAP)
1065 ws_find_package(Systemd BUILD_sdjournal HAVE_SYSTEMD)
1066
1067 # Build the Qt GUI?
1068 if(BUILD_wireshark)
1069         # Untested, may not work if CMAKE_PREFIX_PATH gets overwritten
1070         # somewhere. The if WIN32 in this place is annoying as well.
1071         if(WIN32)
1072                 set(QT5_BASE_PATH "$ENV{QT5_BASE_DIR}")
1073                 set(CMAKE_PREFIX_PATH "${QT5_BASE_PATH}")
1074         endif()
1075         if(APPLE AND EXISTS /usr/local/opt/qt5)
1076                 # Homebrew installs Qt5 (up to at least 5.11.0) in
1077                 # /usr/local/qt5. Ensure that it can be found by CMake
1078                 # since it is not in the default /usr/local prefix.
1079                 # Add it to PATHS so that it doesn't override the
1080                 # CMAKE_PREFIX_PATH environment variable.
1081                 # QT_FIND_PACKAGE_OPTIONS should be passed to find_package,
1082                 # e.g. find_package(Qt5Core ${QT_FIND_PACKAGE_OPTIONS})
1083                 list(APPEND QT_FIND_PACKAGE_OPTIONS PATHS /usr/local/opt/qt5)
1084         endif()
1085         set(QT_PACKAGELIST
1086                 Qt5Core
1087                 Qt5LinguistTools
1088                 Qt5Multimedia
1089                 Qt5PrintSupport
1090                 Qt5Svg
1091                 Qt5Widgets
1092         )
1093         if(APPLE)
1094                 list(APPEND QT_PACKAGELIST Qt5MacExtras)
1095                 ws_find_package(Sparkle ENABLE_SPARKLE HAVE_SOFTWARE_UPDATE)
1096         endif()
1097         if(WIN32)
1098                 list(APPEND QT_PACKAGELIST Qt5WinExtras)
1099         endif()
1100         foreach(_qt_package IN LISTS QT_PACKAGELIST)
1101                 find_package(${_qt_package} REQUIRED ${QT_FIND_PACKAGE_OPTIONS})
1102                 list(APPEND QT_LIBRARIES ${${_qt_package}_LIBRARIES})
1103                 list(APPEND QT_INCLUDE_DIRS ${${_qt_package}_INCLUDE_DIRS})
1104                 list(APPEND QT_COMPILE_DEFINITIONS ${${_qt_package}_COMPILE_DEFINITIONS})
1105         endforeach()
1106         set(QT_FOUND ON)
1107         if(Qt5MacExtras_FOUND)
1108                 set(QT_MACEXTRAS_LIB 1)
1109         endif()
1110 endif()
1111
1112 # MaxMind DB address resolution
1113 ws_find_package(MaxMindDB BUILD_mmdbresolve HAVE_MAXMINDDB)
1114
1115 # SMI SNMP
1116 reset_find_package(SMI SMI_SHARE_DIR)
1117 ws_find_package(SMI ENABLE_SMI HAVE_LIBSMI)
1118
1119 # Support for TLS decryption using RSA private keys.
1120 ws_find_package(GNUTLS ENABLE_GNUTLS HAVE_LIBGNUTLS "3.2.0")
1121
1122 # Kerberos
1123 ws_find_package(KERBEROS ENABLE_KERBEROS HAVE_KERBEROS)
1124
1125 # Zlib compression
1126 ws_find_package(ZLIB ENABLE_ZLIB HAVE_ZLIB)
1127
1128 # Minizip compression
1129 ws_find_package(Minizip ENABLE_MINIZIP HAVE_MINIZIP)
1130
1131 # Brotli compression
1132 ws_find_package(BROTLI ENABLE_BROTLI HAVE_BROTLI)
1133
1134 # LZ4 compression
1135 ws_find_package(LZ4 ENABLE_LZ4 HAVE_LZ4)
1136
1137 # Snappy compression
1138 ws_find_package(SNAPPY ENABLE_SNAPPY HAVE_SNAPPY)
1139
1140 # zstd compression
1141 ws_find_package(ZSTD ENABLE_ZSTD HAVE_ZSTD "1.0.0")
1142
1143 # Enhanced HTTP/2 dissection
1144 ws_find_package(NGHTTP2 ENABLE_NGHTTP2 HAVE_NGHTTP2)
1145
1146 # Embedded Lua interpreter
1147 ws_find_package(LUA ENABLE_LUA HAVE_LUA "5.1")
1148
1149 ws_find_package(NL ENABLE_NETLINK HAVE_LIBNL)
1150
1151 ws_find_package(SBC ENABLE_SBC HAVE_SBC)
1152
1153 ws_find_package(SPANDSP ENABLE_SPANDSP HAVE_SPANDSP)
1154
1155 ws_find_package(BCG729 ENABLE_BCG729 HAVE_BCG729)
1156
1157 # CMake 3.9 and below used 'LIBXML2_LIBRARIES' as the name of the cache entry
1158 # storing the find_library result. Transfer it to the new cache variable such
1159 # that reset_find_package can detect and clear outdated cache variables.
1160 if(DEFINED LIBXML2_LIBRARIES AND NOT DEFINED LIBXML2_LIBRARY)
1161         set(LIBXML2_LIBRARY ${LIBXML2_LIBRARIES} CACHE FILEPATH "")
1162 endif()
1163 # Call reset_find_package explicitly since variables are in upper case.
1164 reset_find_package(LIBXML2)
1165 ws_find_package(LibXml2 ENABLE_LIBXML2 HAVE_LIBXML2)
1166 if(NOT LIBXML2_FOUND)
1167         # CMake 3.9 and below used LIBXML2_LIBRARIES as the name of
1168         # the cache entry storing the find_library result.
1169         # Current CMake (3.13) and below sets LIBXML2_LIBRARIES and LIBXML2_INCLUDE_DIRS
1170         # to a non-empty value, be sure to clear it when not found.
1171         set(LIBXML2_LIBRARIES "")
1172         set(LIBXML2_INCLUDE_DIRS "")
1173 endif()
1174
1175 # Capabilities
1176 ws_find_package(CAP ENABLE_CAP HAVE_LIBCAP)
1177 if(NOT WIN32)
1178         find_package(SETCAP)
1179 endif()
1180
1181 # Include minizip include directories
1182 if(MINIZIP_FOUND)
1183         include_directories(
1184                 ${MINIZIP_INCLUDE_DIRS}
1185         )
1186 else()
1187         set(MINIZIP_LIBRARY "")
1188 endif()
1189
1190 # Windows version updates
1191 ws_find_package(WINSPARKLE ENABLE_WINSPARKLE HAVE_SOFTWARE_UPDATE)
1192
1193 find_package( Asciidoctor 1.5 )
1194
1195 find_package(POD REQUIRED)
1196
1197 find_package(DOXYGEN)
1198
1199 # The SpeexDSP resampler is required iff building wireshark or sharkd.
1200 if(BUILD_wireshark OR BUILD_sharkd)
1201         find_package(SpeexDSP)
1202         if(SpeexDSP_FOUND)
1203                 set(HAVE_SPEEXDSP 1)
1204         else()
1205                 add_subdirectory(speexdsp)
1206                 set(SPEEXDSP_INCLUDE_DIRS "")
1207                 set(SPEEXDSP_LIBRARIES "speexresampler")
1208         endif()
1209 endif()
1210
1211 # dist target that prepares source dir
1212 # XXX Duplicated in the RPM section below.
1213 add_custom_target(dist
1214         COMMAND ${CMAKE_BINARY_DIR}/packaging/source/git-export-release.sh -d "${CMAKE_BINARY_DIR}"
1215         WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
1216 )
1217
1218 if(GNUTLS_FOUND AND NOT GNUTLS_VERSION VERSION_LESS "3.4.0")
1219         # While all Linux and Windows builds have PKCS #11 support enabled,
1220         # macos-setup.sh explicitly disables it using --without-p11-kit.
1221         #
1222         # Require at least GnuTLS 3.4.0 such that public keys can be calculated
1223         # from PKCS #11 private keys.
1224         include(CheckSymbolExists)
1225         cmake_push_check_state()
1226         if(WIN32)
1227                 set(CMAKE_REQUIRED_DEFINITIONS -Dssize_t=int)
1228         endif()
1229         set(CMAKE_REQUIRED_INCLUDES ${GNUTLS_INCLUDE_DIRS})
1230         set(CMAKE_REQUIRED_LIBRARIES ${GNUTLS_LIBRARIES})
1231         check_symbol_exists(gnutls_pkcs11_obj_list_import_url4 gnutls/pkcs11.h HAVE_GNUTLS_PKCS11)
1232         cmake_pop_check_state()
1233 endif()
1234
1235 if (QT_FOUND)
1236         if (Qt5Widgets_VERSION VERSION_LESS 5.2)
1237                 message(FATAL_ERROR "Qt 5.2 or later is required.")
1238         endif()
1239         if (Qt5Widgets_VERSION VERSION_GREATER 5.6
1240             AND (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang"))
1241                 # Qt 5.7 and later require C++ 11.
1242                 set(CMAKE_CXX_STANDARD 11)
1243                 set(CMAKE_CXX_STANDARD_REQUIRED ON)
1244         endif()
1245         if(NOT DEFINED MOC_OPTIONS)
1246                 # Squelch moc verbose "nothing to do" output
1247                 set(MOC_OPTIONS -nn)
1248         endif()
1249
1250         # CMake uses qmake to find Qt4. It relies on Qt's CMake modules
1251         # to find Qt5. This means that we can't assume that the qmake
1252         # in our PATH is the correct one. We can fetch qmake's location
1253         # from Qt5::qmake, which is is defined in Qt5CoreConfigExtras.cmake.
1254         get_target_property(QT_QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION)
1255         get_filename_component(_qt_bin_path "${QT_QMAKE_EXECUTABLE}" DIRECTORY)
1256         set(QT_BIN_PATH "${_qt_bin_path}" CACHE INTERNAL
1257                 "Path to qmake, macdeployqt, windeployqt, and other Qt utilities."
1258         )
1259         # Use qmake to find windeployqt and macdeployqt. Ideally one of
1260         # the modules in ${QTDIR}/lib/cmake would do this for us.
1261         if(WIN32)
1262                 find_program(QT_WINDEPLOYQT_EXECUTABLE windeployqt
1263                         HINTS "${QT_BIN_PATH}"
1264                         DOC "Path to the windeployqt utility."
1265                 )
1266                 if(Qt5Widgets_VERSION VERSION_GREATER "5.5.999")
1267                         set(QT_WINDEPLOYQT_EXTRA_OPTS --pdb)
1268                 endif()
1269
1270         elseif(APPLE)
1271                 find_program(QT_MACDEPLOYQT_EXECUTABLE macdeployqt
1272                         HINTS "${QT_BIN_PATH}"
1273                         DOC "Path to the macdeployqt utility."
1274                 )
1275                 find_program(DMGBUILD_EXECUTABLE dmgbuild
1276                         DOC "Path to the dmgbuild utility"
1277                 )
1278                 # https://doc.qt.io/qt-5.11/supported-platforms-and-configurations.html
1279                 # CMake < 3.7 doesn't support VERSION_GREATER_EQUAL.
1280                 if(Qt5Widgets_VERSION VERSION_GREATER "5.11.999")
1281                         set(MIN_MACOS_VERSION 10.12)
1282                 elseif(Qt5Widgets_VERSION VERSION_GREATER "5.9.999")
1283                         set(MIN_MACOS_VERSION 10.11)
1284                 elseif(Qt5Widgets_VERSION VERSION_GREATER "5.8.999")
1285                         set(MIN_MACOS_VERSION 10.10)
1286                 elseif(Qt5Widgets_VERSION VERSION_GREATER "5.7.999")
1287                         set(MIN_MACOS_VERSION 10.9)
1288                 elseif(Qt5Widgets_VERSION VERSION_GREATER "5.4.999")
1289                         set(MIN_MACOS_VERSION 10.8)
1290                 endif()
1291                 if(CMAKE_OSX_DEPLOYMENT_TARGET AND CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS MIN_MACOS_VERSION)
1292                         message(FATAL_ERROR "Qt version ${Qt5Widgets_VERSION} requires CMAKE_OSX_DEPLOYMENT_TARGET (${CMAKE_OSX_DEPLOYMENT_TARGET}) >= ${MIN_MACOS_VERSION}")
1293                 endif()
1294         endif()
1295
1296 endif()
1297
1298 if(ENABLE_CHECKHF_CONFLICT)
1299         set(ENABLE_CHECK_FILTER 1)
1300 endif()
1301
1302 #
1303 # Platform-specific additional libraries.
1304 #
1305 if(WIN32)
1306         set(WIN_PSAPI_LIBRARY    psapi.lib)
1307         set(WIN_WS2_32_LIBRARY   ws2_32.lib)
1308         set(WIN_COMCTL32_LIBRARY comctl32.lib )
1309         set(WIN_VERSION_LIBRARY  version.lib)
1310 endif()
1311
1312 if(APPLE)
1313         #
1314         # We assume that APPLE means macOS so that we have the macOS
1315         # frameworks.
1316         #
1317         set(HAVE_MACOS_FRAMEWORKS 1)
1318         FIND_LIBRARY (APPLE_APPLICATION_SERVICES_LIBRARY ApplicationServices)
1319         FIND_LIBRARY (APPLE_APPKIT_LIBRARY AppKit)
1320         FIND_LIBRARY (APPLE_CORE_FOUNDATION_LIBRARY CoreFoundation)
1321         FIND_LIBRARY (APPLE_SYSTEM_CONFIGURATION_LIBRARY SystemConfiguration)
1322 endif()
1323
1324 include(ConfigureChecks.cmake)
1325
1326 # Global properties
1327 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
1328
1329 if(ENABLE_CCACHE AND (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang"))
1330         # https://stackoverflow.com/questions/1815688/how-to-use-ccache-with-cmake/24305849#24305849
1331         find_program(CCACHE_EXECUTABLE ccache)
1332         if(CCACHE_EXECUTABLE)
1333                 set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_EXECUTABLE}")
1334                 set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCACHE_EXECUTABLE}")
1335         endif()
1336 endif()
1337
1338 # The top level checkAPIs target, add before subdirectory calls so it's avaiable to all
1339 add_custom_target(checkAPI)
1340 set_target_properties(checkAPI
1341         PROPERTIES
1342                 FOLDER "Auxiliary"
1343                 EXCLUDE_FROM_ALL True
1344                 EXCLUDE_FROM_DEFAULT_BUILD True
1345 )
1346
1347 include( UseCheckAPI )
1348
1349 # Target platform locations
1350 # UN*X in general, including macOS if not building an app bundle:
1351 # $DESTDIR/lib/wireshark/extcap
1352 # Windows: $DESTDIR/extcap
1353 # macOS app bundle: Wireshark.app/Contents/Resources/share/wireshark/extcap
1354 # If you change the nesting level be sure to check also the INSTALL_RPATH
1355 # target property.
1356 if (WIN32)
1357         set(EXTCAP_INSTALL_LIBDIR "extcap" CACHE INTERNAL "The extcap dir")
1358 else ()
1359         set(EXTCAP_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/extcap" CACHE INTERNAL "The extcap dir")
1360 endif()
1361
1362 if(APPLE)
1363         #
1364         # As https://developer.apple.com/library/archive/technotes/tn2206/_index.html
1365         # says,
1366         #
1367         # "Note that a location where code is expected to reside cannot generally
1368         # contain directories full of nested code, because those directories tend
1369         # to be interpreted as bundles. So this occasional practice is not
1370         # recommended and not officially supported. If you do do this, do not use
1371         # periods in the directory names. The code signing machinery interprets
1372         # directories with periods in their names as code bundles and will reject
1373         # them if they don't conform to the expected code bundle layout."
1374         #
1375         set(PLUGIN_PATH_ID "${PROJECT_MAJOR_VERSION}-${PROJECT_MINOR_VERSION}")
1376 else()
1377         set(PLUGIN_PATH_ID "${PROJECT_MAJOR_VERSION}.${PROJECT_MINOR_VERSION}")
1378 endif()
1379
1380 # Directory where plugins and Lua dissectors can be found.
1381 if(WIN32)
1382         set(PLUGIN_INSTALL_LIBDIR "plugins" CACHE INTERNAL "The plugin dir")
1383 else()
1384         set(PLUGIN_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/plugins" CACHE INTERNAL "The plugin dir")
1385 endif()
1386 set(PLUGIN_INSTALL_VERSION_LIBDIR "${PLUGIN_INSTALL_LIBDIR}/${PLUGIN_PATH_ID}")
1387 set(PLUGIN_VERSION_DIR "plugins/${PLUGIN_PATH_ID}")
1388
1389 add_subdirectory( capchild )
1390 add_subdirectory( caputils )
1391 add_subdirectory( doc )
1392 add_subdirectory( docbook EXCLUDE_FROM_ALL )
1393 add_subdirectory( epan )
1394 add_subdirectory( extcap )
1395 add_subdirectory( randpkt_core )
1396 add_subdirectory( tools/lemon )
1397 add_subdirectory( ui )
1398 add_subdirectory( wiretap )
1399 add_subdirectory( writecap )
1400
1401 # Location of our data files. This should be set to a value that allows
1402 # running from the build directory on Windows, on macOS when building an
1403 # application bundle, and on UNIX in general if
1404 # WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set.
1405 if(ENABLE_APPLICATION_BUNDLE)
1406         if(CMAKE_CFG_INTDIR STREQUAL ".")
1407                 set(_datafile_dir "${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/Resources/share/wireshark")
1408         else()
1409                 # Xcode
1410                 set(_datafile_dir "${CMAKE_BINARY_DIR}/run/${CMAKE_CFG_INTDIR}/Wireshark.app/Contents/Resources/share/wireshark")
1411         endif()
1412 elseif(NOT CMAKE_CFG_INTDIR STREQUAL ".")
1413         # Visual Studio, Xcode, etc.
1414         set(_datafile_dir "${CMAKE_BINARY_DIR}/run/${CMAKE_CFG_INTDIR}")
1415 else()
1416         # Makefile, Ninja, etc.
1417         set(_datafile_dir "${CMAKE_BINARY_DIR}/run")
1418 endif()
1419
1420 set(DATAFILE_DIR ${_datafile_dir} CACHE INTERNAL "Build time data file location.")
1421
1422 # wsutil must be added after DATAFILE_DIR is set such that filesystem.c can
1423 # learn about the directory location.
1424 add_subdirectory( wsutil )
1425
1426 if(BUILD_wireshark AND QT_FOUND)
1427         add_subdirectory( ui/qt )
1428 endif()
1429
1430 # Location of our plugins. PLUGIN_DIR should allow running
1431 # from the build directory similar to DATAFILE_DIR above.
1432 if(ENABLE_PLUGINS)
1433         # Target platform locations
1434         # UN*X in general, including macOS if not building an app bundle:
1435         # $DESTDIR/lib/wireshark/plugins/$VERSION
1436         # Windows: $DESTDIR/wireshark/plugins/$VERSION
1437         # macOS app bundle: Wireshark.app/Contents/PlugIns/wireshark
1438         set(HAVE_PLUGINS 1)
1439         add_custom_target(plugins)
1440         set_target_properties(plugins PROPERTIES FOLDER "Plugins")
1441         set(PLUGIN_SRC_DIRS
1442                 plugins/epan/ethercat
1443                 plugins/epan/gryphon
1444                 plugins/epan/irda
1445                 plugins/epan/mate
1446                 plugins/epan/opcua
1447                 plugins/epan/profinet
1448                 plugins/epan/stats_tree
1449                 plugins/epan/transum
1450                 plugins/epan/unistim
1451                 plugins/epan/wimax
1452                 plugins/epan/wimaxasncp
1453                 plugins/epan/wimaxmacphy
1454                 plugins/wiretap/usbdump
1455                 plugins/codecs/G711
1456                 plugins/codecs/l16_mono
1457                 ${CUSTOM_PLUGIN_SRC_DIR}
1458         )
1459         if(SPANDSP_FOUND)
1460                 list(APPEND PLUGIN_SRC_DIRS
1461                         plugins/codecs/G722
1462                         plugins/codecs/G726
1463                 )
1464         endif()
1465         if(BCG729_FOUND)
1466                 list(APPEND PLUGIN_SRC_DIRS
1467                         plugins/codecs/G729
1468                 )
1469         endif()
1470         if(SBC_FOUND)
1471                 list(APPEND PLUGIN_SRC_DIRS
1472                         plugins/codecs/sbc
1473                 )
1474         endif()
1475
1476         # Build demo plugin, only if asked explicitly
1477         if(ENABLE_PLUGIN_IFDEMO)
1478                 set(PLUGIN_SRC_DIRS
1479                         ${PLUGIN_SRC_DIRS}
1480                         plugins/epan/pluginifdemo
1481                 )
1482         endif()
1483
1484 else()
1485         set(PLUGIN_SRC_DIRS )
1486 endif()
1487
1488 if(ENABLE_APPLICATION_BUNDLE)
1489         if(CMAKE_CFG_INTDIR STREQUAL ".")
1490                 set(_plugin_dir "${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/PlugIns/wireshark/${PLUGIN_PATH_ID}")
1491         else()
1492                 # Xcode
1493                 set(_plugin_dir "${CMAKE_BINARY_DIR}/run/$<CONFIG>/Wireshark.app/Contents/PlugIns/wireshark/${PLUGIN_PATH_ID}")
1494         endif()
1495 elseif(WIN32 AND NOT CMAKE_CFG_INTDIR STREQUAL ".")
1496         set(_plugin_dir "${CMAKE_BINARY_DIR}/run/$<CONFIG>/${PLUGIN_VERSION_DIR}")
1497 else()
1498         set(_plugin_dir "${DATAFILE_DIR}/${PLUGIN_VERSION_DIR}")
1499 endif()
1500 set (PLUGIN_DIR ${_plugin_dir} CACHE INTERNAL "Build time plugin location.")
1501
1502 foreach(_plugin_src_dir ${PLUGIN_SRC_DIRS})
1503         add_subdirectory( ${_plugin_src_dir} )
1504 endforeach()
1505
1506 if(ENABLE_PCAP_NG_DEFAULT)
1507         set(PCAP_NG_DEFAULT 1)
1508 endif()
1509
1510 # Large file support (e.g. make off_t 64 bit if supported)
1511 include(gmxTestLargeFiles)
1512 gmx_test_large_files(GMX_LARGEFILES)
1513
1514 set( VERSION ${PROJECT_VERSION} )
1515 if(VCSVERSION_OVERRIDE)
1516         # Allow distributors to override detection of the Git tag and version.
1517         string(CONFIGURE "#define VCSVERSION \"@VCSVERSION_OVERRIDE@\"\n"
1518                 _version_h_contents ESCAPE_QUOTES)
1519         file(WRITE "${CMAKE_BINARY_DIR}/version.h" "${_version_h_contents}")
1520         message(STATUS "VCSVERSION_OVERRIDE: ${VCSVERSION_OVERRIDE}")
1521 else()
1522         add_custom_target(version
1523                 BYPRODUCTS version.h
1524                 COMMAND ${PERL_EXECUTABLE}
1525                         ${CMAKE_SOURCE_DIR}/tools/make-version.pl
1526                         ${CMAKE_SOURCE_DIR}
1527         )
1528         set_target_properties(version PROPERTIES FOLDER "Auxiliary")
1529 endif()
1530
1531 set( configure_input "Built with CMake ${CMAKE_VERSION}" )
1532 configure_file(${CMAKE_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_BINARY_DIR}/config.h)
1533
1534 configure_file(${CMAKE_SOURCE_DIR}/ws_version.h.in ${CMAKE_BINARY_DIR}/ws_version.h)
1535
1536 set( prefix "${CMAKE_INSTALL_PREFIX}" )
1537 set( exec_prefix "\${prefix}" )
1538 set( libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}" )
1539 set( includedir  "\${prefix}/include" )
1540 set( plugindir "\${libdir}/wireshark/${PLUGIN_VERSION_DIR}" )
1541
1542 # Doxygen variables
1543 file(GLOB TOP_LEVEL_SOURCE_LIST *.c *.cpp *.h)
1544 string (REPLACE ";" " " DOXYGEN_TOP_LEVEL_SOURCES "${TOP_LEVEL_SOURCE_LIST}")
1545 set(DOXYGEN_INPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
1546 set(DOXYGEN_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
1547
1548 set(CFG_OUT_FILES
1549         doxygen.cfg
1550         image/libwireshark.rc
1551         image/wireshark.rc
1552         image/dumpcap.rc
1553         image/libwsutil.rc
1554         image/wiretap.rc
1555         image/wireshark.exe.manifest
1556         packaging/macosx/Info.plist
1557         packaging/macosx/dmgbuild-settings.py
1558         packaging/macosx/osx-app.sh
1559         packaging/macosx/osx-dmg.sh
1560         packaging/source/git-export-release.sh
1561         wireshark.pc
1562 )
1563 foreach( _cfg_file ${CFG_OUT_FILES} )
1564         configure_file( ${CMAKE_SOURCE_DIR}/${_cfg_file}.in ${CMAKE_BINARY_DIR}/${_cfg_file} @ONLY )
1565 endforeach()
1566
1567 include(FeatureSummary)
1568 set_package_properties(SBC PROPERTIES
1569         DESCRIPTION "Bluetooth low-complexity, subband codec (SBC) decoder"
1570         URL "https://git.kernel.org/pub/scm/bluetooth/sbc.git"
1571         PURPOSE "Support for playing SBC codec in RTP player"
1572 )
1573 set_package_properties(SPANDSP PROPERTIES
1574         DESCRIPTION "a library of many DSP functions for telephony"
1575         URL "https://www.soft-switch.org"
1576         PURPOSE "Support for G.722 and G.726 codecs in RTP player"
1577 )
1578 set_package_properties(BCG729 PROPERTIES
1579         DESCRIPTION "G.729 decoder"
1580         URL "https://www.linphone.org/technical-corner/bcg729/overview"
1581         PURPOSE "Support for G.729 codec in RTP player"
1582 )
1583 set_package_properties(LIBXML2 PROPERTIES
1584         DESCRIPTION "XML parsing library"
1585         URL "http://xmlsoft.org/"
1586         PURPOSE "Read XML configuration files in EPL dissector"
1587 )
1588 set_package_properties(LIBSSH PROPERTIES
1589         DESCRIPTION "Library for implementing SSH clients"
1590         URL "https://www.libssh.org/"
1591         PURPOSE "extcap remote SSH interfaces (sshdump, ciscodump)"
1592 )
1593 set_package_properties(LZ4 PROPERTIES
1594         DESCRIPTION "LZ4 is lossless compression algorithm used in some protocol (CQL...)"
1595         URL "http://www.lz4.org"
1596         PURPOSE "LZ4 decompression in CQL and Kafka dissectors"
1597 )
1598 set_package_properties(SNAPPY PROPERTIES
1599         DESCRIPTION "A fast compressor/decompressor from Google"
1600         URL "https://google.github.io/snappy/"
1601         PURPOSE "Snappy decompression in CQL and Kafka dissectors"
1602 )
1603 set_package_properties(ZSTD PROPERTIES
1604         DESCRIPTION "A compressor/decompressor from Facebook providing better compression than Snappy at a cost of speed"
1605         URL "https://facebook.github.io/zstd/"
1606         PURPOSE "Zstd decompression in Kafka dissector"
1607 )
1608 set_package_properties(NGHTTP2 PROPERTIES
1609         DESCRIPTION "HTTP/2 C library and tools"
1610         URL "https://nghttp2.org"
1611         PURPOSE "Header decompression in HTTP2"
1612 )
1613 set_package_properties(CARES PROPERTIES
1614         DESCRIPTION "Library for asynchronous DNS requests"
1615         URL "https://c-ares.haxx.se/"
1616         PURPOSE "DNS name resolution for captures"
1617 )
1618 set_package_properties(Systemd PROPERTIES
1619         URL "https://freedesktop.org/wiki/Software/systemd/"
1620         DESCRIPTION "System and Service Manager (libraries)"
1621         PURPOSE "Support for systemd journal extcap interface (sdjournal)"
1622 )
1623 set_package_properties(NL PROPERTIES
1624         URL "https://www.infradead.org/~tgr/libnl/"
1625         DESCRIPTION "Libraries for using the Netlink protocol on Linux"
1626         PURPOSE "Support for managing wireless 802.11 interfaces"
1627 )
1628 set_package_properties(MaxMindDB PROPERTIES
1629         URL "https://github.com/maxmind/libmaxminddb"
1630         DESCRIPTION "C library for the MaxMind DB file format"
1631         PURPOSE "Support for GeoIP lookup"
1632 )
1633 set_package_properties(SpeexDSP PROPERTIES
1634         URL "https://www.speex.org/"
1635         DESCRIPTION "SpeexDSP is a patent-free, Open Source/Free Software DSP library"
1636         PURPOSE "RTP audio resampling"
1637 )
1638 set_package_properties(Minizip PROPERTIES
1639         URL "https://www.winimage.com/zLibDll/minizip.html"
1640         DESCRIPTION "C library for supporting zip/unzip functionality"
1641         PURPOSE "Support for profiles import/export"
1642 )
1643
1644 string(TOUPPER "${CMAKE_BUILD_TYPE}" _build_type)
1645 message(STATUS "C-Flags: ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${_build_type}}")
1646 message(STATUS "CXX-Flags: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${_build_type}}")
1647 if(WERROR_COMMON_FLAGS)
1648         message(STATUS "Warnings as errors enabled: ${WERROR_COMMON_FLAGS}")
1649 else()
1650         message(STATUS "Warnings as errors disabled")
1651 endif()
1652
1653 feature_summary(WHAT ALL)
1654
1655 # Should this be part of libui?
1656 if(WIN32)
1657         set(PLATFORM_UI_SRC
1658                 ui/win32/console_win32.c
1659                 ui/win32/file_dlg_win32.c
1660         )
1661         set(PLATFORM_UI_RC_FILES
1662                 image/file_dlg_win32.rc
1663         )
1664 elseif(APPLE)
1665         set(PLATFORM_UI_SRC
1666                 ui/macosx/cocoa_bridge.mm
1667         )
1668         if (SPARKLE_FOUND)
1669                 list(APPEND PLATFORM_UI_SRC ui/macosx/sparkle_bridge.m)
1670         endif()
1671 endif()
1672
1673 set(TSHARK_TAP_SRC
1674         ${CMAKE_SOURCE_DIR}/ui/cli/tap-credentials.c
1675         ${CMAKE_SOURCE_DIR}/ui/cli/tap-camelsrt.c
1676         ${CMAKE_SOURCE_DIR}/ui/cli/tap-diameter-avp.c
1677         ${CMAKE_SOURCE_DIR}/ui/cli/tap-expert.c
1678         ${CMAKE_SOURCE_DIR}/ui/cli/tap-exportobject.c
1679         ${CMAKE_SOURCE_DIR}/ui/cli/tap-endpoints.c
1680         ${CMAKE_SOURCE_DIR}/ui/cli/tap-flow.c
1681         ${CMAKE_SOURCE_DIR}/ui/cli/tap-follow.c
1682         ${CMAKE_SOURCE_DIR}/ui/cli/tap-funnel.c
1683         ${CMAKE_SOURCE_DIR}/ui/cli/tap-gsm_astat.c
1684         ${CMAKE_SOURCE_DIR}/ui/cli/tap-hosts.c
1685         ${CMAKE_SOURCE_DIR}/ui/cli/tap-httpstat.c
1686         ${CMAKE_SOURCE_DIR}/ui/cli/tap-icmpstat.c
1687         ${CMAKE_SOURCE_DIR}/ui/cli/tap-icmpv6stat.c
1688         ${CMAKE_SOURCE_DIR}/ui/cli/tap-iostat.c
1689         ${CMAKE_SOURCE_DIR}/ui/cli/tap-iousers.c
1690         ${CMAKE_SOURCE_DIR}/ui/cli/tap-macltestat.c
1691         ${CMAKE_SOURCE_DIR}/ui/cli/tap-protocolinfo.c
1692         ${CMAKE_SOURCE_DIR}/ui/cli/tap-protohierstat.c
1693         ${CMAKE_SOURCE_DIR}/ui/cli/tap-rlcltestat.c
1694         ${CMAKE_SOURCE_DIR}/ui/cli/tap-rpcprogs.c
1695         ${CMAKE_SOURCE_DIR}/ui/cli/tap-rtd.c
1696         ${CMAKE_SOURCE_DIR}/ui/cli/tap-rtp.c
1697         ${CMAKE_SOURCE_DIR}/ui/cli/tap-rtspstat.c
1698         ${CMAKE_SOURCE_DIR}/ui/cli/tap-sctpchunkstat.c
1699         ${CMAKE_SOURCE_DIR}/ui/cli/tap-simple_stattable.c
1700         ${CMAKE_SOURCE_DIR}/ui/cli/tap-sipstat.c
1701         ${CMAKE_SOURCE_DIR}/ui/cli/tap-smbsids.c
1702         ${CMAKE_SOURCE_DIR}/ui/cli/tap-srt.c
1703         ${CMAKE_SOURCE_DIR}/ui/cli/tap-stats_tree.c
1704         ${CMAKE_SOURCE_DIR}/ui/cli/tap-sv.c
1705         ${CMAKE_SOURCE_DIR}/ui/cli/tap-wspstat.c
1706         ${CUSTOM_TSHARK_TAP_SRC}
1707
1708 )
1709
1710 set(INSTALL_DIRS
1711         diameter
1712         dtds
1713         profiles
1714         radius
1715         tpncp
1716         wimaxasncp
1717 )
1718
1719 set(INSTALL_FILES
1720         cfilters
1721         colorfilters
1722         dfilters
1723         dfilter_macros
1724         enterprises.tsv
1725         ipmap.html
1726         manuf
1727         pdml2html.xsl
1728         services
1729         smi_modules
1730         wka
1731         docbook/ws.css
1732         ${CMAKE_BINARY_DIR}/doc/AUTHORS-SHORT
1733         ${CMAKE_BINARY_DIR}/doc/androiddump.html
1734         ${CMAKE_BINARY_DIR}/doc/udpdump.html
1735         ${CMAKE_BINARY_DIR}/doc/capinfos.html
1736         ${CMAKE_BINARY_DIR}/doc/captype.html
1737         ${CMAKE_BINARY_DIR}/doc/ciscodump.html
1738         ${CMAKE_BINARY_DIR}/doc/dftest.html
1739         ${CMAKE_BINARY_DIR}/doc/dumpcap.html
1740         ${CMAKE_BINARY_DIR}/doc/editcap.html
1741         ${CMAKE_BINARY_DIR}/doc/extcap.html
1742         ${CMAKE_BINARY_DIR}/doc/mergecap.html
1743         ${CMAKE_BINARY_DIR}/doc/randpkt.html
1744         ${CMAKE_BINARY_DIR}/doc/randpktdump.html
1745         ${CMAKE_BINARY_DIR}/doc/rawshark.html
1746         ${CMAKE_BINARY_DIR}/doc/reordercap.html
1747         ${CMAKE_BINARY_DIR}/doc/sshdump.html
1748         ${CMAKE_BINARY_DIR}/doc/text2pcap.html
1749         ${CMAKE_BINARY_DIR}/doc/tshark.html
1750         ${CMAKE_BINARY_DIR}/doc/wireshark.html
1751         ${CMAKE_BINARY_DIR}/doc/wireshark-filter.html
1752 )
1753
1754 if(MAXMINDDB_FOUND)
1755         list(APPEND INSTALL_FILES ${CMAKE_BINARY_DIR}/doc/mmdbresolve.html)
1756 endif()
1757
1758 if (BUILD_corbaidl2wrs)
1759         list(APPEND INSTALL_FILES ${CMAKE_BINARY_DIR}/doc/idl2wrs.html)
1760 endif()
1761 if (BUILD_xxx2deb)
1762         list(APPEND INSTALL_FILES
1763                 ${CMAKE_BINARY_DIR}/doc/asn2deb.html
1764                 ${CMAKE_BINARY_DIR}/doc/idl2deb.html
1765         )
1766 endif()
1767
1768 if(WIN32)
1769         set(TEXTIFY_FILES COPYING NEWS README.windows)
1770         set(TEXTIFY_MD_FILES README.md)
1771         foreach(_text_file ${TEXTIFY_FILES} ${TEXTIFY_MD_FILES})
1772                 string(REGEX REPLACE ".md$" "" _out_file ${_text_file})
1773                 set(INSTALL_FILES ${CMAKE_BINARY_DIR}/${_out_file}.txt ${INSTALL_FILES})
1774         endforeach()
1775 else()
1776         set(INSTALL_FILES COPYING ${INSTALL_FILES})
1777 endif()
1778
1779 set(VERSION_INFO_LIBS
1780         ${ZLIB_LIBRARIES}
1781 )
1782 set(VERSION_INFO_INCLUDE_DIRS
1783         ${ZLIB_INCLUDE_DIRS}
1784 )
1785
1786 if(WIN32)
1787         set(_dll_output_dir "${DATAFILE_DIR}")
1788         add_custom_target(copy_cli_dlls)
1789         set_target_properties(copy_cli_dlls PROPERTIES FOLDER "Copy Tasks")
1790         add_custom_command(TARGET copy_cli_dlls PRE_BUILD
1791                 COMMAND ${CMAKE_COMMAND} -E make_directory "${_dll_output_dir}"
1792         )
1793
1794         # XXX Can (and should) we iterate over these similar to the way
1795         # the top-level CMakeLists.txt iterates over the package list?
1796
1797         # Required DLLs and their corresponding PDBs.
1798         add_custom_command(TARGET copy_cli_dlls PRE_BUILD
1799                 COMMAND ${CMAKE_COMMAND} -E copy_if_different
1800                         "$<IF:$<CONFIG:Debug>,${GLIB2_DLLS_DEBUG},${GLIB2_DLLS_RELEASE}>"
1801                         "$<IF:$<CONFIG:Debug>,${GLIB2_PDBS_DEBUG},${GLIB2_PDBS_RELEASE}>"
1802                         "${_dll_output_dir}"
1803                 WORKING_DIRECTORY $<IF:$<CONFIG:Debug>,${GLIB2_DLL_DIR_DEBUG},${GLIB2_DLL_DIR_RELEASE}>
1804                 COMMAND_EXPAND_LISTS
1805         )
1806
1807         # Optional DLLs and PDBs.
1808         set (OPTIONAL_DLLS)
1809         set (OPTIONAL_PDBS)
1810         if (AIRPCAP_FOUND)
1811                 list (APPEND OPTIONAL_DLLS "${AIRPCAP_DLL_DIR}/${AIRPCAP_DLL}")
1812         endif(AIRPCAP_FOUND)
1813         if (CARES_FOUND)
1814                 list (APPEND OPTIONAL_DLLS "${CARES_DLL_DIR}/${CARES_DLL}")
1815                 list (APPEND OPTIONAL_PDBS "${CARES_DLL_DIR}/${CARES_PDB}")
1816         endif(CARES_FOUND)
1817         if (MAXMINDDB_FOUND)
1818                 list (APPEND OPTIONAL_DLLS "${MAXMINDDB_DLL_DIR}/${MAXMINDDB_DLL}")
1819         endif(MAXMINDDB_FOUND)
1820         if (LIBSSH_FOUND)
1821                 list (APPEND OPTIONAL_DLLS "${LIBSSH_DLL_DIR}/${LIBSSH_DLL}")
1822         endif(LIBSSH_FOUND)
1823         foreach( _dll ${GCRYPT_DLLS} )
1824                 list (APPEND OPTIONAL_DLLS "${GCRYPT_DLL_DIR}/${_dll}")
1825         endforeach(_dll)
1826         foreach( _dll ${GNUTLS_DLLS} )
1827                 list (APPEND OPTIONAL_DLLS "${GNUTLS_DLL_DIR}/${_dll}")
1828         endforeach(_dll)
1829         foreach( _dll ${KERBEROS_DLLS} )
1830                 list (APPEND OPTIONAL_DLLS "${KERBEROS_DLL_DIR}/${_dll}")
1831         endforeach(_dll)
1832         if (LUA_FOUND)
1833                 list (APPEND OPTIONAL_DLLS "${LUA_DLL_DIR}/${LUA_DLL}")
1834         endif(LUA_FOUND)
1835         if (LZ4_FOUND)
1836                 list (APPEND OPTIONAL_DLLS "${LZ4_DLL_DIR}/${LZ4_DLL}")
1837                 list (APPEND OPTIONAL_PDBS "${LZ4_DLL_DIR}/${LZ4_PDB}")
1838         endif(LZ4_FOUND)
1839         if (ZSTD_FOUND)
1840                 list (APPEND OPTIONAL_DLLS "${ZSTD_DLL_DIR}/${ZSTD_DLL}")
1841         endif(ZSTD_FOUND)
1842         if (NGHTTP2_FOUND)
1843                 list (APPEND OPTIONAL_DLLS "${NGHTTP2_DLL_DIR}/${NGHTTP2_DLL}")
1844                 list (APPEND OPTIONAL_PDBS "${NGHTTP2_DLL_DIR}/${NGHTTP2_PDB}")
1845         endif(NGHTTP2_FOUND)
1846         if (SBC_FOUND)
1847                 list (APPEND OPTIONAL_DLLS "${SBC_DLL_DIR}/${SBC_DLL}")
1848         endif(SBC_FOUND)
1849         if (SPANDSP_FOUND)
1850                 list (APPEND OPTIONAL_DLLS "${SPANDSP_DLL_DIR}/${SPANDSP_DLL}")
1851         endif(SPANDSP_FOUND)
1852         if (BCG729_FOUND)
1853                 list (APPEND OPTIONAL_DLLS "${BCG729_DLL_DIR}/${BCG729_DLL}")
1854         endif(BCG729_FOUND)
1855         if (LIBXML2_FOUND)
1856                 foreach( _dll ${LIBXML2_DLLS} )
1857                         list (APPEND OPTIONAL_DLLS "${LIBXML2_DLL_DIR}/${_dll}")
1858                 endforeach(_dll)
1859                 foreach( _pdb ${LIBXML2_PDBS} )
1860                         list (APPEND OPTIONAL_PDBS "${LIBXML2_DLL_DIR}/${_pdb}")
1861                 endforeach(_pdb)
1862         endif(LIBXML2_FOUND)
1863         if (SMI_FOUND)
1864                 list (APPEND OPTIONAL_DLLS "${SMI_DLL_DIR}/${SMI_DLL}")
1865                 # Wireshark.nsi wants SMI_DIR which is the base SMI directory
1866                 get_filename_component(SMI_DIR ${SMI_DLL_DIR} DIRECTORY)
1867                 add_custom_command(TARGET copy_cli_dlls PRE_BUILD
1868                         COMMAND ${CMAKE_COMMAND} -E make_directory
1869                                 "${_dll_output_dir}/snmp"
1870                         COMMAND ${CMAKE_COMMAND} -E make_directory
1871                                 "${_dll_output_dir}/snmp/mibs"
1872                         COMMAND ${CMAKE_COMMAND} -E copy_directory
1873                                 "${SMI_SHARE_DIR}/mibs/iana"
1874                                 "${_dll_output_dir}/snmp/mibs"
1875                         COMMAND ${CMAKE_COMMAND} -E copy_directory
1876                                 "${SMI_SHARE_DIR}/mibs/ietf"
1877                                 "${_dll_output_dir}/snmp/mibs"
1878                         COMMAND ${CMAKE_COMMAND} -E copy_directory
1879                                 "${SMI_SHARE_DIR}/mibs/irtf"
1880                                 "${_dll_output_dir}/snmp/mibs"
1881                         COMMAND ${CMAKE_COMMAND} -E copy_directory
1882                                 "${SMI_SHARE_DIR}/mibs/site"
1883                                 "${_dll_output_dir}/snmp/mibs"
1884                         COMMAND ${CMAKE_COMMAND} -E copy_directory
1885                                 "${SMI_SHARE_DIR}/mibs/tubs"
1886                                 "${_dll_output_dir}/snmp/mibs"
1887                         COMMAND ${CMAKE_COMMAND} -E copy_directory
1888                                 "${SMI_SHARE_DIR}/pibs"
1889                                 "${_dll_output_dir}/snmp/mibs"
1890                         COMMAND ${CMAKE_COMMAND} -E copy_directory
1891                                 "${SMI_SHARE_DIR}/yang"
1892                                 "${_dll_output_dir}/snmp/mibs"
1893                         #remove the extra directories copied (shallow copying the above would remove the need for this)
1894                         COMMAND ${CMAKE_COMMAND} -E remove_directory
1895                                 "${_dll_output_dir}/snmp/mibs/iana"
1896                         COMMAND ${CMAKE_COMMAND} -E remove_directory
1897                                 "${_dll_output_dir}/snmp/mibs/ietf"
1898                         COMMAND ${CMAKE_COMMAND} -E remove_directory
1899                                 "${_dll_output_dir}/snmp/mibs/site"
1900                         COMMAND ${CMAKE_COMMAND} -E remove_directory
1901                                 "${_dll_output_dir}/snmp/mibs/tubs"
1902                 )
1903         endif(SMI_FOUND)
1904         if (SNAPPY_FOUND)
1905                 list (APPEND OPTIONAL_DLLS "${SNAPPY_DLL_DIR}/${SNAPPY_DLL}")
1906         endif(SNAPPY_FOUND)
1907         if (WINSPARKLE_FOUND)
1908                 list (APPEND OPTIONAL_DLLS "${WINSPARKLE_DLL_DIR}/${WINSPARKLE_DLL}")
1909         endif(WINSPARKLE_FOUND)
1910         if (ZLIB_FOUND)
1911                 list (APPEND OPTIONAL_DLLS "${ZLIB_DLL_DIR}/${ZLIB_DLL}")
1912                 list (APPEND OPTIONAL_PDBS "${ZLIB_DLL_DIR}/${ZLIB_PDB}")
1913         endif(ZLIB_FOUND)
1914         if (BROTLI_FOUND)
1915                 foreach( _dll ${BROTLI_DLLS} )
1916                         list (APPEND OPTIONAL_DLLS "${BROTLI_DLL_DIR}/${_dll}")
1917                 endforeach(_dll)
1918         endif(BROTLI_FOUND)
1919
1920         # With libs downloaded to c:/wireshark-win64-libs this currently
1921         # (early 2018) expands to about 1900 characters.
1922         if (OPTIONAL_DLLS)
1923                 add_custom_command(TARGET copy_cli_dlls PRE_BUILD
1924                         COMMAND ${CMAKE_COMMAND} -E copy_if_different
1925                                 ${OPTIONAL_DLLS}
1926                                 "${_dll_output_dir}"
1927                         VERBATIM
1928                 )
1929                 install(FILES ${OPTIONAL_DLLS} DESTINATION "${CMAKE_INSTALL_BINDIR}")
1930         endif(OPTIONAL_DLLS)
1931
1932         if (OPTIONAL_PDBS)
1933                 add_custom_command(TARGET copy_cli_dlls PRE_BUILD
1934                         COMMAND ${CMAKE_COMMAND} -E copy_if_different
1935                                 ${OPTIONAL_PDBS}
1936                                 "${_dll_output_dir}"
1937                         VERBATIM
1938                 )
1939         endif(OPTIONAL_PDBS)
1940
1941         add_dependencies(epan copy_cli_dlls)
1942
1943         # We have a lot of choices for creating zip archives:
1944         # - 7z, WinZip, etc., which require a separate download+install.
1945         # - "CMake -E tar cz", which creates a tar file.
1946         # - CPack, which requires a CPack configuration.
1947         # - PowerShell via PSCX or System.IO.Compression.FileSystem.
1948         # - Python via zipfile.
1949         # For now, just look for 7z. It's installed on the Windows builders,
1950         # which might be the only systems that use this target.
1951         find_program(ZIP_EXECUTABLE 7z
1952                 PATH "$ENV{PROGRAMFILES}/7-Zip" "$ENV{PROGRAMW6432}/7-Zip"
1953                 DOC "Path to the 7z utility."
1954         )
1955         if(ZIP_EXECUTABLE)
1956                 add_custom_target(pdb_zip_package COMMENT "This packages .PDBs but will not create them.")
1957                 set_target_properties(pdb_zip_package PROPERTIES FOLDER "Packaging")
1958                 set(_pdb_zip "${CMAKE_BINARY_DIR}/Wireshark-pdb-${WIRESHARK_TARGET_PLATFORM}-${VERSION}.zip")
1959                 file(TO_NATIVE_PATH "${_pdb_zip}" _pdb_zip_win)
1960                 add_custom_command(TARGET pdb_zip_package POST_BUILD
1961                         COMMAND ${CMAKE_COMMAND} -E remove -f "${_pdb_zip}"
1962                         COMMAND ${ZIP_EXECUTABLE} a -tzip -mmt=on "${_pdb_zip_win}"
1963                                 *.pdb *.lib
1964                                 extcap/*.pdb
1965                                 ${PLUGIN_VERSION_DIR}/epan/*.pdb
1966                                 ${PLUGIN_VERSION_DIR}/wiretap/*.pdb
1967                         WORKING_DIRECTORY "${_dll_output_dir}"
1968                 )
1969         endif()
1970 endif(WIN32)
1971
1972 # List of extra dependencies for the "copy_data_files" target
1973 set(copy_data_files_depends)
1974
1975 if(WIN32)
1976         foreach(_text_file ${TEXTIFY_FILES})
1977                 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${_text_file}.txt
1978                         COMMAND ${POWERSHELL_COMMAND} "${CMAKE_SOURCE_DIR}/tools/textify.ps1"
1979                                 -Destination ${CMAKE_BINARY_DIR}
1980                                 ${CMAKE_SOURCE_DIR}/${_text_file}
1981                         DEPENDS
1982                                 ${CMAKE_SOURCE_DIR}/${_text_file}
1983                 )
1984         endforeach()
1985         foreach(_md_file ${TEXTIFY_MD_FILES})
1986                 string(REGEX REPLACE ".md$" ".txt" _text_file ${_md_file})
1987                 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${_text_file}
1988                         COMMAND ${POWERSHELL_COMMAND} "${CMAKE_SOURCE_DIR}/tools/textify.ps1"
1989                                 -Destination ${CMAKE_BINARY_DIR}
1990                                 ${CMAKE_SOURCE_DIR}/${_md_file}
1991                         COMMAND ${CMAKE_COMMAND} -E rename
1992                                 ${CMAKE_BINARY_DIR}/${_md_file}.txt
1993                                 ${CMAKE_BINARY_DIR}/${_text_file}
1994                         DEPENDS
1995                                 ${CMAKE_SOURCE_DIR}/${_text_file}
1996                 )
1997         endforeach()
1998 endif()
1999
2000 foreach(_install_file ${INSTALL_FILES})
2001         get_filename_component(_install_file_src "${_install_file}" ABSOLUTE)
2002         get_filename_component(_install_basename "${_install_file}" NAME)
2003         set(_output_file "${DATAFILE_DIR}/${_install_basename}")
2004         add_custom_command(OUTPUT "${_output_file}"
2005                 COMMAND ${CMAKE_COMMAND} -E copy_if_different
2006                         "${_install_file_src}"
2007                         "${_output_file}"
2008                 DEPENDS
2009                         docs
2010                         "${_install_file}"
2011         )
2012         list(APPEND copy_data_files_depends "${_output_file}")
2013 endforeach()
2014
2015 # Install LUA files in staging directory such that LUA can used when Wireshark
2016 # is ran from the build directory. For install targets, see
2017 # epan/wslua/CMakeLists.txt
2018 if(LUA_FOUND AND ENABLE_LUA)
2019         set(_lua_files
2020                 "${CMAKE_BINARY_DIR}/epan/wslua/init.lua"
2021                 "${CMAKE_SOURCE_DIR}/epan/wslua/console.lua"
2022                 "${CMAKE_SOURCE_DIR}/epan/wslua/dtd_gen.lua"
2023         )
2024         foreach(_lua_file ${_lua_files})
2025                 get_filename_component(_lua_filename "${_lua_file}" NAME)
2026                 list(APPEND copy_data_files_depends
2027                         "${DATAFILE_DIR}/${_lua_filename}")
2028                 add_custom_command(OUTPUT "${DATAFILE_DIR}/${_lua_filename}"
2029                         COMMAND ${CMAKE_COMMAND} -E copy_if_different
2030                                 "${_lua_file}"
2031                                 "${DATAFILE_DIR}/${_lua_filename}"
2032                         DEPENDS
2033                                 wsluaauxiliary
2034                                 "${_lua_file}"
2035                 )
2036         endforeach()
2037 endif(LUA_FOUND AND ENABLE_LUA)
2038 # doc/*.html handled elsewhere.
2039
2040 # Glob patterns relative to the source directory that should be copied to
2041 # ${DATAFILE_DIR} (including directory prefixes)
2042 # TODO shouldn't this use full (relative) paths instead of glob patterns?
2043 set(DATA_FILES_SRC
2044         "tpncp/tpncp.dat"
2045         "wimaxasncp/*.dtd"
2046         "wimaxasncp/*.xml"
2047 )
2048
2049 # Copy all paths from the source tree to the data directory. Directories are
2050 # automatically created if missing as the filename is given.
2051 file(GLOB _data_files RELATIVE "${CMAKE_SOURCE_DIR}" ${DATA_FILES_SRC})
2052 foreach(_data_file ${_data_files})
2053         add_custom_command(OUTPUT "${DATAFILE_DIR}/${_data_file}"
2054                 COMMAND ${CMAKE_COMMAND} -E copy_if_different
2055                         "${CMAKE_SOURCE_DIR}/${_data_file}"
2056                         "${DATAFILE_DIR}/${_data_file}"
2057                 DEPENDS
2058                         "${CMAKE_SOURCE_DIR}/${_data_file}"
2059         )
2060         list(APPEND copy_data_files_depends "${DATAFILE_DIR}/${_data_file}")
2061 endforeach()
2062
2063 file(GLOB _dtds_src_files RELATIVE "${CMAKE_SOURCE_DIR}" "dtds/*.dtd")
2064
2065 set (_dtds_data_files)
2066 foreach(_data_file ${_dtds_src_files})
2067         list(APPEND _dtds_data_files "${DATAFILE_DIR}/${_data_file}")
2068 endforeach()
2069
2070 add_custom_command(
2071         OUTPUT ${_dtds_data_files}
2072         COMMAND ${CMAKE_COMMAND} -E make_directory "${DATAFILE_DIR}/dtds"
2073         COMMAND ${CMAKE_COMMAND} -E copy_if_different
2074                 ${_dtds_src_files}
2075                 "${DATAFILE_DIR}/dtds"
2076         VERBATIM
2077         DEPENDS ${_dtds_src_files}
2078         WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
2079 )
2080
2081 file(GLOB _diameter_src_files RELATIVE "${CMAKE_SOURCE_DIR}"
2082         diameter/*.dtd
2083         diameter/*.xml
2084 )
2085
2086 set (_diameter_data_files)
2087 foreach(_data_file ${_diameter_src_files})
2088         list(APPEND _diameter_data_files "${DATAFILE_DIR}/${_data_file}")
2089 endforeach()
2090
2091 add_custom_command(
2092         OUTPUT ${_diameter_data_files}
2093         COMMAND ${CMAKE_COMMAND} -E make_directory "${DATAFILE_DIR}/diameter"
2094         COMMAND ${CMAKE_COMMAND} -E copy_if_different
2095                 ${_diameter_src_files}
2096                 "${DATAFILE_DIR}/diameter"
2097         VERBATIM
2098         DEPENDS ${_diameter_src_files}
2099         WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
2100 )
2101
2102 file(GLOB _radius_src_files RELATIVE "${CMAKE_SOURCE_DIR}"
2103         radius/README.radius_dictionary
2104         radius/custom.includes
2105         radius/dictionary
2106         radius/dictionary.*
2107 )
2108
2109 set (_radius_data_files)
2110 foreach(_data_file ${_radius_src_files})
2111         list(APPEND _radius_data_files "${DATAFILE_DIR}/${_data_file}")
2112 endforeach()
2113
2114 add_custom_command(
2115         OUTPUT ${_radius_data_files}
2116         COMMAND ${CMAKE_COMMAND} -E make_directory "${DATAFILE_DIR}/radius"
2117         COMMAND ${CMAKE_COMMAND} -E copy_if_different
2118                 ${_radius_src_files}
2119                 "${DATAFILE_DIR}/radius"
2120         VERBATIM
2121         DEPENDS ${_radius_src_files}
2122         WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
2123 )
2124
2125 file(GLOB _profiles_src_files RELATIVE "${CMAKE_SOURCE_DIR}" profiles/*/*)
2126 set (_profiles_data_files)
2127 foreach(_data_file ${_profiles_src_files})
2128         list(APPEND _profiles_data_files "${DATAFILE_DIR}/${_data_file}")
2129 endforeach()
2130
2131 add_custom_command(
2132         OUTPUT ${_profiles_data_files}
2133         COMMAND ${CMAKE_COMMAND} -E copy_directory
2134                 "${CMAKE_SOURCE_DIR}/profiles" "${DATAFILE_DIR}/profiles"
2135 )
2136
2137 list(APPEND copy_data_files_depends
2138         ${_dtds_data_files}
2139         ${_diameter_data_files}
2140         ${_radius_data_files}
2141         ${_profiles_data_files}
2142 )
2143
2144 # Copy files including ${INSTALL_FILES} and ${INSTALL_DIRS} to ${DATAFILE_DIR}
2145 add_custom_target(copy_data_files ALL DEPENDS ${copy_data_files_depends} )
2146 set_target_properties(copy_data_files PROPERTIES FOLDER "Copy Tasks")
2147
2148
2149 # Shared code, build object files once for all users.
2150 add_library(version_info OBJECT version_info.c)
2151 target_include_directories(version_info SYSTEM PRIVATE ${VERSION_INFO_INCLUDE_DIRS})
2152 if(NOT VCSVERSION_OVERRIDE)
2153         add_dependencies(version_info version)
2154 endif()
2155 # sources common for wireshark, tshark, rawshark and sharkd
2156 add_library(shark_common OBJECT
2157         cfile.c
2158         extcap.c
2159         extcap_parser.c
2160         file_packet_provider.c
2161         frame_tvbuff.c
2162         sync_pipe_write.c
2163 )
2164 add_library(cli_main OBJECT cli_main.c)
2165 add_library(capture_opts OBJECT capture_opts.c)
2166 target_include_directories(capture_opts SYSTEM PRIVATE ${PCAP_INCLUDE_DIRS})
2167 set_target_properties(version_info shark_common cli_main capture_opts
2168         PROPERTIES
2169         COMPILE_FLAGS "${WERROR_COMMON_FLAGS}"
2170 )
2171
2172
2173 if(BUILD_wireshark AND QT_FOUND)
2174         set(WIRESHARK_SRC
2175                 file.c
2176                 fileset.c
2177                 ${PLATFORM_UI_SRC}
2178         )
2179         set(wireshark_FILES
2180                 $<TARGET_OBJECTS:capture_opts>
2181                 $<TARGET_OBJECTS:qtui>
2182                 $<TARGET_OBJECTS:shark_common>
2183                 $<TARGET_OBJECTS:version_info>
2184                 ${WIRESHARK_SRC}
2185                 ${PLATFORM_UI_RC_FILES}
2186         )
2187         set_executable_resources(wireshark "Wireshark" UNIQUE_RC)
2188 endif()
2189
2190 if(ENABLE_APPLICATION_BUNDLE)
2191         #
2192         # Add -Wl,-single_module to the LDFLAGS used with shared
2193         # libraries, to fix some error that show up in some cases;
2194         # some Apple documentation recommends it for most shared
2195         # libraries.
2196         #
2197         set( CMAKE_SHARED_LINKER_FLAGS "-Wl,-single_module ${CMAKE_SHARED_LINKER_FLAGS}" )
2198         #
2199         # Add -Wl,-headerpad_max_install_names to the LDFLAGS, as
2200         # code-signing issues is running out of padding space.
2201         #
2202         # Add -Wl,-search_paths_first to make sure that if we search
2203         # directories A and B, in that order, for a given library, a
2204         # non-shared version in directory A, rather than a shared
2205         # version in directory B, is chosen (so we can use
2206         # --with-pcap=/usr/local to force all programs to be linked
2207         # with a static version installed in /usr/local/lib rather than
2208         # the system version in /usr/lib).
2209         #
2210
2211         set(CMAKE_EXE_LINKER_FLAGS
2212         "-Wl,-headerpad_max_install_names -Wl,-search_paths_first ${CMAKE_EXE_LINKER_FLAGS}"
2213         )
2214
2215         # Create our Frameworks directory
2216         file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/run/${CMAKE_CFG_INTDIR}/Wireshark.app/Contents/Frameworks")
2217
2218         # Add files to the app bundle
2219         # Wireshark.app/Contents
2220         file(WRITE ${CMAKE_BINARY_DIR}/packaging/macosx/PkgInfo "APPLWshk\n")
2221         set(BUNDLE_CONTENTS_FILES
2222                 ${CMAKE_BINARY_DIR}/packaging/macosx/PkgInfo
2223         )
2224         set_source_files_properties(${BUNDLE_CONTENTS_FILES} PROPERTIES
2225                 MACOSX_PACKAGE_LOCATION .
2226         )
2227
2228         # Wireshark.app/Contents/Resources
2229         set(BUNDLE_RESOURCE_FILES
2230                 ${CMAKE_SOURCE_DIR}/packaging/macosx/Wireshark.icns
2231                 ${CMAKE_SOURCE_DIR}/packaging/macosx/Wiresharkdoc.icns
2232         )
2233         set_source_files_properties(${BUNDLE_RESOURCE_FILES} PROPERTIES
2234                 MACOSX_PACKAGE_LOCATION Resources
2235         )
2236
2237         # Wireshark.app/Contents/Resources/share/man/man1
2238         set_source_files_properties(${BUNDLE_RESOURCE_SHARE_MAN1_FILES} PROPERTIES
2239                 MACOSX_PACKAGE_LOCATION Resources/share/man/man1
2240                 GENERATED 1
2241         )
2242
2243         # Wireshark.app/Contents/Resources/share/man/man4
2244         set_source_files_properties(${BUNDLE_RESOURCE_SHARE_MAN4_FILES} PROPERTIES
2245                 MACOSX_PACKAGE_LOCATION Resources/share/man/man4
2246                 GENERATED 1
2247         )
2248
2249         # INSTALL_FILES and INSTALL_DIRS are handled by copy_data_files
2250
2251         set(EXTRA_BUNDLE_FILES
2252                 ${BUNDLE_CONTENTS_FILES}
2253                 ${BUNDLE_RESOURCE_FILES}
2254                 ${BUNDLE_RESOURCE_SHARE_MAN1_FILES}
2255                 ${BUNDLE_RESOURCE_SHARE_MAN4_FILES}
2256         )
2257 else()
2258         set(EXTRA_BUNDLE_FILES)
2259 endif()
2260
2261 if(BUILD_wireshark AND QT_FOUND)
2262         set(wireshark_LIBS
2263                 ui
2264                 capchild
2265                 caputils
2266                 wiretap
2267                 epan
2268                 ${QT_LIBRARIES}
2269                 ${VERSION_INFO_LIBS}
2270                 ${APPLE_APPLICATION_SERVICES_LIBRARY}
2271                 ${APPLE_APPKIT_LIBRARY}
2272                 ${APPLE_CORE_FOUNDATION_LIBRARY}
2273                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
2274                 ${SPARKLE_LIBRARIES}
2275                 ${WIN_WS2_32_LIBRARY}
2276                 ${WIN_VERSION_LIBRARY}
2277                 ${WINSPARKLE_LIBRARIES}
2278                 $<$<BOOL:${WIN32}>:UxTheme.lib>
2279                 ${SPEEXDSP_LIBRARIES}
2280                 ${MINIZIP_LIBRARIES}
2281         )
2282
2283         add_executable(wireshark WIN32 MACOSX_BUNDLE ${wireshark_FILES} ${EXTRA_BUNDLE_FILES})
2284         if(WIN32)
2285                 set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT wireshark)
2286         endif()
2287         set(PROGLIST ${PROGLIST} wireshark)
2288         set_target_properties(wireshark PROPERTIES
2289                 LINK_FLAGS "${WS_LINK_FLAGS}"
2290                 FOLDER "Executables"
2291                 INSTALL_RPATH "${EXECUTABLE_INSTALL_RPATH}"
2292         )
2293         if(ENABLE_APPLICATION_BUNDLE OR WIN32)
2294                 set_target_properties(wireshark PROPERTIES OUTPUT_NAME Wireshark)
2295         endif()
2296
2297         if(ENABLE_APPLICATION_BUNDLE)
2298                 add_dependencies(wireshark manpages)
2299                 set_target_properties(
2300                         wireshark PROPERTIES
2301                                 MACOSX_BUNDLE_INFO_PLIST ${CMAKE_BINARY_DIR}/packaging/macosx/Info.plist
2302                 )
2303                 if(CMAKE_CFG_INTDIR STREQUAL ".")
2304                         # Add a wrapper script which opens the bundle. This adds
2305                         # convenience but makes debugging more difficult.
2306                         # It is not created if using Xcode
2307                         # XXX Running run/Wireshark.app/Contents/MacOS/Wireshark works
2308                         # fine for me (Gerald) here on Mojave. Can we just make this a
2309                         # symlink?
2310                         file(REMOVE ${CMAKE_BINARY_DIR}/run/wireshark)
2311                         file(WRITE ${CMAKE_BINARY_DIR}/run/wireshark "#!/bin/sh\n")
2312                         file(APPEND ${CMAKE_BINARY_DIR}/run/wireshark "# Generated by ${CMAKE_CURRENT_LIST_FILE}\n")
2313                         file(APPEND ${CMAKE_BINARY_DIR}/run/wireshark "# Wrapper script which should work around the issue described at\n")
2314                         file(APPEND ${CMAKE_BINARY_DIR}/run/wireshark "# https://stackoverflow.com/questions/25318524/what-exactly-should-i-pass-to-nsapp-activateignoringotherapps-to-get-my-appl\n")
2315                         file(APPEND ${CMAKE_BINARY_DIR}/run/wireshark "exec ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/MacOS/Wireshark \"\$\@\"\n")
2316                         execute_process(COMMAND chmod a+x ${CMAKE_BINARY_DIR}/run/wireshark)
2317                 endif()
2318         endif()
2319
2320         target_link_libraries(wireshark ${wireshark_LIBS})
2321         target_include_directories(wireshark SYSTEM PRIVATE ${SPARKLE_INCLUDE_DIRS})
2322
2323         install(
2324                 TARGETS wireshark
2325                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
2326                 BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}
2327         )
2328
2329         if(QT_WINDEPLOYQT_EXECUTABLE)
2330                 add_custom_target(copy_qt_dlls ALL)
2331                 set_target_properties(copy_qt_dlls PROPERTIES FOLDER "Copy Tasks")
2332                 # Will we ever need to use --debug? Windeployqt seems to
2333                 # be smart enough to copy debug DLLs when needed.
2334                 add_custom_command(TARGET copy_qt_dlls
2335                         POST_BUILD
2336                         COMMAND set "PATH=${QT_BIN_PATH};%PATH%"
2337                         COMMAND "${QT_WINDEPLOYQT_EXECUTABLE}"
2338                                 $<$<CONFIG:Debug>:--debug>
2339                                 $<$<NOT:$<CONFIG:Debug>>:--release>
2340                                 --no-compiler-runtime
2341                                 --verbose 10
2342                                 ${QT_WINDEPLOYQT_EXTRA_OPTS}
2343                                 "$<TARGET_FILE:wireshark>"
2344                 )
2345                 add_dependencies(copy_qt_dlls wireshark)
2346
2347                 install(CODE "execute_process(COMMAND
2348                         \"${QT_WINDEPLOYQT_EXECUTABLE}\"
2349                         --no-compiler-runtime
2350                         \"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/Wireshark.exe\")"
2351                 )
2352
2353         endif(QT_WINDEPLOYQT_EXECUTABLE)
2354 endif()
2355
2356 # Common properties for CLI executables
2357 macro(set_extra_executable_properties _executable _folder)
2358         set_target_properties(${_executable} PROPERTIES
2359                 LINK_FLAGS "${WILDCARD_OBJ} ${WS_LINK_FLAGS}"
2360                 FOLDER ${_folder}
2361                 INSTALL_RPATH "${EXECUTABLE_INSTALL_RPATH}"
2362         )
2363
2364         set(PROGLIST ${PROGLIST} ${_executable})
2365
2366         if(ENABLE_APPLICATION_BUNDLE)
2367                 if(NOT CMAKE_CFG_INTDIR STREQUAL ".")
2368                         # Xcode
2369                         set_target_properties(${_executable} PROPERTIES
2370                                 RUNTIME_OUTPUT_DIRECTORY run/$<CONFIG>/Wireshark.app/Contents/MacOS
2371                         )
2372                 else ()
2373                         set_target_properties(${_executable} PROPERTIES
2374                                 RUNTIME_OUTPUT_DIRECTORY run/Wireshark.app/Contents/MacOS
2375                         )
2376                         # Create a convenience link from run/<name> to its respective
2377                         # target in the application bundle.
2378                         add_custom_target(${_executable}-symlink
2379                                 COMMAND ln -s -f
2380                                         Wireshark.app/Contents/MacOS/${_executable}
2381                                         ${CMAKE_BINARY_DIR}/run/${_executable}
2382                         )
2383                         add_dependencies(${_executable} ${_executable}-symlink)
2384                 endif()
2385         endif()
2386 endmacro()
2387
2388 register_tap_files(tshark-tap-register.c
2389         ${TSHARK_TAP_SRC}
2390 )
2391
2392 if(BUILD_tshark)
2393         set(tshark_LIBS
2394                 ui
2395                 capchild
2396                 caputils
2397                 wiretap
2398                 epan
2399                 ${VERSION_INFO_LIBS}
2400                 ${APPLE_CORE_FOUNDATION_LIBRARY}
2401                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
2402                 ${WIN_WS2_32_LIBRARY}
2403                 ${M_LIBRARIES}
2404         )
2405         set(tshark_FILES
2406                 $<TARGET_OBJECTS:capture_opts>
2407                 $<TARGET_OBJECTS:cli_main>
2408                 $<TARGET_OBJECTS:shark_common>
2409                 $<TARGET_OBJECTS:version_info>
2410                 tshark-tap-register.c
2411                 tshark.c
2412                 ${TSHARK_TAP_SRC}
2413         )
2414
2415         set_executable_resources(tshark "TShark" UNIQUE_RC)
2416         add_executable(tshark ${tshark_FILES})
2417         set_extra_executable_properties(tshark "Executables")
2418         target_link_libraries(tshark ${tshark_LIBS})
2419         install(TARGETS tshark RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2420 endif()
2421
2422 if(BUILD_tfshark)
2423         set(tfshark_LIBS
2424                 ui
2425                 wiretap
2426                 epan
2427                 ${VERSION_INFO_LIBS}
2428                 ${APPLE_CORE_FOUNDATION_LIBRARY}
2429                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
2430         )
2431         set(tfshark_FILES
2432                 $<TARGET_OBJECTS:cli_main>
2433                 $<TARGET_OBJECTS:shark_common>
2434                 $<TARGET_OBJECTS:version_info>
2435                 tfshark.c
2436                 ${TSHARK_TAP_SRC}
2437         )
2438         set_executable_resources(tfshark "TFShark")
2439         add_executable(tfshark ${tfshark_FILES})
2440         set_extra_executable_properties(tfshark "Executables")
2441         target_link_libraries(tfshark ${tfshark_LIBS})
2442         install(TARGETS tfshark RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2443 endif()
2444
2445 if(BUILD_rawshark AND PCAP_FOUND)
2446         set(rawshark_LIBS
2447                 caputils
2448                 ui
2449                 wiretap
2450                 epan
2451                 ${VERSION_INFO_LIBS}
2452                 ${APPLE_CORE_FOUNDATION_LIBRARY}
2453                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
2454                 ${WIN_WS2_32_LIBRARY}
2455         )
2456         set(rawshark_FILES
2457                 $<TARGET_OBJECTS:cli_main>
2458                 $<TARGET_OBJECTS:shark_common>
2459                 $<TARGET_OBJECTS:version_info>
2460                 rawshark.c
2461         )
2462         set_executable_resources(rawshark "Rawshark")
2463         add_executable(rawshark ${rawshark_FILES})
2464         set_extra_executable_properties(rawshark "Executables")
2465         target_link_libraries(rawshark ${rawshark_LIBS})
2466         install(TARGETS rawshark RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2467 endif()
2468
2469 if(BUILD_sharkd)
2470         set(sharkd_LIBS
2471                 ui
2472                 wiretap
2473                 epan
2474                 ${VERSION_INFO_LIBS}
2475                 ${APPLE_CORE_FOUNDATION_LIBRARY}
2476                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
2477                 ${WIN_WS2_32_LIBRARY}
2478                 ${SPEEXDSP_LIBRARIES}
2479                 ${M_LIBRARIES}
2480         )
2481         set(sharkd_FILES
2482                 #
2483                 # XXX - currently doesn't work on Windows if it uses
2484                 # $<TARGET_OBJECTS:cli_main> and has real_main().
2485                 #
2486                 $<TARGET_OBJECTS:shark_common>
2487                 $<TARGET_OBJECTS:version_info>
2488                 sharkd.c
2489                 sharkd_daemon.c
2490                 sharkd_session.c
2491         )
2492         set_executable_resources(sharkd "SharkD")
2493         add_executable(sharkd ${sharkd_FILES})
2494         set_extra_executable_properties(sharkd "Executables")
2495         target_link_libraries(sharkd ${sharkd_LIBS})
2496         target_include_directories(sharkd SYSTEM
2497                 PUBLIC
2498                         ${SPEEXDSP_INCLUDE_DIRS}
2499         )
2500
2501         install(TARGETS sharkd RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2502 endif()
2503
2504 if(BUILD_dftest)
2505         set(dftest_LIBS
2506                 ui
2507                 wiretap
2508                 epan
2509                 ${VERSION_INFO_LIBS}
2510         )
2511         set(dftest_FILES
2512                 dftest.c
2513         )
2514         add_executable(dftest ${dftest_FILES})
2515         set_extra_executable_properties(dftest "Tests")
2516         target_link_libraries(dftest ${dftest_LIBS})
2517 endif()
2518
2519 if(BUILD_randpkt)
2520         set(randpkt_LIBS
2521                 randpkt_core
2522                 ui
2523                 wiretap
2524                 wsutil
2525                 ${M_LIBRARIES}
2526                 ${CARES_LIBRARIES}
2527                 ${ZLIB_LIBRARIES}
2528         )
2529         set(randpkt_FILES
2530                 $<TARGET_OBJECTS:cli_main>
2531                 $<TARGET_OBJECTS:version_info>
2532                 randpkt.c
2533         )
2534         add_executable(randpkt ${randpkt_FILES})
2535         set_extra_executable_properties(randpkt "Executables")
2536         target_link_libraries(randpkt ${randpkt_LIBS})
2537         install(TARGETS randpkt RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2538 endif()
2539
2540 if(BUILD_fuzzshark OR ENABLE_FUZZER OR OSS_FUZZ)
2541         add_subdirectory(fuzz)
2542 endif()
2543
2544 if(BUILD_text2pcap)
2545         set(text2pcap_LIBS
2546                 writecap
2547                 wsutil
2548                 ${M_LIBRARIES}
2549                 ${ZLIB_LIBRARIES}
2550         )
2551         set(text2pcap_FILES
2552                 $<TARGET_OBJECTS:cli_main>
2553                 $<TARGET_OBJECTS:version_info>
2554                 text2pcap.c
2555         )
2556         add_lex_files(text2pcap_LEX_FILES text2pcap_FILES
2557                 text2pcap-scanner.l
2558         )
2559         set_executable_resources(text2pcap "Text2pcap"
2560                 COPYRIGHT_INFO "2001 Ashok Narayanan <ashokn@cisco.com>")
2561         add_executable(text2pcap ${text2pcap_FILES})
2562         set_extra_executable_properties(text2pcap "Executables")
2563         target_link_libraries(text2pcap ${text2pcap_LIBS})
2564         install(TARGETS text2pcap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2565 endif()
2566
2567 if(BUILD_mergecap)
2568         set(mergecap_LIBS
2569                 ui
2570                 wiretap
2571                 ${ZLIB_LIBRARIES}
2572                 ${CMAKE_DL_LIBS}
2573         )
2574         set(mergecap_FILES
2575                 $<TARGET_OBJECTS:cli_main>
2576                 $<TARGET_OBJECTS:version_info>
2577                 mergecap.c
2578         )
2579         set_executable_resources(mergecap "Mergecap")
2580         add_executable(mergecap ${mergecap_FILES})
2581         set_extra_executable_properties(mergecap "Executables")
2582         target_link_libraries(mergecap ${mergecap_LIBS})
2583         install(TARGETS mergecap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2584 endif()
2585
2586 if(BUILD_reordercap)
2587         set(reordercap_LIBS
2588                 ui
2589                 wiretap
2590                 ${ZLIB_LIBRARIES}
2591                 ${CMAKE_DL_LIBS}
2592         )
2593         set(reordercap_FILES
2594                 $<TARGET_OBJECTS:cli_main>
2595                 $<TARGET_OBJECTS:version_info>
2596                 reordercap.c
2597         )
2598         set_executable_resources(reordercap "Reordercap")
2599         add_executable(reordercap ${reordercap_FILES})
2600         set_extra_executable_properties(reordercap "Executables")
2601         target_link_libraries(reordercap ${reordercap_LIBS})
2602         install(TARGETS reordercap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2603 endif()
2604
2605 if(BUILD_capinfos)
2606         set(capinfos_LIBS
2607                 ui
2608                 wiretap
2609                 wsutil
2610                 ${ZLIB_LIBRARIES}
2611                 ${GCRYPT_LIBRARIES}
2612                 ${CMAKE_DL_LIBS}
2613         )
2614         set(capinfos_FILES
2615                 $<TARGET_OBJECTS:cli_main>
2616                 $<TARGET_OBJECTS:version_info>
2617                 capinfos.c
2618         )
2619         set_executable_resources(capinfos "Capinfos")
2620         add_executable(capinfos ${capinfos_FILES})
2621         set_extra_executable_properties(capinfos "Executables")
2622         target_link_libraries(capinfos ${capinfos_LIBS})
2623         install(TARGETS capinfos RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2624 endif()
2625
2626 if(BUILD_captype)
2627         set(captype_LIBS
2628                 ui
2629                 wiretap
2630                 wsutil
2631                 ${ZLIB_LIBRARIES}
2632                 ${CMAKE_DL_LIBS}
2633         )
2634         set(captype_FILES
2635                 $<TARGET_OBJECTS:cli_main>
2636                 $<TARGET_OBJECTS:version_info>
2637                 captype.c
2638         )
2639         set_executable_resources(captype "Captype")
2640         add_executable(captype ${captype_FILES})
2641         set_extra_executable_properties(captype "Executables")
2642         target_link_libraries(captype ${captype_LIBS})
2643         install(TARGETS captype RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2644 endif()
2645
2646 if(BUILD_editcap)
2647         set(editcap_LIBS
2648                 ui
2649                 wiretap
2650                 ${ZLIB_LIBRARIES}
2651                 ${GCRYPT_LIBRARIES}
2652                 ${CMAKE_DL_LIBS}
2653         )
2654         set(editcap_FILES
2655                 $<TARGET_OBJECTS:cli_main>
2656                 $<TARGET_OBJECTS:version_info>
2657                 editcap.c
2658         )
2659         set_executable_resources(editcap "Editcap")
2660         add_executable(editcap ${editcap_FILES})
2661         set_extra_executable_properties(editcap "Executables")
2662         target_link_libraries(editcap ${editcap_LIBS})
2663         install(TARGETS editcap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2664 endif()
2665
2666 if(BUILD_dumpcap AND PCAP_FOUND)
2667         set(dumpcap_LIBS
2668                 writecap
2669                 wsutil
2670                 caputils
2671                 ui
2672                 pcap::pcap
2673                 ${CAP_LIBRARIES}
2674                 ${GLIB2_LIBRARIES}
2675                 ${GTHREAD2_LIBRARIES}
2676                 ${ZLIB_LIBRARIES}
2677                 ${APPLE_CORE_FOUNDATION_LIBRARY}
2678                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
2679                 ${WIN_WS2_32_LIBRARY}
2680         )
2681         set(dumpcap_FILES
2682                 $<TARGET_OBJECTS:capture_opts>
2683                 $<TARGET_OBJECTS:cli_main>
2684                 $<TARGET_OBJECTS:version_info>
2685                 dumpcap.c
2686                 ringbuffer.c
2687                 sync_pipe_write.c
2688         )
2689         set_executable_resources(dumpcap "Dumpcap" UNIQUE_RC)
2690         add_executable(dumpcap ${dumpcap_FILES})
2691         set_extra_executable_properties(dumpcap "Executables")
2692         target_link_libraries(dumpcap ${dumpcap_LIBS})
2693         install(TARGETS dumpcap
2694                         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
2695                         PERMISSIONS ${DUMPCAP_SETUID}
2696                                 OWNER_READ OWNER_WRITE OWNER_EXECUTE
2697                                 GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
2698         )
2699         if(ENABLE_DUMPCAP_GROUP)
2700                 install(CODE "execute_process(COMMAND chgrp ${DUMPCAP_INSTALL_GROUP} ${CMAKE_INSTALL_FULL_BINDIR}/dumpcap)")
2701                 install(CODE "execute_process(COMMAND chmod o-x ${CMAKE_INSTALL_FULL_BINDIR}/dumpcap)")
2702         endif()
2703         if(DUMPCAP_INSTALL_OPTION STREQUAL "capabilities")
2704                 install( CODE "execute_process(
2705                         COMMAND
2706                                 ${SETCAP_EXECUTABLE}
2707                                 cap_net_raw,cap_net_admin+ep
2708                                 ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/dumpcap${CMAKE_EXECUTABLE_SUFFIX}
2709                         RESULT_VARIABLE
2710                                 _SETCAP_RESULT
2711                         )
2712                         if( _SETCAP_RESULT )
2713                                 message( WARNING \"setcap failed (${_SETCAP_RESULT}).\")
2714                         endif()"
2715                 )
2716         endif()
2717 elseif(BUILD_dumpcap AND ENABLE_PCAP)
2718         message(WARNING "Dumpcap was requested but libpcap dependency is not available. "
2719                 "Wireshark will be built without packet capture capability.")
2720 endif()
2721
2722 # We have two idl2wrs utilities: this and the CORBA version in tools.
2723 # We probably shouldn't do that.
2724 if(BUILD_dcerpcidl2wrs)
2725         set(idl2wrs_LIBS
2726                 ${GLIB2_LIBRARIES}
2727                 wsutil
2728         )
2729         set(idl2wrs_FILES
2730                 epan/dissectors/dcerpc/idl2wrs.c
2731         )
2732
2733         add_executable(idl2wrs ${idl2wrs_FILES})
2734         set_target_properties(idl2wrs PROPERTIES FOLDER "Executables")
2735         set_extra_executable_properties(idl2wrs "Executables")
2736         target_link_libraries(idl2wrs ${idl2wrs_LIBS})
2737         install(TARGETS idl2wrs RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2738 endif()
2739
2740 if (WIN32)
2741         find_package( MSVC_REDIST )
2742
2743         # Must come after executable targets are defined.
2744         find_package( NSIS )
2745
2746         if(MAKENSIS_EXECUTABLE)
2747                 add_subdirectory( packaging/nsis EXCLUDE_FROM_ALL )
2748                 ADD_NSIS_UNINSTALLER_TARGET()
2749                 ADD_NSIS_PACKAGE_TARGET()
2750         endif()
2751
2752         find_package( WiX )
2753
2754         if(WIX_CANDLE_EXECUTABLE)
2755                 add_subdirectory( packaging/wix EXCLUDE_FROM_ALL )
2756                 ADD_WIX_PACKAGE_TARGET()
2757         endif()
2758
2759         find_package( PortableApps )
2760         if(PORTABLEAPPS_LAUNCHER_GENERATOR_EXECUTABLE AND PORTABLEAPPS_INSTALLER_EXECUTABLE)
2761                 add_subdirectory( packaging/portableapps EXCLUDE_FROM_ALL )
2762                 ADD_PORTABLEAPPS_PACKAGE_TARGET()
2763         endif()
2764 endif()
2765
2766 if (MAXMINDDB_FOUND)
2767         set(mmdbresolve_LIBS
2768                 # Note: libmaxminddb is not GPL-2 compatible.
2769                 ${MAXMINDDB_LIBRARY}
2770         )
2771         set(mmdbresolve_FILES
2772                 mmdbresolve.c
2773         )
2774         add_executable(mmdbresolve ${mmdbresolve_FILES})
2775         set_extra_executable_properties(mmdbresolve "Executables")
2776         target_link_libraries(mmdbresolve ${mmdbresolve_LIBS})
2777         target_include_directories(mmdbresolve PUBLIC ${MAXMINDDB_INCLUDE_DIRS})
2778         target_compile_definitions(mmdbresolve PUBLIC ${MAXMINDDB_DEFINITIONS})
2779         install(TARGETS mmdbresolve RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2780 endif()
2781
2782 if(ENABLE_APPLICATION_BUNDLE)
2783         set (install_chmodbpf_component_pkg "${CMAKE_BINARY_DIR}/install.ChmodBPF.pkg")
2784         add_custom_command(OUTPUT "${install_chmodbpf_component_pkg}"
2785                 COMMAND pkgbuild
2786                         --identifier org.wireshark.ChmodBPF.pkg
2787                         --version 1.1
2788                         --root "${CMAKE_SOURCE_DIR}/packaging/macosx/ChmodBPF/root"
2789                         --scripts "${CMAKE_SOURCE_DIR}/packaging/macosx/ChmodBPF/install-scripts"
2790                         ${install_chmodbpf_component_pkg}
2791                 DEPENDS
2792                         "${CMAKE_SOURCE_DIR}/packaging/macosx/ChmodBPF/root/Library/Application Support/Wireshark/ChmodBPF/ChmodBPF"
2793                         "${CMAKE_SOURCE_DIR}/packaging/macosx/ChmodBPF/root/Library/LaunchDaemons/org.wireshark.ChmodBPF.plist"
2794                         "${CMAKE_SOURCE_DIR}/packaging/macosx/ChmodBPF/install-scripts/postinstall"
2795         )
2796         set (install_chmodbpf_pkg "${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/Resources/Extras/Install ChmodBPF.pkg")
2797         add_custom_command(OUTPUT "${install_chmodbpf_pkg}"
2798                 COMMAND productbuild
2799                         --identifier org.wireshark.install.ChmodBPF.product
2800                         --version 1.1
2801                         --distribution "${CMAKE_SOURCE_DIR}/packaging/macosx/ChmodBPF/install-distribution.xml"
2802                         --package-path "${CMAKE_BINARY_DIR}"
2803                         ${install_chmodbpf_pkg}
2804                 DEPENDS
2805                         "${CMAKE_SOURCE_DIR}/packaging/macosx/ChmodBPF/install-distribution.xml"
2806                         ${install_chmodbpf_component_pkg}
2807         )
2808
2809         set (uninstall_chmodbpf_component_pkg "${CMAKE_BINARY_DIR}/uninstall.ChmodBPF.pkg")
2810         add_custom_command(OUTPUT "${uninstall_chmodbpf_component_pkg}"
2811                 COMMAND pkgbuild
2812                         --identifier org.wireshark.uninstall.ChmodBPF.pkg
2813                         --version 1.1
2814                         --nopayload
2815                         --scripts "${CMAKE_SOURCE_DIR}/packaging/macosx/ChmodBPF/uninstall-scripts"
2816                         ${uninstall_chmodbpf_component_pkg}
2817                 DEPENDS
2818                         "${CMAKE_SOURCE_DIR}/packaging/macosx/ChmodBPF/uninstall-scripts/postinstall"
2819         )
2820         set (uninstall_chmodbpf_pkg "${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/Resources/Extras/Uninstall ChmodBPF.pkg")
2821         add_custom_command(OUTPUT "${uninstall_chmodbpf_pkg}"
2822                 COMMAND productbuild
2823                         --identifier org.wireshark.uninstall.ChmodBPF.product
2824                         --version 1.1
2825                         --distribution "${CMAKE_SOURCE_DIR}/packaging/macosx/ChmodBPF/uninstall-distribution.xml"
2826                         --package-path "${CMAKE_BINARY_DIR}"
2827                         ${uninstall_chmodbpf_pkg}
2828                 DEPENDS
2829                         "${CMAKE_SOURCE_DIR}/packaging/macosx/ChmodBPF/uninstall-distribution.xml"
2830                         ${uninstall_chmodbpf_component_pkg}
2831         )
2832
2833         add_custom_target(chmodbpf DEPENDS ${install_chmodbpf_pkg} ${uninstall_chmodbpf_pkg})
2834
2835         set (install_path_helper_component_pkg "${CMAKE_BINARY_DIR}/install.path_helper.pkg")
2836         add_custom_command(OUTPUT "${install_path_helper_component_pkg}"
2837                 COMMAND pkgbuild
2838                         --identifier org.wireshark.path_helper.pkg
2839                         --version 1.0
2840                         --root "${CMAKE_SOURCE_DIR}/packaging/macosx/path_helper/root/etc"
2841                         --install-location /private/etc
2842                         ${install_path_helper_component_pkg}
2843                 DEPENDS
2844                         "${CMAKE_SOURCE_DIR}/packaging/macosx/path_helper/root/etc/paths.d/Wireshark"
2845                         "${CMAKE_SOURCE_DIR}/packaging/macosx/path_helper/root/etc/manpaths.d/Wireshark"
2846         )
2847         set (install_path_helper_pkg "${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/Resources/Extras/Add Wireshark to the system path.pkg")
2848         add_custom_command(OUTPUT "${install_path_helper_pkg}"
2849                 COMMAND productbuild
2850                         --identifier org.wireshark.install.path_helper.product
2851                         --version 1.0
2852                         --distribution "${CMAKE_SOURCE_DIR}/packaging/macosx/path_helper/install-distribution.xml"
2853                         --package-path "${CMAKE_BINARY_DIR}"
2854                         ${install_path_helper_pkg}
2855                 DEPENDS
2856                         "${CMAKE_SOURCE_DIR}/packaging/macosx/path_helper/install-distribution.xml"
2857                         ${install_path_helper_component_pkg}
2858         )
2859
2860         set (uninstall_path_helper_component_pkg "${CMAKE_BINARY_DIR}/uninstall.path_helper.pkg")
2861         add_custom_command(OUTPUT "${uninstall_path_helper_component_pkg}"
2862                 COMMAND pkgbuild
2863                         --identifier org.wireshark.uninstall.path_helper.pkg
2864                         --version 1.0
2865                         --nopayload
2866                         --scripts "${CMAKE_SOURCE_DIR}/packaging/macosx/path_helper/uninstall-scripts"
2867                         ${uninstall_path_helper_component_pkg}
2868                 DEPENDS
2869                         "${CMAKE_SOURCE_DIR}/packaging/macosx/path_helper/uninstall-scripts/postinstall"
2870         )
2871         set (uninstall_path_helper_pkg "${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/Resources/Extras/Remove Wireshark from the system path.pkg")
2872         add_custom_command(OUTPUT "${uninstall_path_helper_pkg}"
2873                 COMMAND productbuild
2874                         --identifier org.wireshark.uninstall.path_helper.product
2875                         --version 1.0
2876                         --distribution "${CMAKE_SOURCE_DIR}/packaging/macosx/path_helper/uninstall-distribution.xml"
2877                         --package-path "${CMAKE_BINARY_DIR}"
2878                         ${uninstall_path_helper_pkg}
2879                 DEPENDS
2880                         ${CMAKE_SOURCE_DIR}/packaging/macosx/path_helper/uninstall-distribution.xml
2881                         ${uninstall_path_helper_component_pkg}
2882         )
2883
2884         add_custom_target(path_helper DEPENDS ${install_path_helper_pkg} ${uninstall_path_helper_pkg})
2885
2886         add_custom_target(app_bundle)
2887         set_target_properties(app_bundle PROPERTIES FOLDER "Copy Tasks")
2888         add_custom_command(TARGET app_bundle
2889                 POST_BUILD
2890                 COMMAND "${CMAKE_BINARY_DIR}/packaging/macosx/osx-app.sh"
2891                 WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/run"
2892         )
2893         add_dependencies(app_bundle ${PROGLIST} chmodbpf path_helper)
2894
2895         if( DMGBUILD_EXECUTABLE AND ASCIIDOCTOR_FOUND)
2896                 add_custom_target(dmg_package_prep DEPENDS app_bundle)
2897
2898                 set(_read_me_first "packaging/macosx/Read me first.html")
2899                 ADD_CUSTOM_COMMAND(
2900                 OUTPUT
2901                         ${_read_me_first}
2902                 COMMAND ${ASCIIDOCTOR_EXECUTABLE}
2903                         --backend html
2904                         --out-file ${_read_me_first}
2905                         --attribute include-dir=${CMAKE_SOURCE_DIR}/docbook
2906                         --attribute min-macos-version=${MIN_MACOS_VERSION}
2907                         ${CMAKE_CURRENT_SOURCE_DIR}/packaging/macosx/Read_me_first.adoc
2908                 DEPENDS
2909                         ${CMAKE_CURRENT_SOURCE_DIR}/packaging/macosx/Read_me_first.adoc
2910                 )
2911                 add_custom_target(read_me_first_html DEPENDS ${_read_me_first} )
2912                 add_dependencies(dmg_package_prep read_me_first_html)
2913
2914                 ADD_CUSTOM_TARGET( dmg_package
2915                         COMMAND bash -x ${CMAKE_BINARY_DIR}/packaging/macosx/osx-dmg.sh
2916                         # Unlike nsis_package_prep + nsis_package, we can add a direct
2917                         # dependency here.
2918                         DEPENDS dmg_package_prep
2919                         # We create Wireshark.app in "run". Do our work there.
2920                         WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/run
2921                 )
2922         endif()
2923
2924 endif()
2925
2926 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
2927         find_program(RPMBUILD_EXECUTABLE rpmbuild)
2928         find_program(DPKG_BUILDPACKAGE_EXECUTABLE dpkg-buildpackage)
2929         find_program(GIT_EXECUTABLE git)
2930         # Should we add appimaged's monitored directories
2931         # as HINTS?
2932         # https://github.com/AppImage/appimaged
2933         find_program(LINUXDEPLOYQT_EXECUTABLE linuxdeployqt)
2934         find_program(APPIMAGETOOL_EXECUTABLE appimagetool)
2935 endif()
2936
2937
2938 string(REPLACE "-" "_" RPM_VERSION "${VERSION}")
2939 configure_file(packaging/rpm/wireshark.spec.in ${CMAKE_BINARY_DIR}/packaging/rpm/SPECS/wireshark.spec)
2940 if(RPMBUILD_EXECUTABLE)
2941         foreach(_rpm_dir BUILD RPMS SOURCES SPECS SRPMS)
2942                 file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/packaging/rpm/${_rpm_dir}")
2943         endforeach()
2944
2945         set(_rpmbuild_with_args)
2946         if(CMAKE_GENERATOR STREQUAL "Ninja")
2947                 list(APPEND _rpmbuild_with_args --with ninja)
2948         endif()
2949         if(CCACHE_EXECUTABLE)
2950                 list(APPEND _rpmbuild_with_args --with ccache)
2951         endif()
2952         if(NOT BUILD_wireshark)
2953                 list(APPEND _rpmbuild_with_args --without qt5)
2954         endif()
2955         if (MAXMINDDB_FOUND)
2956                 list(APPEND _rpmbuild_with_args --with mmdbresolve)
2957         endif()
2958         if (LUA_FOUND)
2959                 list(APPEND _rpmbuild_with_args --with lua)
2960         endif()
2961         if (LZ4_FOUND AND SNAPPY_FOUND)
2962                 list(APPEND _rpmbuild_with_args --with lz4_and_snappy)
2963         endif()
2964         if (CARES_FOUND)
2965                 list(APPEND _rpmbuild_with_args --with c_ares)
2966         endif()
2967         if (SPANDSP_FOUND)
2968                 list(APPEND _rpmbuild_with_args --with spandsp)
2969         endif()
2970         if (BCG729_FOUND)
2971                 list(APPEND _rpmbuild_with_args --with bcg729)
2972         endif()
2973         if (LIBXML2_FOUND)
2974                 list(APPEND _rpmbuild_with_args --with libxml2)
2975         endif()
2976         if (NGHTTP2_FOUND)
2977                 list(APPEND _rpmbuild_with_args --with nghttp2)
2978         endif()
2979         if (SYSTEMD_FOUND)
2980                 list(APPEND _rpmbuild_with_args --with sdjournal)
2981         endif()
2982         if (BROTLI_FOUND)
2983                 list(APPEND _rpmbuild_with_args --with brotli)
2984         endif()
2985
2986         execute_process(
2987                 COMMAND ${PERL_EXECUTABLE}
2988                         ${CMAKE_SOURCE_DIR}/tools/make-version.pl
2989                         ${CMAKE_SOURCE_DIR}
2990         )
2991
2992         # XXX Replace with the "dist" target?
2993         set(_export_tarball "${PROJECT_NAME}-${VERSION}.tar.xz")
2994         add_custom_command(
2995                 OUTPUT "${CMAKE_BINARY_DIR}/packaging/rpm/SOURCES/${_export_tarball}"
2996                 COMMAND ${CMAKE_BINARY_DIR}/packaging/source/git-export-release.sh
2997                         -d "${CMAKE_BINARY_DIR}/packaging/rpm/SOURCES"
2998                         "${VERSION}"
2999                 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
3000         )
3001         add_custom_target(rpm-package
3002                 COMMAND ${RPMBUILD_EXECUTABLE}
3003                         --define "_topdir ${CMAKE_BINARY_DIR}/packaging/rpm"
3004                         --define "_prefix ${CMAKE_INSTALL_PREFIX}"
3005                         ${_rpmbuild_with_args}
3006                         -v
3007                         -ba SPECS/wireshark.spec
3008                 DEPENDS "${CMAKE_BINARY_DIR}/packaging/rpm/SOURCES/${_export_tarball}"
3009                 WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/packaging/rpm"
3010                 COMMENT "Create a tarball from the current git commit."
3011         )
3012 endif()
3013
3014 if(DPKG_BUILDPACKAGE_EXECUTABLE)
3015         add_custom_target(deb-package
3016                 COMMAND ${DPKG_BUILDPACKAGE_EXECUTABLE} -us -uc
3017                 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
3018         )
3019 endif()
3020
3021 if(LINUXDEPLOYQT_EXECUTABLE AND APPIMAGETOOL_EXECUTABLE)
3022         # The documentation at https://github.com/probonopd/linuxdeployqt
3023         # says that you need to set CMAKE_BUILD_TYPE=Release and
3024         # CMAKE_INSTALL_PREFIX=/usr. I (gcc) also had to set
3025         # CMAKE_INSTALL_LIBDIR=/usr/lib.
3026         if (CMAKE_BUILD_TYPE STREQUAL "Release" AND CMAKE_INSTALL_PREFIX STREQUAL "/usr" AND CMAKE_INSTALL_LIBDIR STREQUAL "/usr/lib" )
3027                 add_custom_target(appimage-prerequisites)
3028                 add_dependencies(appimage-prerequisites ${PROGLIST})
3029         else()
3030                 add_custom_target(appimage-prerequisites
3031                         COMMAND echo "CMAKE_BUILD_TYPE isn't Release or CMAKE_INSTALL_PREFIX isn't /usr or CMAKE_INSTALL_LIBDIR isn't /usr/lib."
3032                         COMMAND false
3033                 )
3034         endif()
3035         set (_ai_appdir "${CMAKE_BINARY_DIR}/packaging/appimage/appdir")
3036         add_custom_target(appimage-appdir
3037                 COMMAND ${CMAKE_COMMAND} -E make_directory "${_ai_appdir}"
3038                 COMMAND env DESTDIR=${_ai_appdir}
3039                         ${CMAKE_COMMAND} --build . --target install
3040                 DEPENDS appimage-prerequisites
3041         )
3042         set(_exe_args)
3043         foreach(_prog ${PROGLIST})
3044                 # XXX Is this the correct path?
3045                 list(APPEND _exe_args "-executable=${_ai_appdir}/usr/bin/${_prog}")
3046         endforeach()
3047         # linuxdeployqt currently clobbers AppRun:
3048         # https://github.com/probonopd/linuxdeployqt/issues/159
3049         # When that's fixed we will no longer need appimagetool. Until
3050         # then, we need to prep and package in two steps:
3051         # https://github.com/probonopd/linuxdeployqt/wiki/Custom-wrapper-script-instead-of-AppRun
3052         add_custom_target(appimage-prep
3053                 COMMAND ${LINUXDEPLOYQT_EXECUTABLE}
3054                         "${_ai_appdir}/usr/share/applications/wireshark.desktop"
3055                         ${_exe_args}
3056                 COMMAND rm -f "${_ai_appdir}/AppRun"
3057                 COMMAND install
3058                         "${CMAKE_SOURCE_DIR}/packaging/appimage/AppRun"
3059                         "${_ai_appdir}/AppRun"
3060                 DEPENDS appimage-appdir
3061         )
3062         add_custom_target(appimage
3063                 COMMAND env VERSION=${PROJECT_VERSION} ${APPIMAGETOOL_EXECUTABLE} appdir
3064                 WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/packaging/appimage"
3065                 DEPENDS appimage-prep
3066         )
3067 endif()
3068
3069 set(CLEAN_C_FILES
3070         ${dumpcap_FILES}
3071         ${wireshark_FILES}
3072         ${tshark_FILES}
3073         ${rawshark_FILES}
3074         ${dftest_FILES}
3075         ${randpkt_FILES}
3076         ${randpktdump_FILES}
3077         ${udpdump_FILES}
3078         ${text2pcap_FILES}
3079         ${mergecap_FILES}
3080         ${capinfos_FILES}
3081         ${captype_FILES}
3082         ${editcap_FILES}
3083         ${idl2wrs_FILES}
3084         ${mmdbresolve_FILES}
3085 )
3086
3087 if(CLEAN_C_FILES)
3088         # Make sure we don't pass /WX to rc.exe. Rc doesn't have a /WX flag,
3089         # but it does have /W (warn about invalid code pages) and /X (ignore
3090         # the INCLUDE environment variable).
3091         # This should apparently be handled for us via CMAKE_RC_FLAG_REGEX
3092         # in CMakeRCInformation.cmake but that doesn't appear to work.
3093         if(WIN32)
3094                 list(FILTER CLEAN_C_FILES EXCLUDE REGEX ".*\\.rc")
3095         endif()
3096
3097         # XXX This also contains object files ($<TARGET_OBJECTS:...>), is that an issue?
3098         set_source_files_properties(
3099                 ${CLEAN_C_FILES}
3100                 PROPERTIES
3101                 COMPILE_FLAGS "${WERROR_COMMON_FLAGS}"
3102         )
3103 endif()
3104
3105 install(
3106         FILES
3107                 ${INSTALL_FILES}
3108         PERMISSIONS
3109                 OWNER_WRITE OWNER_READ
3110                 GROUP_READ
3111                 WORLD_READ
3112         DESTINATION
3113                 ${CMAKE_INSTALL_DATADIR}
3114 )
3115
3116 set(SHARK_PUBLIC_HEADERS
3117         cfile.h
3118         cli_main.h
3119         file.h
3120         globals.h
3121         log.h
3122         ws_attributes.h
3123         ws_compiler_tests.h
3124         ws_diag_control.h
3125         ws_symbol_export.h
3126         version_info.h
3127         ${CMAKE_BINARY_DIR}/ws_version.h
3128 )
3129
3130 install(FILES ${SHARK_PUBLIC_HEADERS}
3131         DESTINATION ${PROJECT_INSTALL_INCLUDEDIR}
3132 )
3133
3134 # Install icons and other desktop files for Freedesktop.org-compliant desktops.
3135 if((BUILD_wireshark AND QT_FOUND) AND NOT (WIN32 OR APPLE))
3136         install(FILES wireshark-mime-package.xml
3137                 DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/mime/packages"
3138                 RENAME wireshark.xml
3139         )
3140         install(FILES wireshark.appdata.xml
3141                 DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/appdata"
3142         )
3143         if(BUILD_wireshark AND QT_FOUND)
3144                 install(FILES wireshark.desktop
3145                         DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications")
3146         endif()
3147         foreach(size 16 24 32 48 64 128 256)
3148                 install(FILES image/wsicon${size}.png
3149                         DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/${size}x${size}/apps"
3150                         RENAME wireshark.png)
3151                 install(FILES image/WiresharkDoc-${size}.png
3152                         DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/${size}x${size}/mimetypes"
3153                         RENAME application-wireshark-doc.png)
3154         endforeach()
3155         install(FILES image/wsicon.svg
3156                 DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/apps"
3157                 RENAME wireshark.svg)
3158 endif()
3159
3160 install(
3161         FILES
3162                 "${CMAKE_BINARY_DIR}/wireshark.pc"
3163         DESTINATION
3164                 ${CMAKE_INSTALL_LIBDIR}/pkgconfig
3165 )
3166
3167 install(
3168         DIRECTORY
3169                 ${INSTALL_DIRS}
3170         DESTINATION
3171                 ${CMAKE_INSTALL_DATADIR}
3172         FILE_PERMISSIONS
3173                 OWNER_WRITE OWNER_READ
3174                 GROUP_READ
3175                 WORLD_READ
3176         DIRECTORY_PERMISSIONS
3177                 OWNER_EXECUTE OWNER_WRITE OWNER_READ
3178                 GROUP_EXECUTE GROUP_READ
3179                 WORLD_EXECUTE WORLD_READ
3180         PATTERN ".git" EXCLUDE
3181         PATTERN ".svn" EXCLUDE
3182         PATTERN "Makefile.*" EXCLUDE
3183 )
3184
3185 if(WIN32)
3186         # Note: CMake export mechanism misbehaves with a '.' in the
3187         # path (incorrect relative path computation).
3188         set(WIRESHARK_INSTALL_CMAKEDIR "cmake")
3189 else()
3190         set(WIRESHARK_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/cmake")
3191 endif()
3192
3193 install(
3194         FILES
3195                 ${CMAKE_MODULE_PATH}/FindGLIB2.cmake
3196                 ${CMAKE_MODULE_PATH}/FindWSWinLibs.cmake
3197                 ${CMAKE_MODULE_PATH}/UseAsn2Wrs.cmake
3198                 ${CMAKE_MODULE_PATH}/LocatePythonModule.cmake
3199                 ${CMAKE_MODULE_PATH}/UseMakePluginReg.cmake
3200         DESTINATION
3201                 ${WIRESHARK_INSTALL_CMAKEDIR}
3202 )
3203
3204 include(CMakePackageConfigHelpers)
3205
3206 configure_package_config_file(WiresharkConfig.cmake.in
3207         ${CMAKE_BINARY_DIR}/WiresharkConfig.cmake
3208         INSTALL_DESTINATION ${WIRESHARK_INSTALL_CMAKEDIR}
3209         PATH_VARS
3210                 CMAKE_INSTALL_LIBDIR
3211                 CMAKE_INSTALL_INCLUDEDIR
3212                 PLUGIN_INSTALL_VERSION_LIBDIR
3213                 EXTCAP_INSTALL_LIBDIR
3214 )
3215
3216 write_basic_package_version_file(
3217         ${CMAKE_BINARY_DIR}/WiresharkConfigVersion.cmake
3218         COMPATIBILITY AnyNewerVersion
3219 )
3220
3221 install(
3222         FILES
3223                 ${CMAKE_BINARY_DIR}/WiresharkConfig.cmake
3224                 ${CMAKE_BINARY_DIR}/WiresharkConfigVersion.cmake
3225         DESTINATION
3226                 ${WIRESHARK_INSTALL_CMAKEDIR}
3227 )
3228
3229 install(EXPORT WiresharkTargets
3230         DESTINATION ${WIRESHARK_INSTALL_CMAKEDIR}
3231 )
3232
3233 if (DOXYGEN_EXECUTABLE)
3234         # API reference
3235         # We don't have a good way of tracking dependencies, so we simply
3236         # recreate the whole thing from scratch each time.
3237         add_custom_target(wsar_html
3238                 COMMAND ${CMAKE_COMMAND} -E remove_directory wsar_html
3239                 COMMAND ${DOXYGEN_EXECUTABLE} doxygen.cfg
3240         )
3241
3242         add_custom_target(wsar_html_zip
3243                 COMMAND ${CMAKE_COMMAND} -E tar "cfv" "wsar_html.zip" --format=zip wsar_html
3244                 DEPENDS wsar_html
3245         )
3246         set_target_properties(wsar_html wsar_html_zip PROPERTIES
3247                 FOLDER "Docs"
3248                 EXCLUDE_FROM_DEFAULT_BUILD True
3249         )
3250 endif(DOXYGEN_EXECUTABLE)
3251
3252 add_custom_target(test-programs
3253         DEPENDS exntest
3254                 oids_test
3255                 reassemble_test
3256                 tvbtest
3257                 wmem_test
3258         COMMENT "Building unit test programs and wrapper"
3259 )
3260 set_target_properties(test-programs PROPERTIES
3261         FOLDER "Tests"
3262         EXCLUDE_FROM_DEFAULT_BUILD True
3263 )
3264
3265 # Test suites
3266 enable_testing()
3267 # We could try to build this list dynamically, but given that we tend to
3268 # go years between adding suites just run
3269 #     test/test.py --list-groups | sort
3270 # and paste the output here.
3271 set(_test_group_list
3272         suite_capture
3273         suite_clopts
3274         suite_decryption
3275         suite_dfilter.group_bytes_ether
3276         suite_dfilter.group_bytes_ipv6
3277         suite_dfilter.group_bytes_type
3278         suite_dfilter.group_double
3279         suite_dfilter.group_dfunction_string
3280         suite_dfilter.group_integer
3281         suite_dfilter.group_integer_1byte
3282         suite_dfilter.group_ipv4
3283         suite_dfilter.group_membership
3284         suite_dfilter.group_range_method
3285         suite_dfilter.group_scanner
3286         suite_dfilter.group_string_type
3287         suite_dfilter.group_stringz
3288         suite_dfilter.group_time_relative
3289         suite_dfilter.group_time_type
3290         suite_dfilter.group_tvb
3291         suite_dfilter.group_uint64
3292         suite_dissection
3293         suite_dissectors.group_asterix
3294         suite_fileformats
3295         suite_follow
3296         suite_io
3297         suite_mergecap
3298         suite_nameres
3299         suite_outputformats
3300         suite_text2pcap
3301         suite_sharkd
3302         suite_unittests
3303         suite_wslua
3304 )
3305
3306 # We don't currently handle spaces in arguments. On Windows this
3307 # means that you will probably have to pass in an interface index
3308 # instead of a name.
3309 set(TEST_EXTRA_ARGS "" CACHE STRING "Extra arguments to pass to test/test.py")
3310 separate_arguments(TEST_EXTRA_ARGS)
3311
3312 foreach(_group_name ${_test_group_list})
3313         add_test(
3314                 NAME ${_group_name}
3315                 COMMAND ${CMAKE_COMMAND} -E env PYTHONIOENCODING=UTF-8
3316                         ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/test/test.py
3317                         --verbose
3318                         --program-path ${WS_PROGRAM_PATH}
3319                         ${TEST_EXTRA_ARGS}
3320                         ${_group_name}
3321                 )
3322         set_tests_properties(${_group_name} PROPERTIES TIMEOUT 600)
3323 endforeach()
3324
3325 # Make it possible to run pytest without passing the full path as argument.
3326 if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
3327         file(READ "${CMAKE_CURRENT_SOURCE_DIR}/pytest.ini" pytest_ini)
3328         string(REGEX REPLACE "\naddopts = ([^\n]+)"
3329                 "\naddopts = ${CMAKE_CURRENT_SOURCE_DIR}/test \\1"
3330                 pytest_ini "${pytest_ini}")
3331         file(WRITE "${CMAKE_BINARY_DIR}/pytest.ini" "${pytest_ini}")
3332 endif()
3333
3334 if (GIT_EXECUTABLE)
3335         # Update AUTHORS file with entries from git shortlog
3336         add_custom_target(
3337                 gen-authors
3338                 COMMAND ${PERL_EXECUTABLE} tools/generate_authors.pl AUTHORS.src > AUTHORS
3339                 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
3340         )
3341 else (GIT_EXECUTABLE)
3342         add_custom_target( gen-authors COMMAND ${CMAKE_COMMAND} -E echo "Git not found." )
3343 endif (GIT_EXECUTABLE)
3344 set_target_properties(gen-authors PROPERTIES FOLDER "Docs")
3345
3346 if (WIN32)
3347         file (TO_NATIVE_PATH ${CMAKE_SOURCE_DIR}/tools/Get-HardenFlags.ps1 _win_harden_flags)
3348         add_custom_target(hardening-check
3349                 COMMAND ${POWERSHELL_COMMAND} "${_win_harden_flags}" "${_dll_output_dir_win}"
3350                 DEPENDS ${PROGLIST}
3351                 COMMENT "Checking binaries for security features"
3352         )
3353         set_target_properties(hardening-check PROPERTIES FOLDER "Tests")
3354 else ()
3355         find_program(HARDENING_CHECK_EXECUTABLE hardening-check
3356                 DOC "Path to the hardening-check utility."
3357         )
3358         if(HARDENING_CHECK_EXECUTABLE)
3359                 foreach(_prog ${PROGLIST})
3360                         get_target_property(_prog_dir ${_prog} RUNTIME_OUTPUT_DIRECTORY)
3361                         if(NOT _prog_dir)
3362                                 set(_prog_dir "${CMAKE_BINARY_DIR}/run")
3363                         endif()
3364                         set(_prog_paths ${_prog_paths} "${_prog_dir}/${_prog}")
3365                 endforeach()
3366                 add_custom_target(hardening-check
3367                         COMMAND ${HARDENING_CHECK_EXECUTABLE} ${_prog_paths}
3368                         DEPENDS ${PROGLIST}
3369                         COMMENT "Checking binaries for security features"
3370                 )
3371         endif()
3372 endif()
3373
3374 CHECKAPI(
3375         NAME
3376           main
3377         SWITCHES
3378           -build
3379         SOURCES
3380           ${WIRESHARK_SRC}
3381           ${TSHARK_TAP_SRC}
3382 )
3383
3384 find_program(SHELLCHECK_EXECUTABLE shellcheck
3385         DOC "Path to the shellcheck utility."
3386 )
3387 if(SHELLCHECK_EXECUTABLE)
3388         add_custom_target(shellcheck)
3389         set_target_properties(shellcheck PROPERTIES FOLDER "Tests")
3390         # --external-sources requires 0.4.0 or later.
3391         add_custom_command(TARGET shellcheck POST_BUILD
3392                 COMMAND shellcheck --external-sources
3393                         image/stock_icons/svg-to-png.sh
3394                         packaging/appimage/AppRun
3395                         packaging/macosx/osx-app.sh.in
3396                         packaging/macosx/osx-dmg.sh.in
3397                         packaging/source/git-export-release.sh.in
3398                         tools/compress-pngs.sh
3399                         tools/debian-setup.sh
3400                         tools/fuzz-test.sh
3401                         tools/gen-bugnote
3402                         tools/pre-commit
3403                         tools/randpkt-test.sh
3404                         tools/release-update-debian-soversions.sh
3405                         tools/test-captures.sh
3406                         tools/update-tx
3407                         tools/valgrind-wireshark.sh
3408                 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
3409         )
3410 endif()
3411
3412 #
3413 # Editor modelines  -  https://www.wireshark.org/tools/modelines.html
3414 #
3415 # Local variables:
3416 # c-basic-offset: 8
3417 # tab-width: 8
3418 # indent-tabs-mode: t
3419 # End:
3420 #
3421 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
3422 # :indentSize=8:tabSize=8:noTabs=false:
3423 #