Revert "CMake: Replace deprecated module FindPythonInterp"
[metze/wireshark/wip.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 if(DEFINED ENV{FORCE_CMAKE_NINJA_NON_VERBOSE})
10         #
11         # Forcibly unset CMAKE_VERBOSE_MAKEFILE,
12         # to make *CERTAIN* that we don't do
13         # anything verbose here!
14         #
15         unset(CMAKE_VERBOSE_MAKEFILE CACHE)
16 endif()
17
18 # Needed for add_custom_command() WORKING_DIRECTORY generator expressions
19 cmake_minimum_required(VERSION 3.13)
20 if(POLICY CMP0083)
21         cmake_policy(SET CMP0083 NEW)
22 endif()
23
24 if(WIN32)
25         if(DEFINED ENV{MSYSTEM})
26                 set(_msystem $ENV{MSYSTEM})
27                 set(_repository False)
28                 message(STATUS "Using MSYS2 with MSYSTEM=${_msystem}")
29         else()
30                 set(_msystem False)
31                 set(_repository True)
32                 message(STATUS "Using 3rd party repository")
33         endif()
34         set(USE_MSYSTEM ${_msystem} CACHE INTERNAL "Use MSYS2 subsystem")
35         set(HAVE_MSYSTEM ${USE_MSYSTEM}) # For config.h
36         set(USE_REPOSITORY ${_repository} CACHE INTERNAL "Use Wireshark 3rd Party Repository")
37 endif()
38
39 if(WIN32 AND NOT USE_MSYSTEM)
40         set(_project_name Wireshark)
41         set(_log_project_name Logray)
42 else()
43         set(_project_name wireshark)
44         set(_log_project_name logray)
45 endif()
46
47 project(${_project_name} C CXX)
48
49 # Updated by tools/make-version.py
50 set(PROJECT_MAJOR_VERSION 4)
51 set(PROJECT_MINOR_VERSION 1)
52 set(PROJECT_PATCH_VERSION 0)
53 set(PROJECT_BUILD_VERSION 0)
54 set(PROJECT_VERSION_EXTENSION "")
55
56 if(DEFINED ENV{WIRESHARK_VERSION_EXTRA})
57         set(PROJECT_VERSION_EXTENSION "$ENV{WIRESHARK_VERSION_EXTRA}")
58 endif()
59
60 set(PROJECT_VERSION "${PROJECT_MAJOR_VERSION}.${PROJECT_MINOR_VERSION}.${PROJECT_PATCH_VERSION}${PROJECT_VERSION_EXTENSION}")
61
62 set(LOG_PROJECT_NAME ${_log_project_name})
63 set(LOG_PROJECT_MAJOR_VERSION 0)
64 set(LOG_PROJECT_MINOR_VERSION 8)
65 set(LOG_PROJECT_PATCH_VERSION 3)
66 set(LOG_PROJECT_VERSION "${LOG_PROJECT_MAJOR_VERSION}.${LOG_PROJECT_MINOR_VERSION}.${LOG_PROJECT_PATCH_VERSION}${PROJECT_VERSION_EXTENSION}")
67
68 include( CMakeOptions.txt )
69
70 # We require minimum C11
71 set(CMAKE_C_STANDARD 11)
72 set(CMAKE_C_STANDARD_REQUIRED ON)
73
74 # We require minimum C++11
75 set(CMAKE_CXX_STANDARD 11)
76 set(CMAKE_CXX_STANDARD_REQUIRED ON)
77 set(CMAKE_CXX_EXTENSIONS OFF)
78
79 message(STATUS "Generating build using CMake ${CMAKE_VERSION}")
80
81 # Set a default build type if none was specified
82 set(_default_build_type "RelWithDebInfo")
83 if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
84         set(CMAKE_BUILD_TYPE "${_default_build_type}" CACHE STRING "Choose the type of build." FORCE)
85         # Set the possible values of build type for cmake-gui
86         set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
87 endif()
88
89 # Build type is ignored by multi-config generators.
90 if (NOT CMAKE_CONFIGURATION_TYPES)
91         message(STATUS "Using \"${CMAKE_GENERATOR}\" generator and build type \"${CMAKE_BUILD_TYPE}\"")
92 else()
93         message(STATUS "Using \"${CMAKE_GENERATOR}\" generator (multi-config)")
94 endif()
95
96 #Where to find local cmake scripts
97 set(WS_CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
98 set(CMAKE_MODULE_PATH ${WS_CMAKE_MODULE_PATH})
99
100 # CMake >= 3.9.0 supports LTO/IPO.
101 if (ENABLE_LTO)
102         include(CheckIPOSupported)
103         check_ipo_supported(RESULT lto_supported OUTPUT lto_output)
104         if(lto_supported)
105                 set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
106                 message(STATUS "LTO/IPO is enabled for Release configuration")
107         else()
108                 message(STATUS "LTO/IPO requested but it is not supported by the compiler: ${lto_output}")
109         endif()
110 else()
111         message(STATUS "LTO/IPO is not enabled")
112 endif()
113
114 # If our target platform is enforced by our generator, set
115 # WIRESHARK_TARGET_PLATFORM accordingly. Otherwise use
116 # %WIRESHARK_TARGET_PLATFORM%.
117
118 # XXX We should probably consolidate WIRESHARK_TARGET_PLATFORM and
119 # WIRESHARK_TARGET_PROCESSOR_ARCHITECTURE and just use "x64" and "arm64"
120 # instead of "win64" and "win64arm"
121
122 if(WIN32)
123         if(DEFINED ENV{WIRESHARK_TARGET_PLATFORM})
124                 string(TOLOWER $ENV{WIRESHARK_TARGET_PLATFORM} _target_platform)
125                 set(WIRESHARK_TARGET_PLATFORM ${_target_platform})
126         elseif(USE_MSYSTEM MATCHES "MINGW64|CLANG64|UCRT64")
127                 # https://www.msys2.org/docs/environments
128                 #    MSYS2 comes with different environments/subsystems and
129                 #    the first thing you have to decide is which one to use.
130                 #    The differences among the environments are mainly environment
131                 #    variables, default compilers/linkers, architecture,
132                 #    system libraries used etc. If you are unsure, go with UCRT64.
133                 set(WIRESHARK_TARGET_PLATFORM win64)
134         elseif(USE_MSYSTEM)
135                 if($ENV{MSYSTEM_CARCH} MATCHES "x86_64")
136                         set(WIRESHARK_TARGET_PLATFORM win64)
137                 elseif($ENV{MSYSTEM_CARCH} MATCHES "i686")
138                         set(WIRESHARK_TARGET_PLATFORM win32)
139                 elseif($ENV{MSYSTEM_CARCH} MATCHES "aarch64")
140                         set(WIRESHARK_TARGET_PLATFORM "win64arm")
141                 else()
142                         set(WIRESHARK_TARGET_PLATFORM "$ENV{MSYSTEM_CARCH}")
143                 endif()
144         elseif($ENV{Platform} MATCHES arm64 OR CMAKE_GENERATOR_PLATFORM MATCHES arm64)
145                 set(WIRESHARK_TARGET_PLATFORM win64arm)
146         elseif(CMAKE_CL_64 OR CMAKE_GENERATOR MATCHES Win64)
147                 set(WIRESHARK_TARGET_PLATFORM win64)
148         else()
149                 message(WARNING "Assuming \"win64\" target platform")
150                 set(WIRESHARK_TARGET_PLATFORM win64)
151         endif()
152
153         if(WIRESHARK_TARGET_PLATFORM MATCHES "win64")
154                 set(WIRESHARK_TARGET_PROCESSOR_ARCHITECTURE x64)
155         elseif(WIRESHARK_TARGET_PLATFORM MATCHES "win64arm")
156                 set(WIRESHARK_TARGET_PROCESSOR_ARCHITECTURE arm64)
157         elseif(WIRESHARK_TARGET_PLATFORM MATCHES "win32")
158                 message(FATAL_ERROR "Deprecated target platform ${WIRESHARK_TARGET_PLATFORM}. See https://gitlab.com/wireshark/wireshark/-/issues/17779 for details.")
159                 set(WIRESHARK_TARGET_PROCESSOR_ARCHITECTURE x86)
160         else()
161                 message(FATAL_ERROR "Invalid target platform: ${WIRESHARK_TARGET_PLATFORM}")
162         endif()
163
164         # Sanity check
165         if(MSVC)
166                 if(DEFINED ENV{PLATFORM})
167                         string(TOLOWER $ENV{PLATFORM} _vs_platform)
168                 else()
169                         set(_vs_platform "[undefined]") # x86
170                 endif()
171                 if(
172                         (_vs_platform STREQUAL "x64" AND NOT WIRESHARK_TARGET_PLATFORM STREQUAL "win64")
173                         OR
174                         (_vs_platform STREQUAL "[undefined]" AND NOT WIRESHARK_TARGET_PLATFORM STREQUAL "win32")
175                 )
176                         message(FATAL_ERROR "The PLATFORM environment variable (${_vs_platform})"
177                                 " doesn't match the generator platform (${WIRESHARK_TARGET_PLATFORM})")
178                 endif()
179         endif()
180         message(STATUS
181                 "Building for ${WIRESHARK_TARGET_PLATFORM} \
182 and CPU target ${WIRESHARK_TARGET_PROCESSOR_ARCHITECTURE}"
183         )
184
185         find_package(PowerShell REQUIRED)
186
187         # Determine where the 3rd party libraries will be
188         if(USE_REPOSITORY)
189                 if( DEFINED ENV{WIRESHARK_LIB_DIR} )
190                         # The buildbots set WIRESHARK_LIB_DIR but not WIRESHARK_BASE_DIR.
191                         file( TO_CMAKE_PATH "$ENV{WIRESHARK_LIB_DIR}" _PROJECT_LIB_DIR )
192                 elseif( DEFINED ENV{WIRESHARK_BASE_DIR} )
193                         file( TO_CMAKE_PATH "$ENV{WIRESHARK_BASE_DIR}" _WS_BASE_DIR )
194                         set( _PROJECT_LIB_DIR "${_WS_BASE_DIR}/wireshark-${WIRESHARK_TARGET_PLATFORM}-libs" )
195                 else()
196                         # Don't know what to do
197                         message(FATAL_ERROR "Neither WIRESHARK_BASE_DIR or WIRESHARK_LIB_DIR are defined")
198                 endif()
199
200                 # Download third-party libraries
201                 file (TO_NATIVE_PATH ${CMAKE_SOURCE_DIR}/tools/win-setup.ps1 _win_setup)
202                 file (TO_NATIVE_PATH ${_PROJECT_LIB_DIR} _ws_lib_dir)
203                 file (TO_NATIVE_PATH ${CMAKE_COMMAND} _win_cmake_command)
204
205                 # Is it possible to have a one-time, non-cached option in CMake? If
206                 # so, we could add a "-DFORCE_WIN_SETUP" which passes -Force to
207                 # win-setup.ps1.
208                 execute_process(
209                         COMMAND ${POWERSHELL_COMMAND} "\"${_win_setup}\"" -Destination "${_ws_lib_dir}" -Platform ${WIRESHARK_TARGET_PLATFORM} -CMakeExecutable "\"${_win_cmake_command}\""
210                         RESULT_VARIABLE _win_setup_failed
211                         ERROR_VARIABLE _win_setup_error_output
212                 )
213                 if(_win_setup_failed)
214                         message(FATAL_ERROR "Windows setup (win-setup.ps1) failed: ${_win_setup_error_output}.")
215                 endif()
216
217                 set(EXTRA_INSTALLER_DIR ${_ws_lib_dir})
218
219                 # XXX Add a dependency on ${_ws_lib_dir}/current_tag.txt?
220         else()
221                 set(EXTRA_INSTALLER_DIR ${CMAKE_BINARY_DIR}/packaging/nsis)
222         endif()
223 endif(WIN32)
224
225 include(UseCustomIncludes)
226 ADD_CUSTOM_CMAKE_INCLUDE()
227
228 # Ensure that all executables and libraries end up in the same directory. Actual
229 # files might end up in a configuration subdirectory, e.g. run/Debug or
230 # run/Release. We try to set DATAFILE_DIR to actual location below.
231 if(NOT ARCHIVE_OUTPUT_PATH)
232         set(ARCHIVE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/run CACHE INTERNAL
233                    "Single output directory for building all archives.")
234 endif()
235 if(NOT EXECUTABLE_OUTPUT_PATH)
236         set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/run CACHE INTERNAL
237                    "Single output directory for building all executables.")
238 endif()
239 if(NOT LIBRARY_OUTPUT_PATH)
240         set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/run CACHE INTERNAL
241                    "Single output directory for building all libraries.")
242 endif()
243
244 #
245 # The release mode (CMAKE_BUILD_TYPE=release) defines NDEBUG for
246 # the Unix Makefile generator.
247 #
248
249 # Defines CMAKE_INSTALL_BINDIR, CMAKE_INSTALL_DATADIR, etc ...
250 if(WIN32 AND NOT USE_MSYSTEM)
251         # Override some values on Windows, to match the existing
252         # convention of installing everything to a single root folder.
253         set(CMAKE_INSTALL_BINDIR ".")
254         set(CMAKE_INSTALL_LIBDIR ".")
255         set(CMAKE_INSTALL_INCLUDEDIR "include")
256         set(CMAKE_INSTALL_DATADIR ".")
257         set(CMAKE_INSTALL_DOCDIR ".")
258 else()
259         # By default INSTALL_DATADIR is set to INSTALL_DATAROOTDIR, set the
260         # proper value here.
261         set(CMAKE_INSTALL_DATADIR "share/${PROJECT_NAME}"
262                 CACHE PATH "Read-only architecture-independent data"
263         )
264 endif()
265 include(GNUInstallDirs)
266
267 set(PROJECT_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}")
268
269 # Make sure our executables can load our libraries if we install into
270 # a non-default directory on Unix-like systems other than macOS.
271 # https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling
272 set(LIBRARY_INSTALL_RPATH "")
273 set(EXECUTABLE_INSTALL_RPATH "")
274 set(EXTCAP_INSTALL_RPATH "")
275 if(NOT (WIN32 OR APPLE OR USE_STATIC))
276         # Try to set a RPATH for installed binaries if the library directory is
277         # not already included in the default search list.
278         list(FIND CMAKE_C_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_FULL_LIBDIR}" IS_SYSTEM_DIR)
279         if(IS_SYSTEM_DIR EQUAL -1)
280                 # Some systems support $ORIGIN in RPATH to enable relocatable
281                 # binaries. In other cases, only absolute paths can be used.
282                 # https://www.lekensteyn.nl/rpath.html
283                 #
284                 # Also note that some systems (notably those using GNU libc)
285                 # silently ignore $ORIGIN in RPATH for binaries that are
286                 # setuid root or use privileged capabilities.
287                 #
288                 if(CMAKE_SYSTEM_NAME MATCHES "^(Linux|SunOS|FreeBSD)$")
289                         set(_enable_rpath_origin TRUE)
290                 else()
291                         set(_enable_rpath_origin FALSE)
292                 endif()
293
294                 # Provide a knob to optionally force absolute rpaths,
295                 # to support old/buggy systems and as a user preference
296                 # for hardening.
297                 # XXX Should this be a CMake option?
298                 set(ENABLE_RPATH_ORIGIN ${_enable_rpath_origin} CACHE BOOL
299                         "Use $ORIGIN with INSTALL_RPATH")
300                 mark_as_advanced(ENABLE_RPATH_ORIGIN)
301
302                 if(ENABLE_RPATH_ORIGIN)
303                         set(LIBRARY_INSTALL_RPATH     "$ORIGIN")
304                         set(EXECUTABLE_INSTALL_RPATH  "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")
305                         set(EXTCAP_INSTALL_RPATH      "$ORIGIN/../..")
306                 else()
307                         set(LIBRARY_INSTALL_RPATH     "${CMAKE_INSTALL_FULL_LIBDIR}")
308                         set(EXECUTABLE_INSTALL_RPATH  "${CMAKE_INSTALL_FULL_LIBDIR}")
309                         set(EXTCAP_INSTALL_RPATH      "${CMAKE_INSTALL_FULL_LIBDIR}")
310                 endif()
311                 # Include non-standard external libraries by default in RPATH.
312                 if(NOT DEFINED CMAKE_INSTALL_RPATH_USE_LINK_PATH)
313                         set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
314                 endif()
315         endif()
316 endif()
317
318 # Ensure that executables in the build directory always have the same RPATH.
319 # This ensures relocatable binaries and reproducible builds (invariant of the
320 # build directory location). (Requires CMake 3.14)
321 set(CMAKE_BUILD_RPATH_USE_ORIGIN ON)
322
323 if(MSVC)
324     # Linking with wsetargv.obj enables "wildcard expansion" of
325     # command-line arguments.
326     set(WILDCARD_OBJ wsetargv.obj)
327 endif()
328
329 include(CheckSymbolExists)
330
331 #
332 # Large file support on UN*X, a/k/a LFS.
333 #
334 # On Windows, we require _fseeki64() and _ftelli64().  Visual
335 # Studio has had supported them since Visual Studio 2005/MSVCR80,
336 # and we require newer versions, so we know we have them.
337 #
338 if(NOT MSVC)
339         include(FindLFS)
340         if(LFS_FOUND)
341                 #
342                 # Add the required #defines.
343                 #
344                 add_definitions(${LFS_DEFINITIONS})
345         endif()
346
347         #
348         # Check for fseeko as well.
349         #
350         include(FindFseeko)
351         if(FSEEKO_FOUND)
352                 set(HAVE_FSEEKO ON)
353
354                 #
355                 # Add the required #defines.
356                 #
357                 add_definitions(${FSEEKO_DEFINITIONS})
358         endif()
359 endif()
360
361 # Banner shown at top right of Qt welcome screen.
362 if(DEFINED ENV{WIRESHARK_VERSION_FLAVOR})
363         set(VERSION_FLAVOR "$ENV{WIRESHARK_VERSION_FLAVOR}")
364 else()
365         set(VERSION_FLAVOR "Development Build")
366 endif()
367
368 # Used in .rc files and manifests
369 set(MANIFEST_PROCESSOR_ARCHITECTURE ${WIRESHARK_TARGET_PROCESSOR_ARCHITECTURE})
370 if (MANIFEST_PROCESSOR_ARCHITECTURE MATCHES "x64")
371         set(MANIFEST_PROCESSOR_ARCHITECTURE "amd64")
372 endif()
373 set(RC_VERSION ${PROJECT_MAJOR_VERSION},${PROJECT_MINOR_VERSION},${PROJECT_PATCH_VERSION},${PROJECT_BUILD_VERSION})
374 set(LOG_RC_VERSION ${LOG_PROJECT_MAJOR_VERSION},${LOG_PROJECT_MINOR_VERSION},${PROJECT_PATCH_VERSION},${PROJECT_BUILD_VERSION})
375
376 message(STATUS "V: ${PROJECT_VERSION}, MaV: ${PROJECT_MAJOR_VERSION}, MiV: ${PROJECT_MINOR_VERSION}, PL: ${PROJECT_PATCH_VERSION}, EV: ${PROJECT_VERSION_EXTENSION}.")
377
378 find_package(PythonInterp)
379 include(UseLemon)
380 include(UseMakePluginReg)
381 include(UseMakeTaps)
382 include(UseExecutableResources)
383 include(UseAsn2Wrs)
384
385 # The following snippet has been taken from
386 # https://github.com/USESystemEngineeringBV/cmake-eclipse-helper/wiki/HowToWorkaroundIndexer
387 # The eclipse indexer otherwise assumes __cplusplus=199711L which will lead to broken
388 # lookup tables for the epan libraries
389 # Check if CXX flags have been set to c++11 -> Setup Eclipse Indexer correctly!
390 # Also setup the project slightly different
391 if(CMAKE_EXTRA_GENERATOR MATCHES "Eclipse CDT4")
392         SET(CXX_ENABLED 0)
393         LIST(LENGTH CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS LIST_LEN)
394         if(LIST_LEN GREATER 0)
395                 SET(CXX_ENABLED 1)
396         endif()
397         SET(C_ENABLED 0)
398         LIST(LENGTH CMAKE_EXTRA_GENERATOR_C_SYSTEM_DEFINED_MACROS LIST_LEN)
399         if(LIST_LEN GREATER 0)
400                 SET(C_ENABLED 1)
401         endif()
402         if(C_ENABLED EQUAL 1 AND CXX_ENABLED EQUAL 1)
403                 # Combined project (C and CXX). This will confuse the indexer. For that reason
404                 # we unsert set the __cplusplus variable for the indexer
405                 list(FIND CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS "__cplusplus" GEN_MACRO_INDEX)
406                 if(GEN_MACRO_INDEX GREATER -1)
407                         list(REMOVE_AT CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS ${GEN_MACRO_INDEX})
408                         list(REMOVE_AT CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS ${GEN_MACRO_INDEX})
409                 endif()
410                 SET(CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS ${CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS} CACHE INTERNAL "")
411         elseif((CXX_ENABLED EQUAL 1) AND (CMAKE_CXX_FLAGS MATCHES ".*-std=c\\+\\+11.*"))
412                 #add_definitions (-D__cplusplus=201103L)
413                 # CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS
414                 list(FIND CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS "199711L" GEN_MACRO_INDEX)
415                 if(GEN_MACRO_INDEX GREATER -1)
416                         list(REMOVE_AT CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS ${GEN_MACRO_INDEX})
417                         list(INSERT CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS ${GEN_MACRO_INDEX} "201103L")
418                         SET(CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS ${CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS} CACHE INTERNAL "")
419                 endif()
420         endif()
421 endif()
422
423 include_directories(
424         ${CMAKE_BINARY_DIR}
425         ${CMAKE_SOURCE_DIR}
426         ${CMAKE_SOURCE_DIR}/include
427 )
428
429 if( DUMPCAP_INSTALL_OPTION STREQUAL "suid" )
430         set( DUMPCAP_SETUID "SETUID" )
431 else()
432         set( DUMPCAP_SETUID )
433 endif()
434 if( NOT CMAKE_SYSTEM_NAME STREQUAL "Linux" AND
435         DUMPCAP_INSTALL_OPTION STREQUAL "capabilities" )
436         message( WARNING "Capabilities are only supported on Linux" )
437         set( DUMPCAP_INSTALL_OPTION )
438 endif()
439
440 set(OSS_FUZZ OFF CACHE BOOL "Whether building for oss-fuzz")
441 mark_as_advanced(OSS_FUZZ)
442 if(OSS_FUZZ)
443         if(ENABLE_FUZZER)
444                 # In oss-fuzz mode, the fuzzing engine can be afl or libFuzzer.
445                 message(FATAL_ERROR "Cannot force libFuzzer when using oss-fuzz")
446         endif()
447         # Must not depend on external dependencies so statically link all libs.
448         set(USE_STATIC ON)
449 endif()
450
451 if(USE_STATIC)
452         set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
453 endif()
454
455 #
456 # Linking can consume a lot of memory, especially when built with ASAN and
457 # static libraries (like oss-fuzz) or Debug mode. With Ninja, the number of
458 # parallel linker processes is constrained by job parallelism (-j), but this can
459 # be reduced further by setting "job pools" to a lower number.
460 #
461 if(CMAKE_MAKE_PROGRAM MATCHES "ninja" AND OSS_FUZZ)
462         # Assume oss-fuzz linker jobs do not require more than 1.2G per task
463         set(per_job_memory_mb 1200)
464         cmake_host_system_information(RESULT total_memory_mb QUERY TOTAL_PHYSICAL_MEMORY)
465         math(EXPR parallel_link_jobs "${total_memory_mb} / ${per_job_memory_mb}")
466         if(parallel_link_jobs LESS 1)
467                 set(parallel_link_jobs 1)
468         endif()
469         set_property(GLOBAL APPEND PROPERTY JOB_POOLS link_job_pool=${parallel_link_jobs})
470         set(CMAKE_JOB_POOL_LINK link_job_pool)
471         message(STATUS "Ninja job pool size: ${parallel_link_jobs}")
472 endif()
473
474 # Always enable position-independent code when compiling, even for
475 # executables, so you can build position-independent executables.
476 # -pie is added below for non-MSVC, but requires objects to be built with
477 # -fPIC/-fPIE (so set CMAKE_POSITION_INDEPENDENT_CODE to enable that).
478 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
479
480 # Preprocessor definitions common to all compilers
481 set_property(DIRECTORY
482         PROPERTY COMPILE_DEFINITIONS
483                 "G_DISABLE_DEPRECATED"
484                 "G_DISABLE_SINGLE_INCLUDES"
485                 $<$<OR:$<BOOL:${ENABLE_DEBUG}>,$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:WS_DEBUG>
486                 $<$<OR:$<BOOL:${ENABLE_DEBUG_UTF_8}>,$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:WS_DEBUG_UTF_8>
487 )
488
489 if(WIN32)
490         #
491         # NOTE: Because of the way Qt moc is including "config.h" (not as the
492         # first header) this *MUST* be defined on the command line to precede
493         # every included header and not trigger symbol redefinition errors.
494         #
495         add_definitions(
496                 -DWIN32_LEAN_AND_MEAN
497                 #
498                 # Use Unicode in Windows runtime functions.
499                 #
500                 -DUNICODE
501                 -D_UNICODE
502                 #
503                 # NOMINMAX keeps windows.h from defining "min" and "max" via windef.h.
504                 # This avoids conflicts with the C++ standard library.
505                 #
506                 -DNOMINMAX
507         )
508 endif()
509
510 if(MINGW)
511         add_definitions(
512                 #
513                 # Enable POSIX APIs. This will switch stdio to ANSI C functions and
514                 # enable C99 conformant vsnprintf() among other things.
515                 #
516                 -D_POSIX
517         )
518         list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_POSIX)
519 endif()
520
521 if( CMAKE_C_COMPILER_ID MATCHES "MSVC")
522         if (MSVC_VERSION LESS "1928")
523                 message(FATAL_ERROR "Microsoft Visual Studio 2019 version 16.8 or later is required")
524         endif()
525         if (MSVC_VERSION GREATER_EQUAL "2000")
526                 message(FATAL_ERROR "You are using an unsupported version of MSVC")
527         endif()
528
529         add_definitions(
530                 /D_CRT_SECURE_NO_DEPRECATE
531                 # -DPSAPI_VERSION=1                 Programs that must run on earlier versions of Windows as well as Windows 7 and later
532                 #                                   versions should always call this function as GetProcessMemoryInfo. To ensure correct
533                 #                                   resolution of symbols, add Psapi.lib to the TARGETLIBS macro and compile the program
534                 #                                   with -DPSAPI_VERSION=1.To use run-time dynamic linking, load Psapi.dll.
535                 #                                   https://docs.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getprocessmemoryinfo
536                 # -D_ALLOW_KEYWORD_MACROS           For VS2012 onwards the, C++ STL does not permit macro redefinitions of keywords
537                 #                                   (see https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2012/bb531344(v=vs.110))
538                 #                                   This definition prevents the complaint about the redefinition of inline by WinPCap
539                 #                                   in pcap-stdinc.h when compiling C++ files, e.g. the Qt UI
540                 /DPSAPI_VERSION=1
541                 /D_ALLOW_KEYWORD_MACROS
542                 # Disable deprecation of POSIX function names.
543                 # https://stackoverflow.com/questions/37845163/what-is-the-purpose-of-microsofts-underscore-c-functions
544                 /D_CRT_NONSTDC_NO_WARNINGS
545         )
546
547         if(NOT WIRESHARK_TARGET_PLATFORM STREQUAL "win64")
548                 add_definitions("/D_BIND_TO_CURRENT_CRT_VERSION=1")
549         endif()
550
551         set(LOCAL_CFLAGS
552                 /MP
553         )
554
555         set(WS_LINK_FLAGS "/LARGEADDRESSAWARE /MANIFEST:NO /INCREMENTAL:NO /RELEASE")
556
557         # To do: Add /external:... See https://devblogs.microsoft.com/cppblog/broken-warnings-theory/
558         #
559         # /diagnostics:caret                Place a caret under compilation issues similar to
560         #                                   Clang and gcc.
561         # /Zo                               Enhanced debugging of optimised code
562         # /utf-8                            Set Source and Executable character sets to UTF-8
563         #                                   VS2015(MSVC14): On by default when /Zi or /Z7 used.
564         # /guard:cf                         Control Flow Guard (compile and link).
565         #                                   See https://docs.microsoft.com/en-us/windows/win32/secbp/control-flow-guard
566         #                                   Note: This requires CMake 3.9.0 or newer.
567         #                                   https://gitlab.kitware.com/cmake/cmake/commit/f973d49ab9d4c59b93f6dac812a94bb130200836
568         # /Qspectre                         Speculative execution attack mitigation
569         #                                   See https://devblogs.microsoft.com/cppblog/spectre-mitigations-in-msvc/
570         list(APPEND LOCAL_CFLAGS /diagnostics:caret /Zo /utf-8 /guard:cf)
571         set(WS_LINK_FLAGS "${WS_LINK_FLAGS} /guard:cf")
572         # /Qspectre is not available for VS2015 or older VS2017. Test for its availability.
573         set(WIRESHARK_COMMON_FLAGS /Qspectre)
574
575         if(ENABLE_CODE_ANALYSIS)
576                 # We should probably add a code_analysis.props file and use it to set
577                 # CAExcludePath, otherwise we trigger on Qt's headers:
578                 # https://stackoverflow.com/questions/59669026/how-to-add-property-to-affect-code-analysis-in-cmake
579                 # https://gitlab.kitware.com/cmake/cmake/-/issues/19682
580                 # For now, we set CAExcludePath=C:\Qt;%include% in the Visual Studio
581                 # Code Analys builder's environment.
582                 list(APPEND LOCAL_CFLAGS /analyze:WX-)
583         endif()
584
585         # Additional compiler warnings to be treated as "Level 3"
586         # when compiling Wireshark sources. (Selected from "level 4" warnings).
587         ## 4295: array is too small to include a terminating null character
588         ## 4100: unreferenced formal parameter
589         ## 4189: local variable is initialized but not referenced
590         # Disable warnings about use of flexible array members:
591         ## 4200: nonstandard extension used : zero-sized array in struct/union
592         list(APPEND LOCAL_CFLAGS /w34295 /w34100 /w34189 /wd4200)
593
594         # MSVC 14.28 + C11 enables C5105, but older Windows SDKs aren't completely compatible.
595         # Windows SDK 10.0.17763.0 generates syntax errors with C11 enabled.
596         if (CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION VERSION_LESS 10.0.18362.0)
597                 message(FATAL_ERROR "Windows SDK ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION} doesn't support C11. Please make sure you're using 10.0.20348.0 or later.")
598         endif()
599         # Windows SDK 10.0.18362.0 to 10.0.19041.685 generate warning C5105 with C11 enabled.
600         if(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION VERSION_LESS 10.0.20348.0)
601                 message(WARNING "Windows SDK ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION} doesn't support C11. Please make sure you're using 10.0.20348.0 or later.")
602                 ## 5105: macro expansion producing 'defined' has undefined behavior
603                 list(APPEND LOCAL_CFLAGS /wd5105)
604         endif()
605
606         # We've matched these to specific compiler versions using the
607         # checks above. There's no need to pass them to check_c_compiler_flag
608         # or check_cxx_compiler_flag, which can be slow.
609         string(REPLACE ";" " " _flags "${LOCAL_CFLAGS}")
610         set(CMAKE_C_FLAGS "${_flags} ${CMAKE_C_FLAGS}")
611         set(CMAKE_CXX_FLAGS "${_flags} ${CMAKE_CXX_FLAGS}")
612
613 else() # ! MSVC
614         if(APPLE)
615                 # MIN_MACOS_VERSION is used to set LSMinimumSystemVersion
616                 # in Info.plist, so start with something low.
617                 set(MIN_MACOS_VERSION 10.10)
618                 if(CMAKE_OSX_DEPLOYMENT_TARGET)
619                         if(CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS MIN_MACOS_VERSION)
620                                 message(FATAL_ERROR "We don't support building for macOS < ${MIN_MACOS_VERSION}")
621                         endif()
622                         set(MIN_MACOS_VERSION ${CMAKE_OSX_DEPLOYMENT_TARGET})
623                 endif()
624         endif()
625
626         #
627         # NOTE: Adding new warnings is a policy decision that can have far-reaching
628         # implications for the project and each developers workflow. Modern
629         # C compilers are on a race to add new warnings, not always sensibly.
630         # They are opt-in so take a moment to fully consider the implications
631         # of enabling the latest shiny new warning.
632         # If in doubt ask on the Wireshark developer list (recommended).
633         #
634         list(APPEND WIRESHARK_COMMON_FLAGS
635                 #
636                 ### Flags common to C and C++ ###
637                 #
638                 # -O<X> and -g get set by the CMAKE_BUILD_TYPE
639                 -Wall
640                 -Wextra
641                 -Wpointer-arith
642                 -Wformat-security
643                 -fno-strict-overflow
644                 -fexcess-precision=fast # GCC-only
645                 -Wvla
646                 -Wattributes
647                 -Wpragmas               # Clang-only
648                 -Wheader-guard          # Clang-only
649                 -Wcomma                 # Clang-only
650                 -Wshorten-64-to-32      # Clang-only
651                 -Wredundant-decls
652                 -Wunreachable-code      # Clang-only
653                 -Wdocumentation         # Clang-only
654                 -Wlogical-op            # GCC-only
655                 #
656                 # Disable errors unconditionally for some static analysis warnings
657                 # that are dormant at lower optimizations levels or active only in
658                 # bleeding edge versions of a compiler and possibly also
659                 # prone to false positives and compiler bugs. This is
660                 # a big nuisance because the warning is dormant and a low
661                 # priority target for action. That is very disruptive
662                 # with -Werror enabled (the default on the master branch).
663                 #
664                 -Wno-error=stringop-overflow=
665                 #
666                 # XXX Now that we have a CI job with Release build type (using
667                 # -O3 optimization level) the dormancy issue should be ameliorated
668                 # so comment out these exceptions to re-evaluate the impact.
669                 #-Wno-error=maybe-uninitialized
670                 #-Wno-error=alloc-size-larger-than=
671                 #
672                 # Updating external dependencies can introduce new deprecations.
673                 # Also fixing new internal deprecations takes time.
674                 # We want to be able to build with -Werror in that case. New
675                 # code should not introduce new deprecations in any case.
676                 #
677                 -Wno-error=deprecated-declarations
678         )
679
680         if((NOT ENABLE_ASAN) AND (NOT ENABLE_TSAN) AND (NOT ENABLE_UBSAN) AND (NOT DISABLE_FRAME_LARGER_THAN_WARNING))
681                 #
682                 # Only do this if none of ASan, TSan, and UBSan are
683                 # enabled; the instrumentation they add increases
684                 # the stack usage - we only care about stack
685                 # usage in normal operation.
686                 #
687                 list(APPEND WIRESHARK_COMMON_FLAGS
688                         -Wframe-larger-than=32768
689                 )
690         endif()
691
692         list(APPEND WIRESHARK_C_ONLY_FLAGS
693                 #
694                 ### Flags for C only ###
695                 #
696                 #
697                 # XXX - some versions of GCC, including the one in at
698                 # least some Xcode versions that come with Mac OS X
699                 # 10.5, complain about variables in function and
700                 # function pointer *declarations* shadowing other
701                 # variables.  The autoconf script checked for that; we
702                 # don't.
703                 -Wshadow
704                 -Wold-style-definition
705                 -Wstrict-prototypes
706         )
707
708         #
709         # The universal zero initializer (in C: struct s x = { 0 };) for
710         # structures with multiple members is perfectly legal, but some older
711         # compilers warn about it. Silence those older compilers.
712         #
713         if((CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "5.1") OR
714            (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "6.0") OR
715            (CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "12.0"))
716                 if(NOT CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_VERSION VERSION_LESS "5.0")
717                         list(APPEND WIRESHARK_C_ONLY_FLAGS -Wno-missing-field-initializers)
718                 endif()
719                 # Silence warnings for initialization of nested structs like
720                 # struct { struct { int a, b; } s; int c; } v = { 0 };
721                 list(APPEND WIRESHARK_C_ONLY_FLAGS -Wno-missing-braces)
722         endif()
723
724         list(APPEND WIRESHARK_CXX_ONLY_FLAGS
725                 #
726                 ### Flags for C++ only ###
727                 #
728                 -Wextra-semi    # Clang-only
729         )
730
731         #
732         # Not all warnings are the same. They fall on a spectrum from "critical"
733         # to "pedantic nonsense". These are warnings that realistically are worth
734         # fixing eventually.
735         #
736         if(ENABLE_TODO_WARNINGS)
737                 list(APPEND WIRESHARK_COMMON_FLAGS
738                         #
739                         # All the registration functions block these for now.
740                         #
741                         -Wmissing-prototypes
742                         -Wmissing-declarations
743                         #
744                         # A bunch of "that might not work on SPARC" code blocks
745                         # this one for now; some of it is code that *will* work
746                         # on SPARC, such as casts of "struct sockaddr *" to
747                         # "struct sockaddr_in *", which are required by some
748                         # APIs such as getifaddrs().
749                         #
750                         -Wcast-align
751                 )
752         else()
753                 list(APPEND WIRESHARK_COMMON_FLAGS
754                         #
755                         # Converting from g_printf() and g_snprintf() to stdio.h turns
756                         # up many of these warnings. They will have to be handled later.
757                         # It can be a lot of work to fix properly and none of them
758                         # seem to flag very interesting issues.
759                         #
760                         -Wno-format-truncation # Enabled with -Wall
761                 )
762                 list(APPEND WIRESHARK_C_ONLY_FLAGS
763                         -Wno-pointer-sign # Enabled with -Wall
764                 )
765         endif()
766
767         #
768         # These are not enabled by default, because the warnings they
769         # produce are very hard or impossible to eliminate.
770         #
771         if(ENABLE_PEDANTIC_COMPILER_WARNINGS)
772                 list(APPEND WIRESHARK_COMMON_FLAGS
773                         # The following are for C and C++
774                         -Wpedantic
775                         -Wno-overlength-strings
776                         -Wno-long-long
777                         #
778                         # As we use variadic macros, we don't want warnings
779                         # about them, even with -Wpedantic.
780                         #
781                         -Wno-variadic-macros
782                         #
783                         # Various code blocks this one.
784                         #
785                         -Woverflow
786                         -fstrict-overflow -Wstrict-overflow=4
787                         #
788                         # Due to various places where APIs we don't control
789                         # require us to cast away constness, we can probably
790                         # never enable this one with -Werror.
791                         #
792                         -Wcast-qual
793                         #
794                         # Doesn't warn of interesting issues. Usually the
795                         # duplicated branches are protocol constants that
796                         # happen to be equal and are relevant for documentation
797                         # and readability and are trivially optimized by the
798                         # compiler.
799                         #
800                         -Wduplicated-branches           # GCC-only
801                         #
802                         # No longer supported by El Capitan clang on C++
803                         # XXX - is this one of those where CMake's check
804                         # doesn't fail, so it won't reject this?
805                         #
806                         -fno-delete-null-pointer-checks
807                 )
808
809                 #
810                 # Some loops are safe, but it's hard to convince the compiler of
811                 # that. Always disable the warning on GCC 7 due to a bug that
812                 # cause lots of false positives.
813                 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81408
814                 #
815                 if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_C_COMPILER_VERSION MATCHES "^7\\.")
816                         list(APPEND WIRESHARK_COMMON_FLAGS -Wunsafe-loop-optimizations)
817                 endif()
818
819                 list(APPEND WIRESHARK_C_ONLY_FLAGS
820                         # The following are C only, not C++
821                         #
822                         # Due to various places where APIs we don't control
823                         # require us to cast away constness, we can probably
824                         # never enable this one with -Werror.
825                         #
826                         -Wbad-function-cast
827                 )
828
829                 list(APPEND WIRESHARK_CXX_ONLY_FLAGS
830                 )
831         endif()
832
833         if(ENABLE_COMPILER_COLOR_DIAGNOSTICS)
834                 if(CMAKE_C_COMPILER_ID MATCHES "Clang")
835                         set(WIRESHARK_COMMON_FLAGS ${WIRESHARK_COMMON_FLAGS}
836                                 -fcolor-diagnostics
837                         )
838                 elseif(CMAKE_C_COMPILER_ID MATCHES "GNU")
839                         set(WIRESHARK_COMMON_FLAGS ${WIRESHARK_COMMON_FLAGS}
840                                 -fdiagnostics-color=always
841                         )
842                 endif()
843         endif()
844
845         set(WIRESHARK_LD_FLAGS
846                 # See also CheckCLinkerFlag.cmake
847                 -Wl,--as-needed
848                 # -flto
849                 # -fwhopr
850                 # -fwhole-program
851         )
852 endif() # ! MSVC
853
854 # Counterhack to work around some cache magic in CHECK_C_SOURCE_COMPILES
855 include(CheckCCompilerFlag)
856 include(CheckCXXCompilerFlag)
857
858 if(ENABLE_STATIC)
859         set(BUILD_SHARED_LIBS 0)
860 else()
861         set(BUILD_SHARED_LIBS 1)
862 endif()
863
864 function(test_compiler_flag _lang _this_flag _valid_flags_var)
865         string(MAKE_C_IDENTIFIER "${_lang}${_this_flag}_VALID" _flag_var)
866         set(_test_flags "${${_valid_flags_var}} ${_this_flag}")
867         if(_lang STREQUAL "C")
868                 check_c_compiler_flag("${_test_flags}" ${_flag_var})
869         elseif(_lang STREQUAL "CXX")
870                 check_cxx_compiler_flag("${_test_flags}" ${_flag_var})
871         else()
872                 message(FATAL_ERROR "Language must be C or CXX")
873         endif()
874         if (${_flag_var})
875                 set(${_valid_flags_var} "${_test_flags}" PARENT_SCOPE)
876         endif()
877 endfunction()
878
879 foreach(THIS_FLAG ${WIRESHARK_COMMON_FLAGS} ${WIRESHARK_C_ONLY_FLAGS})
880         test_compiler_flag(C ${THIS_FLAG} ADDED_CMAKE_C_FLAGS)
881 endforeach()
882 set(CMAKE_C_FLAGS "${ADDED_CMAKE_C_FLAGS} ${CMAKE_C_FLAGS}")
883
884 foreach(THIS_FLAG ${WIRESHARK_COMMON_FLAGS} ${WIRESHARK_CXX_ONLY_FLAGS})
885         test_compiler_flag(CXX ${THIS_FLAG} ADDED_CMAKE_CXX_FLAGS)
886 endforeach()
887 set(CMAKE_CXX_FLAGS "${ADDED_CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS}")
888
889 # Strips the source and build directory prefix from the __FILE__ macro to ensure
890 # reproducible builds. Supported since GCC 8, Clang support is pending.
891 if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang")
892         # If the build dir is within the source dir, CMake will use something
893         # like ../epan/dfilter/semcheck.c. Map these relative paths in addition
894         # to CMAKE_BINARY_DIR since compile_commands.json uses absolute paths.
895         file(RELATIVE_PATH _relative_source_dir "${CMAKE_BINARY_DIR}" "${CMAKE_SOURCE_DIR}")
896         string(REGEX REPLACE "/$" "" _relative_source_dir "${_relative_source_dir}")
897
898         check_c_compiler_flag(-fmacro-prefix-map=old=new C_fmacro_prefix_map_old_new_VALID)
899         check_cxx_compiler_flag(-fmacro-prefix-map=old=new CXX_fmacro_prefix_map_old_new_VALID)
900         foreach(_lang C CXX)
901                 if(${_lang}_fmacro_prefix_map_old_new_VALID)
902                         set(_flags CMAKE_${_lang}_FLAGS)
903                         set(${_flags} "${${_flags}} -fmacro-prefix-map=${CMAKE_SOURCE_DIR}/=")
904                         set(${_flags} "${${_flags}} -fmacro-prefix-map=${CMAKE_BINARY_DIR}/=")
905                         if(_relative_source_dir MATCHES "\\.\\.$")
906                                 set(${_flags} "${${_flags}} -fmacro-prefix-map=${_relative_source_dir}/=")
907                         endif()
908                 endif()
909         endforeach()
910 endif()
911
912 include(CMakePushCheckState)
913
914 if(ENABLE_ASAN)
915         # Available since MSVC 2019 version 16.9
916         cmake_push_check_state()
917         set(ASAN_FLAG "-fsanitize=address")
918         set(CMAKE_REQUIRED_FLAGS ${ASAN_FLAG})
919         check_c_compiler_flag(${ASAN_FLAG} C__fsanitize_address_VALID)
920         check_cxx_compiler_flag(${ASAN_FLAG} CXX__fsanitize_address_VALID)
921         cmake_pop_check_state()
922         if(NOT C__fsanitize_address_VALID OR NOT CXX__fsanitize_address_VALID)
923                 message(FATAL_ERROR "ENABLE_ASAN was requested, but not supported!")
924         endif()
925         add_compile_options(${ASAN_FLAG})
926         if (MSVC)
927                 # Using ASAN makes some of our code require object files with
928                 # a 32-bit index to the section table instead of 16-bit.
929                 # This makes the .obj files slightly larger (~2%) and makes
930                 # it so that Microsoft linkers prior to MSVC 2005 can't read
931                 # the files, but those are too old anyway.
932                 add_compile_options(/bigobj)
933                 # The Microsoft LINK linker doesn't recognize or need the
934                 # ASAN flag, and will give a LNK4044 warning.
935         else()
936                 # Clang/gcc need the flag added to the linker
937                 # add_link_options since CMake 3.13 (our minimum)
938                 add_link_options(${ASAN_FLAG})
939         endif()
940         # Disable ASAN for build-time tools, e.g. lemon
941         # (MSVC doesn't support this flag)
942         check_c_compiler_flag(-fno-sanitize=all C__fno_sanitize_all_VALID)
943         if(C__fno_sanitize_all_VALID)
944                 set(NO_SANITIZE_CFLAGS "-fno-sanitize=all")
945                 set(NO_SANITIZE_LDFLAGS "-fno-sanitize=all")
946         endif()
947 endif()
948
949 if(ENABLE_TSAN)
950         # Available since Clang >= 3.2 and GCC >= 4.8
951         cmake_push_check_state()
952         set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=thread")
953         check_c_compiler_flag(-fsanitize=thread C__fsanitize_thread_VALID)
954         check_cxx_compiler_flag(-fsanitize=thread CXX__fsanitize_thread_VALID)
955         cmake_pop_check_state()
956         if(NOT C__fsanitize_thread_VALID OR NOT CXX__fsanitize_thread_VALID)
957                 message(FATAL_ERROR "ENABLE_TSAN was requested, but not supported!")
958         endif()
959         set(CMAKE_C_FLAGS "-fsanitize=thread ${CMAKE_C_FLAGS}")
960         set(CMAKE_CXX_FLAGS "-fsanitize=thread ${CMAKE_CXX_FLAGS}")
961         set(WS_LINK_FLAGS "-fsanitize=thread ${WS_LINK_FLAGS}")
962 endif()
963
964 if(ENABLE_UBSAN)
965         # Available since Clang >= 3.3 and GCC >= 4.9
966         cmake_push_check_state()
967         set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=undefined")
968         check_c_compiler_flag(-fsanitize=undefined C__fsanitize_undefined_VALID)
969         check_cxx_compiler_flag(-fsanitize=undefined CXX__fsanitize_undefined_VALID)
970         cmake_pop_check_state()
971         if(NOT C__fsanitize_undefined_VALID OR NOT CXX__fsanitize_undefined_VALID)
972                 message(FATAL_ERROR "ENABLE_UBSAN was requested, but not supported!")
973         endif()
974         set(CMAKE_C_FLAGS "-fsanitize=undefined ${CMAKE_C_FLAGS}")
975         set(CMAKE_CXX_FLAGS "-fsanitize=undefined ${CMAKE_CXX_FLAGS}")
976 endif()
977
978 if(ENABLE_FUZZER)
979         # Available since Clang >= 6
980         # Will enable coverage flags which can be used by the fuzzshark target.
981         cmake_push_check_state()
982         set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=fuzzer-no-link")
983         check_c_compiler_flag(-fsanitize=fuzzer C__fsanitize_fuzzer_no_link_VALID)
984         check_cxx_compiler_flag(-fsanitize=fuzzer CXX__fsanitize_fuzzer_no_link_VALID)
985         cmake_pop_check_state()
986         if(NOT C__fsanitize_fuzzer_no_link_VALID OR NOT CXX__fsanitize_fuzzer_no_link_VALID)
987                 message(FATAL_ERROR "ENABLE_FUZZER was requested, but not supported!")
988         endif()
989         set(CMAKE_C_FLAGS "-fsanitize=fuzzer-no-link ${CMAKE_C_FLAGS}")
990         set(CMAKE_CXX_FLAGS "-fsanitize=fuzzer-no-link ${CMAKE_CXX_FLAGS}")
991 endif()
992
993 if(MSVC)
994         if(ENABLE_VLD)
995                 include(FindVLD)
996                 if(NOT VLD_FOUND)
997                         message(FATAL_ERROR "ENABLE_VLD was requested, but not found!")
998                 endif()
999                 message(STATUS "Enabling Visual Leak Detector in Debug configuration")
1000                 set(WS_MSVC_DEBUG_LINK_FLAGS ${VLD_LINK_FLAGS})
1001         endif()
1002 endif()
1003
1004 set(WERROR_COMMON_FLAGS "")
1005 if(ENABLE_WERROR)
1006         if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
1007                 set(WERROR_COMMON_FLAGS "/WX")
1008         else()
1009                 #
1010                 # If a warning has been enabled by -Wall or -W,
1011                 # and have specified -Werror, there appears to be
1012                 # no way, in Apple's llvm-gcc, to prevent that
1013                 # particular warning from giving an error - not
1014                 # with a pragma, not with -Wno-{warning}, and not
1015                 # with -Wno-error={warning}.
1016                 #
1017                 # Therefore, with that compiler, we just disable
1018                 # -Werror.
1019                 #
1020                 if ((NOT APPLE) OR CMAKE_C_COMPILER_ID MATCHES "Clang")
1021                         check_c_compiler_flag(-Werror WERROR)
1022                         if (WERROR)
1023                                 set(WERROR_COMMON_FLAGS "-Werror")
1024                         endif()
1025                 endif()
1026         endif()
1027 endif()
1028
1029 #
1030 # Try to have the compiler default to hiding symbols, so that only
1031 # symbols explicitly exported with WS_DLL_PUBLIC will be visible
1032 # outside (shared) libraries; that way, more UN*X builds will catch
1033 # failures to export symbols, rather than having that fail only on
1034 # Windows.
1035 #
1036 # We don't need that with MSVC, as that's the default.
1037 #
1038 if( NOT CMAKE_C_COMPILER_ID MATCHES "MSVC")
1039         #
1040         # Try the GCC-and-compatible -fvisibility-hidden first.
1041         #
1042         check_c_compiler_flag(-fvisibility=hidden FVHIDDEN)
1043         if(FVHIDDEN)
1044                 set(CMAKE_C_FLAGS "-fvisibility=hidden ${CMAKE_C_FLAGS}")
1045         else()
1046                 #
1047                 # OK, try the Sun^WOracle C -xldscope=hidden
1048                 #
1049                 check_c_compiler_flag(-xldscope=hidden XLDSCOPEHIDDEN)
1050                 if(XLDSCOPEHIDDEN)
1051                         set(CMAKE_C_FLAGS "-xldscope=hidden ${CMAKE_C_FLAGS}")
1052                 else()
1053                         #
1054                         # Anything else?
1055                         # If there is anything else, we might want to
1056                         # make a list of options to try, and try them
1057                         # in a loop.
1058                         #
1059                         message(WARNING "Hiding shared library symbols is not supported by the compiler."
1060                                 " All shared library symbols will be exported.")
1061                 endif()
1062         endif()
1063 endif()
1064
1065 include(CheckCLinkerFlag)
1066
1067 if(NOT CMAKE_C_COMPILER_ID MATCHES "MSVC" AND NOT OSS_FUZZ)
1068         #
1069         # The -pie linker option produces a position-independent executable.
1070         # Some Linux distributions have this enabled by default in the compiler,
1071         # so setting it here will be superfluous though.
1072         #
1073         # Note that linking with static libraries that are not position
1074         # independent may fail, the user can set CMAKE_EXE_LINKER_FLAGS=-no-pie
1075         # as a workaround.
1076         #
1077         if(CMAKE_VERSION VERSION_LESS "3.14")
1078                 check_c_linker_flag(-pie LINK_pie_VALID)
1079                 if(LINK_pie_VALID)
1080                         set(CMAKE_EXE_LINKER_FLAGS "-pie ${CMAKE_EXE_LINKER_FLAGS}")
1081                 endif()
1082         else()
1083                 include(CheckPIESupported)
1084                 check_pie_supported()
1085         endif()
1086 endif()
1087
1088 foreach(THIS_FLAG ${WIRESHARK_LD_FLAGS})
1089         string(MAKE_C_IDENTIFIER "LINK${THIS_FLAG}_VALID" _flag_var)
1090         check_c_linker_flag(${THIS_FLAG} ${_flag_var})
1091         if (${_flag_var})
1092                 set(WS_LINK_FLAGS "${WS_LINK_FLAGS} ${THIS_FLAG}")
1093         endif()
1094 endforeach()
1095 message(STATUS "Linker flags: ${WS_LINK_FLAGS}")
1096
1097 if(APPLE AND EXISTS /usr/local/opt/gettext)
1098         # GLib on macOS requires libintl. Homebrew installs gettext (and
1099         # libintl) in /usr/local/opt/gettext
1100         include_directories(SYSTEM /usr/local/opt/gettext/include)
1101         link_directories(/usr/local/opt/gettext/lib)
1102 endif()
1103
1104 # Resets cache variables if the <PackageName>_LIBRARY has become invalid.
1105 # Call it before a find_package(<PackageName> ...) invocation that uses
1106 # find_library(<PackageName>_LIBRARY ...).
1107 #
1108 # Usage: reset_find_package(<PackageName> [<extra variables to clear>])
1109 function(reset_find_package _package_name)
1110         set(variables
1111                 # find_library / find_package
1112                 ${_package_name}_LIBRARY
1113                 ${_package_name}_INCLUDE_DIR
1114                 # mark_as_advanced
1115                 ${_package_name}_LIBRARIES
1116                 ${_package_name}_INCLUDE_DIRS
1117                 # Others
1118                 ${_package_name}_DLL_DIR
1119                 ${_package_name}_DLLS
1120                 ${_package_name}_DLL
1121                 ${_package_name}_PDB
1122                 ${ARGN}
1123         )
1124         if(NOT ${_package_name}_LIBRARY OR EXISTS ${${_package_name}_LIBRARY})
1125                 # Cache variable is already missing or cache entry is valid.
1126                 return()
1127         endif()
1128         message(STATUS "Package ${_package_name} has changed, clearing cache.")
1129         foreach(_var IN LISTS variables)
1130                 unset(${_var} CACHE)
1131         endforeach()
1132 endfunction()
1133
1134 # ws_find_package(<PackageName>
1135 #             <CMakeOptions.txt boolean variable>
1136 #             <cmakeconfig.h.in macro definition>
1137 #             [remaining find_package() arguments])
1138 macro(ws_find_package _package_name _enable_package _package_cmakedefine)
1139         if(${_enable_package})
1140                 # Clear outdated cache variables if not already.
1141                 reset_find_package(${_package_name})
1142                 find_package(${_package_name} ${ARGN})
1143                 if(${_package_name}_FOUND)
1144                         set(${_package_cmakedefine} 1)
1145                 endif()
1146         endif()
1147 endmacro()
1148
1149 # The minimum package list
1150 find_package(Git)
1151 reset_find_package(GLIB2 GLIB2_MAIN_INCLUDE_DIR GLIB2_INTERNAL_INCLUDE_DIR)
1152 find_package(GLIB2 "2.54.0" REQUIRED)
1153 include_directories(SYSTEM ${GLIB2_INCLUDE_DIRS})
1154 reset_find_package(GMODULE2)
1155 find_package(GMODULE2)
1156 reset_find_package(GTHREAD2)
1157 find_package(GTHREAD2 REQUIRED)
1158 reset_find_package(GCRYPT GCRYPT_ERROR_LIBRARY)
1159 find_package(GCRYPT "1.8.0" REQUIRED)
1160 # C Asynchronous resolver
1161 reset_find_package(CARES)
1162 find_package(CARES "1.13.0" REQUIRED)
1163 find_package(LEX REQUIRED)
1164 find_package(Perl)
1165 find_package(PCRE2 REQUIRED)
1166
1167 if (NOT WIN32)
1168         find_package(Gettext)
1169         find_package(M REQUIRED)
1170 endif()
1171
1172 if(BUILD_sshdump OR BUILD_ciscodump OR BUILD_wifidump)
1173         set(ENABLE_LIBSSH ON)
1174 else()
1175         set(ENABLE_LIBSSH OFF)
1176 endif()
1177 ws_find_package(LIBSSH ENABLE_LIBSSH HAVE_LIBSSH "0.6")
1178
1179 ws_find_package(PCAP ENABLE_PCAP HAVE_LIBPCAP)
1180 ws_find_package(AIRPCAP ENABLE_AIRPCAP HAVE_AIRPCAP)
1181 ws_find_package(Systemd BUILD_sdjournal HAVE_SYSTEMD)
1182
1183 # Build one of the Qt GUIs?
1184 if(BUILD_wireshark OR BUILD_logray)
1185         if(USE_qt6)
1186                 set(qtver "6")
1187                 if(DEFINED ENV{WIRESHARK_QT6_PREFIX_PATH})
1188                         list(APPEND CMAKE_PREFIX_PATH $ENV{WIRESHARK_QT6_PREFIX_PATH})
1189                 endif()
1190         else()
1191                 set(qtver "5")
1192                 if(DEFINED ENV{WIRESHARK_QT5_PREFIX_PATH})
1193                         list(APPEND CMAKE_PREFIX_PATH $ENV{WIRESHARK_QT5_PREFIX_PATH})
1194                 # XXX We used to recommend setting QT5_BASE_DIR. Remove after the 4.0 branch is created.
1195                 elseif(WIN32 AND NOT USE_MSYSTEM AND DEFINED ENV{QT5_BASE_DIR})
1196                         message(WARNING "Support for QT5_BASE_DIR will be removed in a future release.")
1197                         set(QT5_BASE_PATH "$ENV{QT5_BASE_DIR}")
1198                         set(CMAKE_PREFIX_PATH "${QT5_BASE_PATH}")
1199                 endif()
1200         endif()
1201         if(APPLE AND EXISTS /usr/local/opt/qt5)
1202                 # Homebrew installs Qt5 (up to at least 5.11.0) in
1203                 # /usr/local/qt5. Ensure that it can be found by CMake
1204                 # since it is not in the default /usr/local prefix.
1205                 # Add it to PATHS so that it doesn't override the
1206                 # CMAKE_PREFIX_PATH environment variable.
1207                 # QT_FIND_PACKAGE_OPTIONS should be passed to find_package,
1208                 # e.g. find_package(Qt5Core ${QT_FIND_PACKAGE_OPTIONS})
1209                 list(APPEND QT_FIND_PACKAGE_OPTIONS PATHS /usr/local/opt/qt5)
1210         endif()
1211         set(QT_PACKAGELIST
1212                 Qt${qtver}Core
1213                 Qt${qtver}Gui
1214                 Qt${qtver}LinguistTools
1215                 Qt${qtver}PrintSupport
1216                 Qt${qtver}Widgets
1217                 Qt${qtver}Concurrent
1218         )
1219         set(QT_OPTIONAL_PACKAGELIST
1220                 Qt${qtver}Multimedia
1221         )
1222         if(USE_qt6)
1223                 set(CMAKE_CXX_STANDARD 17)
1224                 # Setting CMAKE_CXX_STANDARD is not sufficient with MSVC, see
1225                 #   https://gitlab.kitware.com/cmake/cmake/-/issues/18837
1226                 # The below test can be found in Qt6, lib/cmake/Qt6/QtFeature.cmake
1227                 if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND MSVC_VERSION GREATER_EQUAL 1913)
1228                         add_definitions("-Zc:__cplusplus")
1229                 endif()
1230                 list(APPEND QT_PACKAGELIST Qt6Core5Compat)
1231         else()
1232                 if(WIN32)
1233                         list(APPEND QT_PACKAGELIST Qt5WinExtras)
1234                 endif()
1235         endif()
1236         foreach(_qt_package IN LISTS QT_PACKAGELIST)
1237                 find_package(${_qt_package} REQUIRED ${QT_FIND_PACKAGE_OPTIONS})
1238                 list(APPEND QT_LIBRARIES ${${_qt_package}_LIBRARIES})
1239                 list(APPEND QT_INCLUDE_DIRS ${${_qt_package}_INCLUDE_DIRS})
1240                 list(APPEND QT_COMPILE_DEFINITIONS ${${_qt_package}_COMPILE_DEFINITIONS})
1241         endforeach()
1242         foreach(_qt_package IN LISTS QT_OPTIONAL_PACKAGELIST)
1243                 find_package(${_qt_package} ${QT_FIND_PACKAGE_OPTIONS})
1244                 list(APPEND QT_LIBRARIES ${${_qt_package}_LIBRARIES})
1245                 list(APPEND QT_INCLUDE_DIRS ${${_qt_package}_INCLUDE_DIRS})
1246                 list(APPEND QT_COMPILE_DEFINITIONS ${${_qt_package}_COMPILE_DEFINITIONS})
1247         endforeach()
1248         if(APPLE AND "/usr/local/opt/qt5/lib/QtCore.framework" IN_LIST Qt5Core_INCLUDE_DIRS)
1249                 # When qt@6 and qt@5 are both installed via Homebrew,
1250                 # /usr/local/include/QtCore/qvariant.h points to Qt 6 headers.
1251                 # Normally the Headers from `-iframework /usr/local/opt/qt5/lib`
1252                 # should be used, but `-isystem /usr/local/include` (via
1253                 # Libgcrypt and others) seems to prioritized, resulting in use
1254                 # of the Qt6 headers. Resolve this by explicit including Qt5.
1255                 list(APPEND QT_INCLUDE_DIRS /usr/local/opt/qt5/include)
1256         endif()
1257         set(QT_FOUND ON)
1258         if(APPLE)
1259                 ws_find_package(Sparkle ENABLE_SPARKLE HAVE_SOFTWARE_UPDATE 2)
1260         endif()
1261         if(Qt${qtver}Multimedia_FOUND)
1262                 set(QT_MULTIMEDIA_LIB 1)
1263         endif()
1264 endif()
1265
1266 # MaxMind DB address resolution
1267 reset_find_package(MAXMINDDB)
1268 ws_find_package(MaxMindDB BUILD_mmdbresolve HAVE_MAXMINDDB)
1269
1270 # SMI SNMP
1271 reset_find_package(SMI SMI_SHARE_DIR)
1272 ws_find_package(SMI ENABLE_SMI HAVE_LIBSMI)
1273
1274 # Support for TLS decryption using RSA private keys.
1275 ws_find_package(GNUTLS ENABLE_GNUTLS HAVE_LIBGNUTLS "3.5.8")
1276
1277 # Kerberos
1278 ws_find_package(KERBEROS ENABLE_KERBEROS HAVE_KERBEROS)
1279
1280 # Zlib compression
1281 ws_find_package(ZLIB ENABLE_ZLIB HAVE_ZLIB)
1282
1283 # Minizip compression
1284 ws_find_package(Minizip ENABLE_MINIZIP HAVE_MINIZIP)
1285
1286 # Brotli compression
1287 ws_find_package(BROTLI ENABLE_BROTLI HAVE_BROTLI)
1288
1289 # LZ4 compression
1290 ws_find_package(LZ4 ENABLE_LZ4 HAVE_LZ4)
1291
1292 # Snappy compression
1293 ws_find_package(SNAPPY ENABLE_SNAPPY HAVE_SNAPPY)
1294
1295 # zstd compression
1296 ws_find_package(ZSTD ENABLE_ZSTD HAVE_ZSTD "1.0.0")
1297
1298 # Enhanced HTTP/2 dissection
1299 ws_find_package(NGHTTP2 ENABLE_NGHTTP2 HAVE_NGHTTP2 "1.11.0")
1300
1301 # Embedded Lua interpreter
1302 ws_find_package(LUA ENABLE_LUA HAVE_LUA "5.1")
1303
1304 ws_find_package(NL ENABLE_NETLINK HAVE_LIBNL)
1305
1306 ws_find_package(SBC ENABLE_SBC HAVE_SBC)
1307
1308 # SpanDSP codec
1309 ws_find_package(SPANDSP ENABLE_SPANDSP HAVE_SPANDSP)
1310
1311 ws_find_package(BCG729 ENABLE_BCG729 HAVE_BCG729)
1312
1313 ws_find_package(AMRNB ENABLE_AMRNB HAVE_AMRNB)
1314
1315 ws_find_package(ILBC ENABLE_ILBC HAVE_ILBC)
1316
1317 ws_find_package(OPUS ENABLE_OPUS HAVE_OPUS)
1318
1319 if (BUILD_logray)
1320         # libsinsp+libscap, required for falco-bridge
1321         ws_find_package(Sinsp ENABLE_SINSP HAVE_SINSP)
1322 endif()
1323
1324 # CMake 3.9 and below used 'LIBXML2_LIBRARIES' as the name of the cache entry
1325 # storing the find_library result. Transfer it to the new cache variable such
1326 # that reset_find_package can detect and clear outdated cache variables.
1327 if(DEFINED LIBXML2_LIBRARIES AND NOT DEFINED LIBXML2_LIBRARY)
1328         set(LIBXML2_LIBRARY ${LIBXML2_LIBRARIES} CACHE FILEPATH "")
1329 endif()
1330 # Call reset_find_package explicitly since variables are in upper case.
1331 reset_find_package(LIBXML2)
1332 ws_find_package(LibXml2 ENABLE_LIBXML2 HAVE_LIBXML2)
1333 if(NOT LIBXML2_FOUND)
1334         # CMake 3.9 and below used LIBXML2_LIBRARIES as the name of
1335         # the cache entry storing the find_library result.
1336         # Current CMake (3.13) and below sets LIBXML2_LIBRARIES and LIBXML2_INCLUDE_DIRS
1337         # to a non-empty value, be sure to clear it when not found.
1338         set(LIBXML2_LIBRARIES "")
1339         set(LIBXML2_INCLUDE_DIRS "")
1340 endif()
1341
1342 # Capabilities to run dumpcap as non-root user.
1343 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
1344         ws_find_package(CAP ENABLE_CAP HAVE_LIBCAP)
1345         find_package(SETCAP)
1346 endif()
1347
1348 # Windows version updates
1349 ws_find_package(WinSparkle ENABLE_WINSPARKLE HAVE_SOFTWARE_UPDATE)
1350
1351 find_package( Asciidoctor 1.5 )
1352 find_package( XSLTPROC )
1353
1354 find_package(DOXYGEN)
1355
1356 # The SpeexDSP resampler is required iff building wireshark or sharkd.
1357 if(BUILD_wireshark OR BUILD_logray OR BUILD_sharkd)
1358         find_package(SpeexDSP REQUIRED)
1359 endif()
1360
1361 # Generate the distribution tarball.
1362 add_custom_target(dist
1363         COMMAND ${CMAKE_BINARY_DIR}/packaging/source/git-export-release.sh -d "${CMAKE_BINARY_DIR}"
1364         WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
1365 )
1366
1367 if(GNUTLS_FOUND)
1368         # Calculating public keys from PKCS #11 private keys requires GnuTLS
1369         # 3.4.0 or greater.
1370         #
1371         # Check that the support is present in case GnuTLS was compiled
1372         # --without-p11-kit as macos-setup.sh did until December 2020.
1373         cmake_push_check_state()
1374         if(WIN32 AND NOT MINGW)
1375                 set(CMAKE_REQUIRED_DEFINITIONS -Dssize_t=int)
1376         endif()
1377         set(CMAKE_REQUIRED_INCLUDES ${GNUTLS_INCLUDE_DIRS})
1378         set(CMAKE_REQUIRED_LIBRARIES ${GNUTLS_LIBRARIES})
1379         check_symbol_exists(gnutls_pkcs11_obj_list_import_url4 gnutls/pkcs11.h HAVE_GNUTLS_PKCS11)
1380         cmake_pop_check_state()
1381 endif()
1382
1383 if (QT_FOUND)
1384         if (Qt${qtver}Widgets_VERSION VERSION_LESS 5.10)
1385                 message(FATAL_ERROR "Qt 5.12 or later is required.")
1386         endif()
1387         if (Qt${qtver}Widgets_VERSION VERSION_LESS 5.12)
1388                 message(WARNING "Wireshark can be build with this version of Qt, though 5.12 or higher is recommended.")
1389         endif()
1390         if(NOT DEFINED MOC_OPTIONS)
1391                 # Squelch moc verbose "nothing to do" output
1392                 set(MOC_OPTIONS -nn)
1393         endif()
1394
1395         # CMake uses qmake to find Qt4. It relies on Qt's CMake modules
1396         # to find Qt5. This means that we can't assume that the qmake
1397         # in our PATH is the correct one. We can fetch qmake's location
1398         # from Qt5::qmake, which is defined in Qt5CoreConfigExtras.cmake.
1399         get_target_property(QT_QMAKE_EXECUTABLE Qt${qtver}::qmake IMPORTED_LOCATION)
1400         get_filename_component(_qt_bin_path "${QT_QMAKE_EXECUTABLE}" DIRECTORY)
1401         set(QT_BIN_PATH "${_qt_bin_path}" CACHE INTERNAL
1402                 "Path to qmake, macdeployqt, windeployqt, and other Qt utilities."
1403         )
1404         # Use qmake to find windeployqt and macdeployqt. Ideally one of
1405         # the modules in ${QTDIR}/lib/cmake would do this for us.
1406         if(WIN32)
1407                 if (USE_qt6 AND USE_MSYSTEM)
1408                         set(_windeployqt_name "windeployqt-qt6")
1409                 else()
1410                         set(_windeployqt_name "windeployqt")
1411                 endif()
1412                 find_program(QT_WINDEPLOYQT_EXECUTABLE ${_windeployqt_name}
1413                         HINTS "${QT_BIN_PATH}"
1414                         DOC "Path to the windeployqt utility."
1415                 )
1416                 # As of Qt 6.5.0, the official Qt "MSVC 2019 ARM64 (TP)" libraries don't ship
1417                 # with native Arm64 executables. Instead, you get x64 executables installed in
1418                 # msvc2019_x64. Look for the path to "qmake.bat", which has to be passed to
1419                 # windeployqt so that it can install the proper DLLs.
1420                 # https://bugreports.qt.io/browse/QTBUG-100070
1421                 set(QT_WINDEPLOYQT_EXTRA_ARGS)
1422                 find_program(_qt_qmake_bat qmake.bat
1423                         HINTS ENV CMAKE_PREFIX_PATH
1424                         PATH_SUFFIXES bin
1425                         DOC "Path to qmake.bat."
1426                 )
1427                 if(_qt_qmake_bat)
1428                         set (QT_WINDEPLOYQT_EXTRA_ARGS "--qmake \"${_qt_qmake_bat}\"")
1429                 endif()
1430         elseif(APPLE)
1431                 find_program(QT_MACDEPLOYQT_EXECUTABLE macdeployqt
1432                         HINTS "${QT_BIN_PATH}"
1433                         DOC "Path to the macdeployqt utility."
1434                 )
1435                 find_program(DMGBUILD_EXECUTABLE dmgbuild
1436                         DOC "Path to the dmgbuild utility"
1437                 )
1438                 # https://doc.qt.io/qt-5/supported-platforms.html
1439                 # https://doc.qt.io/qt-5.11/supported-platforms-and-configurations.html
1440                 # https://doc.qt.io/qt-5.15/supported-platforms.html
1441                 # https://doc-snapshots.qt.io/qt6-dev/supported-platforms.html
1442                 if(Qt${qtver}Widgets_VERSION VERSION_GREATER_EQUAL "6.0.0")
1443                         set(MIN_MACOS_VERSION 10.14)
1444                 elseif(Qt5Widgets_VERSION VERSION_GREATER_EQUAL "5.14.0")
1445                         set(MIN_MACOS_VERSION 10.13)
1446                 elseif(Qt5Widgets_VERSION VERSION_GREATER_EQUAL "5.12.0")
1447                         set(MIN_MACOS_VERSION 10.12)
1448                 elseif(Qt5Widgets_VERSION VERSION_GREATER_EQUAL "5.10.0")
1449                         set(MIN_MACOS_VERSION 10.11)
1450                 endif()
1451                 if(CMAKE_OSX_DEPLOYMENT_TARGET AND CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS MIN_MACOS_VERSION)
1452                         message(FATAL_ERROR "Qt version ${Qt${qtver}Widgets_VERSION} requires CMAKE_OSX_DEPLOYMENT_TARGET (${CMAKE_OSX_DEPLOYMENT_TARGET}) >= ${MIN_MACOS_VERSION}")
1453                 endif()
1454         endif()
1455
1456         # Qt requires MSVC /permissive- option since 6.3 release
1457         if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND Qt${qtver}Widgets_VERSION VERSION_GREATER_EQUAL "6.3.0")
1458                 add_compile_options("/permissive-")
1459         endif()
1460 endif()
1461
1462 if(ENABLE_CHECKHF_CONFLICT)
1463         set(ENABLE_CHECK_FILTER 1)
1464 endif()
1465
1466 #
1467 # Platform-specific additional libraries.
1468 #
1469 if(WIN32)
1470         set(WIN_COMCTL32_LIBRARY comctl32.lib)
1471         set(WIN_IPHLPAPI_LIBRARY iphlpapi.lib)
1472         set(WIN_PSAPI_LIBRARY    psapi.lib)
1473         set(WIN_VERSION_LIBRARY  version.lib)
1474         set(WIN_WS2_32_LIBRARY   ws2_32.lib)
1475 endif()
1476
1477 if(APPLE)
1478         #
1479         # We assume that APPLE means macOS so that we have the macOS
1480         # frameworks.
1481         #
1482         set(HAVE_MACOS_FRAMEWORKS 1)
1483         FIND_LIBRARY (APPLE_APPLICATION_SERVICES_LIBRARY ApplicationServices)
1484         FIND_LIBRARY (APPLE_APPKIT_LIBRARY AppKit)
1485         FIND_LIBRARY (APPLE_CORE_FOUNDATION_LIBRARY CoreFoundation)
1486         FIND_LIBRARY (APPLE_SYSTEM_CONFIGURATION_LIBRARY SystemConfiguration)
1487
1488         message(STATUS "Building for Mac OS X/OS X/macOS ${MIN_MACOS_VERSION} using SDK ${CMAKE_OSX_SYSROOT}")
1489 endif()
1490
1491 include(ConfigureChecks.cmake)
1492
1493 # Global properties
1494 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
1495
1496 if(ENABLE_CCACHE)
1497         if(NOT (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang"))
1498                 # https://ccache.dev/platform-compiler-language-support.html
1499                 message(WARNING "Ccache is enabled, but your compiler is ${CMAKE_C_COMPILER_ID}."
1500                 " We wish you the best of luck.")
1501         endif()
1502         find_program(CCACHE_EXECUTABLE ccache)
1503         if(CCACHE_EXECUTABLE)
1504                 set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_EXECUTABLE}")
1505                 set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_EXECUTABLE}")
1506                 set(CMAKE_C_LINKER_LAUNCHER "${CCACHE_EXECUTABLE}")
1507                 set(CMAKE_CXX_LINKER_LAUNCHER "${CCACHE_EXECUTABLE}")
1508         endif()
1509 endif()
1510
1511 # The top level checkAPIs target, add before subdirectory calls so it's avaiable to all
1512 add_custom_target(checkAPI)
1513 set_target_properties(checkAPI
1514         PROPERTIES
1515                 FOLDER "Auxiliary"
1516                 EXCLUDE_FROM_ALL True
1517                 EXCLUDE_FROM_DEFAULT_BUILD True
1518 )
1519
1520 include( UseCheckAPI )
1521
1522 # Target platform locations
1523 # UN*X in general, including macOS if not building an app bundle:
1524 # $DESTDIR/lib/wireshark/extcap
1525 # Windows: $DESTDIR/extcap
1526 # macOS app bundle: Wireshark.app/Contents/Resources/share/wireshark/extcap
1527 # If you change the nesting level be sure to check also the INSTALL_RPATH
1528 # target property.
1529 if(WIN32 AND NOT USE_MSYSTEM)
1530         set(EXTCAP_INSTALL_LIBDIR "extcap" CACHE INTERNAL "The extcap dir")
1531 else()
1532         set(EXTCAP_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/extcap" CACHE INTERNAL "The extcap dir")
1533 endif()
1534 set(EXTCAP_INSTALL_FULL_LIBDIR "${CMAKE_INSTALL_PREFIX}/${EXTCAP_INSTALL_LIBDIR}")
1535
1536 if(APPLE)
1537         #
1538         # As https://developer.apple.com/library/archive/technotes/tn2206/_index.html
1539         # says,
1540         #
1541         # "Note that a location where code is expected to reside cannot generally
1542         # contain directories full of nested code, because those directories tend
1543         # to be interpreted as bundles. So this occasional practice is not
1544         # recommended and not officially supported. If you do do this, do not use
1545         # periods in the directory names. The code signing machinery interprets
1546         # directories with periods in their names as code bundles and will reject
1547         # them if they don't conform to the expected code bundle layout."
1548         #
1549         set(PLUGIN_PATH_ID "${PROJECT_MAJOR_VERSION}-${PROJECT_MINOR_VERSION}")
1550 else()
1551         set(PLUGIN_PATH_ID "${PROJECT_MAJOR_VERSION}.${PROJECT_MINOR_VERSION}")
1552 endif()
1553
1554 # Directory where plugins and Lua dissectors can be found.
1555 if(WIN32 AND NOT USE_MSYSTEM)
1556         set(PLUGIN_INSTALL_LIBDIR "plugins" CACHE INTERNAL "The plugin dir")
1557 else()
1558         set(PLUGIN_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/plugins" CACHE INTERNAL "The plugin dir")
1559 endif()
1560 set(PLUGIN_INSTALL_FULL_LIBDIR "${CMAKE_INSTALL_PREFIX}/${PLUGIN_INSTALL_LIBDIR}")
1561 set(PLUGIN_INSTALL_VERSION_LIBDIR "${PLUGIN_INSTALL_LIBDIR}/${PLUGIN_PATH_ID}")
1562 set(PLUGIN_VERSION_DIR "plugins/${PLUGIN_PATH_ID}")
1563
1564 add_subdirectory( capture )
1565 add_subdirectory( doc )
1566 add_subdirectory( docbook EXCLUDE_FROM_ALL )
1567 add_subdirectory( epan )
1568 add_subdirectory( extcap )
1569 add_subdirectory( randpkt_core )
1570 if(NOT LEMON_EXECUTABLE)
1571         add_subdirectory( tools/lemon )
1572 endif()
1573 if(PCAP_FOUND)
1574         add_subdirectory( tools/radiotap-gen )
1575 endif()
1576 add_subdirectory( ui )
1577 add_subdirectory( wiretap )
1578 add_subdirectory( writecap )
1579
1580 # Location of our data files. This should be set to a value that allows
1581 # running from the build directory on Windows, on macOS when building an
1582 # application bundle, and on UNIX in general if
1583 # WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set.
1584 if(ENABLE_APPLICATION_BUNDLE)
1585         if(CMAKE_CFG_INTDIR STREQUAL ".")
1586                 set(_datafile_dir "${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/Resources/share/wireshark")
1587         else()
1588                 # Xcode
1589                 set(_datafile_dir "${CMAKE_BINARY_DIR}/run/${CMAKE_CFG_INTDIR}/Wireshark.app/Contents/Resources/share/wireshark")
1590         endif()
1591 elseif(NOT CMAKE_CFG_INTDIR STREQUAL ".")
1592         # Visual Studio, Xcode, etc.
1593         set(_datafile_dir "${CMAKE_BINARY_DIR}/run/${CMAKE_CFG_INTDIR}")
1594 else()
1595         # Makefile, Ninja, etc.
1596         set(_datafile_dir "${CMAKE_BINARY_DIR}/run")
1597 endif()
1598
1599 set(DATAFILE_DIR ${_datafile_dir} CACHE INTERNAL "Build time data file location.")
1600
1601 if(ENABLE_APPLICATION_BUNDLE)
1602         if(CMAKE_CFG_INTDIR STREQUAL ".")
1603                 set(_log_datafile_dir "${CMAKE_BINARY_DIR}/run/Logray.app/Contents/Resources/share/logray")
1604         else()
1605                 # Xcode
1606                 set(_log_datafile_dir "${CMAKE_BINARY_DIR}/run/${CMAKE_CFG_INTDIR}/Logray.app/Contents/Resources/share/logray")
1607         endif()
1608         set(LOG_DATAFILE_DIR ${_log_datafile_dir} CACHE INTERNAL "Build time log analysis data file location.")
1609 # XXX We need to update wsutil/filesystem.c and packaging/nsis/*logray* to match.
1610 # elseif(NOT CMAKE_CFG_INTDIR STREQUAL ".")
1611 #       # Visual Studio, Xcode, etc.
1612 #       set(_log_datafile_dir "${CMAKE_BINARY_DIR}/run/${CMAKE_CFG_INTDIR}/share/logray")
1613 # else()
1614 #       # Makefile, Ninja, etc.
1615 #       set(_log_datafile_dir "${CMAKE_BINARY_DIR}/run/share/logray")
1616 endif()
1617
1618
1619 # wsutil must be added after DATAFILE_DIR is set such that filesystem.c can
1620 # learn about the directory location.
1621 add_subdirectory( wsutil )
1622
1623 if(BUILD_wireshark AND QT_FOUND)
1624         add_subdirectory( ui/qt )
1625 elseif(BUILD_wireshark AND USE_qt6)
1626         message(VERBOSE "To use Qt5 instead of Qt6 use CMake option USE_qt6=OFF.")
1627 endif()
1628
1629 if(BUILD_logray AND QT_FOUND)
1630         add_subdirectory( ui/logray )
1631 endif()
1632
1633 # Location of our plugins. PLUGIN_DIR should allow running
1634 # from the build directory similar to DATAFILE_DIR above.
1635 if(ENABLE_PLUGINS)
1636         # Target platform locations
1637         # UN*X in general, including macOS if not building an app bundle:
1638         # $DESTDIR/lib/wireshark/plugins/$VERSION
1639         # Windows: $DESTDIR/wireshark/plugins/$VERSION
1640         # macOS app bundle: Wireshark.app/Contents/PlugIns/wireshark
1641         set(HAVE_PLUGINS 1)
1642         add_custom_target(plugins)
1643         set_target_properties(plugins PROPERTIES FOLDER "Plugins")
1644         set(PLUGIN_SRC_DIRS
1645                 plugins/epan/ethercat
1646                 plugins/epan/gryphon
1647                 plugins/epan/irda
1648                 plugins/epan/mate
1649                 plugins/epan/opcua
1650                 plugins/epan/profinet
1651                 plugins/epan/stats_tree
1652                 plugins/epan/transum
1653                 plugins/epan/unistim
1654                 plugins/epan/wimax
1655                 plugins/epan/wimaxasncp
1656                 plugins/epan/wimaxmacphy
1657                 plugins/wiretap/usbdump
1658                 plugins/codecs/G711
1659                 plugins/codecs/l16_mono
1660                 ${CUSTOM_PLUGIN_SRC_DIR}
1661         )
1662         set(LOGRAY_PLUGIN_SRC_DIRS)
1663         if(SINSP_FOUND)
1664                 list(APPEND LOGRAY_PLUGIN_SRC_DIRS
1665                         plugins/epan/falco_bridge
1666                 )
1667         endif()
1668         if(SPANDSP_FOUND)
1669                 list(APPEND PLUGIN_SRC_DIRS
1670                         plugins/codecs/G722
1671                         plugins/codecs/G726
1672                 )
1673         endif()
1674         if(BCG729_FOUND)
1675                 list(APPEND PLUGIN_SRC_DIRS
1676                         plugins/codecs/G729
1677                 )
1678         endif()
1679         if(AMRNB_FOUND)
1680                 list(APPEND PLUGIN_SRC_DIRS
1681                         plugins/codecs/amrnb
1682                 )
1683         endif()
1684         if(ILBC_FOUND)
1685                 list(APPEND PLUGIN_SRC_DIRS
1686                         plugins/codecs/iLBC
1687                 )
1688         endif()
1689         if(OPUS_FOUND)
1690                 list(APPEND PLUGIN_SRC_DIRS
1691                         plugins/codecs/opus_dec
1692                 )
1693         endif()
1694         if(SBC_FOUND)
1695                 list(APPEND PLUGIN_SRC_DIRS
1696                         plugins/codecs/sbc
1697                 )
1698         endif()
1699
1700         # Build demo plugin, only if asked explicitly
1701         if(ENABLE_PLUGIN_IFDEMO)
1702                 list(APPEND PLUGIN_SRC_DIRS
1703                         plugins/epan/pluginifdemo
1704                 )
1705         endif()
1706
1707 else()
1708         set(PLUGIN_SRC_DIRS )
1709         set(LOGRAY_PLUGIN_SRC_DIRS )
1710 endif()
1711
1712 if(ENABLE_APPLICATION_BUNDLE)
1713         if(CMAKE_CFG_INTDIR STREQUAL ".")
1714                 set(_plugin_dir "${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/PlugIns/wireshark/${PLUGIN_PATH_ID}")
1715         else()
1716                 # Xcode
1717                 set(_plugin_dir "${CMAKE_BINARY_DIR}/run/$<CONFIG>/Wireshark.app/Contents/PlugIns/wireshark/${PLUGIN_PATH_ID}")
1718         endif()
1719         if(CMAKE_CFG_INTDIR STREQUAL ".")
1720                 set(_logray_plugin_dir "${CMAKE_BINARY_DIR}/run/Logray.app/Contents/PlugIns/logray/${PLUGIN_PATH_ID}")
1721         else()
1722                 # Xcode
1723                 set(_logray_plugin_dir "${CMAKE_BINARY_DIR}/run/$<CONFIG>/Logray.app/Contents/PlugIns/logray/${PLUGIN_PATH_ID}")
1724         endif()
1725 elseif(MSVC AND NOT CMAKE_CFG_INTDIR STREQUAL ".")
1726         set(_plugin_dir "${CMAKE_BINARY_DIR}/run/$<CONFIG>/${PLUGIN_VERSION_DIR}")
1727         set(_logray_plugin_dir ${_plugin_dir})
1728 else()
1729         set(_plugin_dir "${DATAFILE_DIR}/${PLUGIN_VERSION_DIR}")
1730         set(_logray_plugin_dir ${_plugin_dir})
1731 endif()
1732 set (PLUGIN_DIR ${_plugin_dir} CACHE INTERNAL "Build time plugin location.")
1733 set (LOGRAY_PLUGIN_DIR ${_logray_plugin_dir} CACHE INTERNAL "Build time Logray plugin location.")
1734
1735 foreach(_plugin_src_dir ${PLUGIN_SRC_DIRS} ${LOGRAY_PLUGIN_SRC_DIRS})
1736         add_subdirectory( ${_plugin_src_dir} )
1737 endforeach()
1738
1739 if(VCSVERSION_OVERRIDE)
1740         # Allow distributors to override detection of the Git tag and version.
1741         string(CONFIGURE "#define VCSVERSION \"@VCSVERSION_OVERRIDE@\"\n"
1742                 _version_h_contents ESCAPE_QUOTES)
1743         file(WRITE "${CMAKE_BINARY_DIR}/vcs_version.h" "${_version_h_contents}")
1744         message(STATUS "VCSVERSION_OVERRIDE: ${VCSVERSION_OVERRIDE}")
1745 else()
1746         add_custom_target(vcs_version
1747                 BYPRODUCTS vcs_version.h
1748                 COMMAND ${PYTHON_EXECUTABLE}
1749                         ${CMAKE_SOURCE_DIR}/tools/make-version.py
1750                         ${CMAKE_SOURCE_DIR}
1751         )
1752         set_target_properties(vcs_version PROPERTIES FOLDER "Auxiliary")
1753 endif()
1754
1755 set( configure_input "Built with CMake ${CMAKE_VERSION}" )
1756 configure_file(${CMAKE_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_BINARY_DIR}/config.h)
1757
1758 configure_file(${CMAKE_SOURCE_DIR}/ws_version.h.in ${CMAKE_BINARY_DIR}/ws_version.h)
1759
1760 set( prefix "${CMAKE_INSTALL_PREFIX}" )
1761 set( exec_prefix "\${prefix}" )
1762 set( libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}" )
1763 set( includedir  "\${prefix}/include" )
1764 set( plugindir "\${libdir}/wireshark/${PLUGIN_VERSION_DIR}" )
1765
1766 # Doxygen variables
1767 file(GLOB TOP_LEVEL_SOURCE_LIST *.c *.cpp *.h)
1768 string (REPLACE ";" " " DOXYGEN_TOP_LEVEL_SOURCES "${TOP_LEVEL_SOURCE_LIST}")
1769 set(DOXYGEN_INPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
1770 set(DOXYGEN_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
1771
1772 set(CFG_OUT_FILES
1773         doxygen.cfg
1774         packaging/macosx/osx-app.sh
1775         packaging/macosx/osx-dmg.sh
1776         packaging/macosx/wireshark-app.dmgbuild
1777         packaging/macosx/wireshark-dsym.dmgbuild
1778         packaging/macosx/WiresharkInfo.plist
1779         packaging/source/git-export-release.sh
1780         resources/dumpcap.rc
1781         resources/libwireshark.rc
1782         resources/libwiretap.rc
1783         resources/libwsutil.rc
1784         resources/wireshark.exe.manifest
1785         resources/wireshark.rc
1786         wireshark.pc
1787 )
1788
1789 if(BUILD_logray)
1790         list(APPEND CFG_OUT_FILES
1791                 packaging/macosx/LograyInfo.plist
1792                 packaging/macosx/logray-app.dmgbuild
1793                 packaging/macosx/logray-dsym.dmgbuild
1794                 resources/logray.exe.manifest
1795         )
1796 endif()
1797
1798 foreach( _cfg_file ${CFG_OUT_FILES} )
1799         configure_file( ${CMAKE_SOURCE_DIR}/${_cfg_file}.in ${CMAKE_BINARY_DIR}/${_cfg_file} @ONLY )
1800 endforeach()
1801
1802 include(FeatureSummary)
1803 set_package_properties(CAP PROPERTIES
1804         DESCRIPTION "The Libcap package implements the user-space interfaces to the POSIX 1003.1e capabilities available in Linux kernels"
1805         URL "https://sites.google.com/site/fullycapable/"
1806         PURPOSE "Allow packet captures without running as root"
1807 )
1808 set_package_properties(SBC PROPERTIES
1809         DESCRIPTION "Bluetooth low-complexity, subband codec (SBC) decoder"
1810         URL "https://git.kernel.org/pub/scm/bluetooth/sbc.git"
1811         PURPOSE "Support for playing SBC codec in RTP player"
1812 )
1813 set_package_properties(SPANDSP PROPERTIES
1814         DESCRIPTION "a library of many DSP functions for telephony"
1815         URL "https://www.soft-switch.org"
1816         PURPOSE "Support for G.722 and G.726 codecs in RTP player"
1817 )
1818 set_package_properties(BCG729 PROPERTIES
1819         DESCRIPTION "G.729 decoder"
1820         URL "https://www.linphone.org/technical-corner/bcg729"
1821         PURPOSE "Support for G.729 codec in RTP player"
1822 )
1823 set_package_properties(AMRNB PROPERTIES
1824         DESCRIPTION "AMRNB decoder"
1825         URL "https://sourceforge.net/p/opencore-amr"
1826         PURPOSE "Support for AMRNB codec in RTP player"
1827 )
1828 set_package_properties(ILBC PROPERTIES
1829         DESCRIPTION "iLBC decoder"
1830         URL "https://github.com/TimothyGu/libilbc"
1831         PURPOSE "Support for iLBC codec in RTP player"
1832 )
1833 set_package_properties(OPUS PROPERTIES
1834         DESCRIPTION "opus decoder"
1835         URL "https://opus-codec.org/"
1836         PURPOSE "Support for opus codec in RTP player"
1837 )
1838 set_package_properties(LIBXML2 PROPERTIES
1839         DESCRIPTION "XML parsing library"
1840         URL "http://xmlsoft.org/"
1841         PURPOSE "Read XML configuration files in EPL dissector"
1842 )
1843 set_package_properties(LIBSSH PROPERTIES
1844         DESCRIPTION "Library for implementing SSH clients"
1845         URL "https://www.libssh.org/"
1846         PURPOSE "extcap remote SSH interfaces (sshdump, ciscodump, wifidump)"
1847 )
1848 set_package_properties(LZ4 PROPERTIES
1849         DESCRIPTION "LZ4 is a fast lossless compression algorithm"
1850         URL "http://www.lz4.org"
1851         PURPOSE "LZ4 decompression in CQL and Kafka dissectors, read compressed capture files"
1852 )
1853 set_package_properties(SNAPPY PROPERTIES
1854         DESCRIPTION "A fast compressor/decompressor from Google"
1855         URL "https://google.github.io/snappy/"
1856         PURPOSE "Snappy decompression in CQL and Kafka dissectors"
1857 )
1858 set_package_properties(ZSTD PROPERTIES
1859         DESCRIPTION "A compressor/decompressor from Facebook providing better compression than Snappy at a cost of speed"
1860         URL "https://facebook.github.io/zstd/"
1861         PURPOSE "Zstd decompression in Kafka dissector, read compressed capture files"
1862 )
1863 set_package_properties(NGHTTP2 PROPERTIES
1864         DESCRIPTION "HTTP/2 C library and tools"
1865         URL "https://nghttp2.org"
1866         PURPOSE "Header decompression in HTTP2"
1867 )
1868 set_package_properties(CARES PROPERTIES
1869         DESCRIPTION "Library for asynchronous DNS requests"
1870         URL "https://c-ares.org/"
1871         PURPOSE "DNS name resolution for captures"
1872 )
1873 set_package_properties(Systemd PROPERTIES
1874         URL "https://freedesktop.org/wiki/Software/systemd/"
1875         DESCRIPTION "System and Service Manager (libraries)"
1876         PURPOSE "Support for systemd journal extcap interface (sdjournal)"
1877 )
1878 set_package_properties(NL PROPERTIES
1879         URL "https://www.infradead.org/~tgr/libnl/"
1880         DESCRIPTION "Libraries for using the Netlink protocol on Linux"
1881         PURPOSE "Support for managing wireless 802.11 interfaces"
1882 )
1883 set_package_properties(MaxMindDB PROPERTIES
1884         URL "https://github.com/maxmind/libmaxminddb"
1885         DESCRIPTION "C library for the MaxMind DB file format"
1886         PURPOSE "Support for GeoIP lookup"
1887 )
1888 set_package_properties(SpeexDSP PROPERTIES
1889         URL "https://www.speex.org/"
1890         DESCRIPTION "SpeexDSP is a patent-free, Open Source/Free Software DSP library"
1891         PURPOSE "RTP audio resampling"
1892 )
1893 set_package_properties(Minizip PROPERTIES
1894         URL "https://github.com/madler/zlib"
1895         DESCRIPTION "Mini zip and unzip based on zlib"
1896         PURPOSE "Support for profiles import/export"
1897 )
1898 set_package_properties(SMI PROPERTIES
1899         URL "https://www.ibr.cs.tu-bs.de/projects/libsmi/"
1900         DESCRIPTION "Library to access SMI management information"
1901         PURPOSE "Support MIB and PIB parsing and OID resolution"
1902 )
1903 set_package_properties(PCRE2 PROPERTIES
1904         URL "https://www.pcre.org"
1905         DESCRIPTION "Regular expression pattern matching using the same syntax and semantics as Perl 5"
1906         PURPOSE "Support for regular expressions"
1907 )
1908 set_package_properties(Sinsp PROPERTIES
1909         DESCRIPTION "libsinsp and libscap"
1910         URL "https://github.com/falcosecurity/libs/"
1911         PURPOSE "Support for Falco plugins"
1912 )
1913
1914 string(TOUPPER "${CMAKE_BUILD_TYPE}" _build_type)
1915 message(STATUS "C-Flags: ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${_build_type}}")
1916 message(STATUS "CXX-Flags: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${_build_type}}")
1917 if(WERROR_COMMON_FLAGS)
1918         message(STATUS "Warnings as errors enabled: ${WERROR_COMMON_FLAGS}")
1919 else()
1920         message(STATUS "Warnings as errors disabled")
1921 endif()
1922
1923 feature_summary(WHAT ALL)
1924
1925 # Should this be part of libui?
1926 if(WIN32)
1927         set(PLATFORM_UI_SRC
1928                 ui/win32/file_dlg_win32.cpp
1929         )
1930         set(PLATFORM_UI_RC_FILES
1931                 resources/file_dlg_win32.rc
1932         )
1933 elseif(APPLE)
1934         set(PLATFORM_UI_SRC
1935                 ui/macosx/cocoa_bridge.mm
1936         )
1937         if (SPARKLE_FOUND)
1938                 list(APPEND PLATFORM_UI_SRC ui/macosx/sparkle_bridge.m)
1939         endif()
1940 endif()
1941
1942 set(TSHARK_TAP_SRC
1943         ${CMAKE_SOURCE_DIR}/ui/cli/tap-credentials.c
1944         ${CMAKE_SOURCE_DIR}/ui/cli/tap-camelsrt.c
1945         ${CMAKE_SOURCE_DIR}/ui/cli/tap-diameter-avp.c
1946         ${CMAKE_SOURCE_DIR}/ui/cli/tap-expert.c
1947         ${CMAKE_SOURCE_DIR}/ui/cli/tap-exportobject.c
1948         ${CMAKE_SOURCE_DIR}/ui/cli/tap-endpoints.c
1949         ${CMAKE_SOURCE_DIR}/ui/cli/tap-flow.c
1950         ${CMAKE_SOURCE_DIR}/ui/cli/tap-follow.c
1951         ${CMAKE_SOURCE_DIR}/ui/cli/tap-funnel.c
1952         ${CMAKE_SOURCE_DIR}/ui/cli/tap-gsm_astat.c
1953         ${CMAKE_SOURCE_DIR}/ui/cli/tap-hosts.c
1954         ${CMAKE_SOURCE_DIR}/ui/cli/tap-httpstat.c
1955         ${CMAKE_SOURCE_DIR}/ui/cli/tap-icmpstat.c
1956         ${CMAKE_SOURCE_DIR}/ui/cli/tap-icmpv6stat.c
1957         ${CMAKE_SOURCE_DIR}/ui/cli/tap-iostat.c
1958         ${CMAKE_SOURCE_DIR}/ui/cli/tap-iousers.c
1959         ${CMAKE_SOURCE_DIR}/ui/cli/tap-macltestat.c
1960         ${CMAKE_SOURCE_DIR}/ui/cli/tap-protocolinfo.c
1961         ${CMAKE_SOURCE_DIR}/ui/cli/tap-protohierstat.c
1962         ${CMAKE_SOURCE_DIR}/ui/cli/tap-rlcltestat.c
1963         ${CMAKE_SOURCE_DIR}/ui/cli/tap-rpcprogs.c
1964         ${CMAKE_SOURCE_DIR}/ui/cli/tap-rtd.c
1965         ${CMAKE_SOURCE_DIR}/ui/cli/tap-rtp.c
1966         ${CMAKE_SOURCE_DIR}/ui/cli/tap-rtspstat.c
1967         ${CMAKE_SOURCE_DIR}/ui/cli/tap-sctpchunkstat.c
1968         ${CMAKE_SOURCE_DIR}/ui/cli/tap-simple_stattable.c
1969         ${CMAKE_SOURCE_DIR}/ui/cli/tap-sipstat.c
1970         ${CMAKE_SOURCE_DIR}/ui/cli/tap-smbsids.c
1971         ${CMAKE_SOURCE_DIR}/ui/cli/tap-srt.c
1972         ${CMAKE_SOURCE_DIR}/ui/cli/tap-stats_tree.c
1973         ${CMAKE_SOURCE_DIR}/ui/cli/tap-sv.c
1974         ${CMAKE_SOURCE_DIR}/ui/cli/tap-wspstat.c
1975         ${CUSTOM_TSHARK_TAP_SRC}
1976
1977 )
1978
1979 # Installed into ${DATAFILE_DIR}
1980 set(INSTALL_DIRS
1981         resources/share/wireshark/profiles
1982         resources/protocols/diameter
1983         resources/protocols/dtds
1984         resources/protocols/radius
1985         resources/protocols/tpncp
1986         resources/protocols/wimaxasncp
1987 )
1988
1989 # Installed into ${DATAFILE_DIR}
1990 set(INSTALL_FILES
1991         enterprises.tsv
1992         manuf
1993         resources/share/wireshark/cfilters
1994         resources/share/wireshark/colorfilters
1995         resources/share/wireshark/dfilter_macros
1996         resources/share/wireshark/dfilters
1997         resources/share/wireshark/smi_modules
1998         services
1999         wka
2000 )
2001 set(DOC_FILES
2002         resources/share/doc/wireshark/ipmap.html
2003         resources/share/doc/wireshark/pdml2html.xsl
2004         doc/README.xml-output
2005         docbook/ws.css
2006 )
2007
2008 if (BUILD_logray)
2009         set(LOG_INSTALL_FILES
2010                 docbook/ws.css
2011                 resources/share/logray/colorfilters
2012                 resources/share/logray/dfilter_buttons
2013         )
2014 endif()
2015
2016 if (ASCIIDOCTOR_FOUND)
2017         list(APPEND DOC_FILES
2018                 ${CMAKE_BINARY_DIR}/doc/androiddump.html
2019                 ${CMAKE_BINARY_DIR}/doc/udpdump.html
2020                 ${CMAKE_BINARY_DIR}/doc/capinfos.html
2021                 ${CMAKE_BINARY_DIR}/doc/captype.html
2022                 ${CMAKE_BINARY_DIR}/doc/ciscodump.html
2023                 ${CMAKE_BINARY_DIR}/doc/dumpcap.html
2024                 ${CMAKE_BINARY_DIR}/doc/editcap.html
2025                 ${CMAKE_BINARY_DIR}/doc/extcap.html
2026                 ${CMAKE_BINARY_DIR}/doc/mergecap.html
2027                 ${CMAKE_BINARY_DIR}/doc/randpkt.html
2028                 ${CMAKE_BINARY_DIR}/doc/randpktdump.html
2029                 ${CMAKE_BINARY_DIR}/doc/etwdump.html
2030                 ${CMAKE_BINARY_DIR}/doc/rawshark.html
2031                 ${CMAKE_BINARY_DIR}/doc/reordercap.html
2032                 ${CMAKE_BINARY_DIR}/doc/sshdump.html
2033                 ${CMAKE_BINARY_DIR}/doc/wifidump.html
2034                 ${CMAKE_BINARY_DIR}/doc/text2pcap.html
2035                 ${CMAKE_BINARY_DIR}/doc/tshark.html
2036                 ${CMAKE_BINARY_DIR}/doc/wireshark.html
2037                 ${CMAKE_BINARY_DIR}/doc/wireshark-filter.html
2038         )
2039         if(MAXMINDDB_FOUND)
2040                 list(APPEND DOC_FILES ${CMAKE_BINARY_DIR}/doc/mmdbresolve.html)
2041         endif()
2042
2043         if (BUILD_corbaidl2wrs)
2044                 list(APPEND DOC_FILES ${CMAKE_BINARY_DIR}/doc/idl2wrs.html)
2045         endif()
2046         if (BUILD_xxx2deb)
2047                 list(APPEND DOC_FILES
2048                         ${CMAKE_BINARY_DIR}/doc/asn2deb.html
2049                         ${CMAKE_BINARY_DIR}/doc/idl2deb.html
2050                 )
2051         endif()
2052         if (BUILD_logray)
2053                 list(APPEND DOC_FILES
2054                         ${CMAKE_BINARY_DIR}/doc/falcodump.html
2055                 )
2056         endif()
2057 endif()
2058
2059 if(NOT WIN32)
2060         # We do this for Windows further down in the copy_data_files target.
2061         list(APPEND DOC_FILES COPYING)
2062 endif()
2063
2064 if(USE_REPOSITORY)
2065         set(_dll_output_dir "$<TARGET_FILE_DIR:wsutil>")
2066         add_custom_target(copy_cli_dlls)
2067         set_target_properties(copy_cli_dlls PROPERTIES FOLDER "Copy Tasks")
2068         add_custom_command(TARGET copy_cli_dlls PRE_BUILD
2069                 COMMAND ${CMAKE_COMMAND} -E make_directory "${_dll_output_dir}"
2070         )
2071
2072         # XXX Can (and should) we iterate over these similar to the way
2073         # the top-level CMakeLists.txt iterates over the package list?
2074
2075         # Required DLLs and their corresponding PDBs.
2076         add_custom_command(TARGET copy_cli_dlls PRE_BUILD
2077                 COMMAND ${CMAKE_COMMAND} -E copy_if_different
2078                         "$<IF:$<CONFIG:Debug>,${GLIB2_DLLS_DEBUG},${GLIB2_DLLS_RELEASE}>"
2079                         "$<IF:$<CONFIG:Debug>,${GLIB2_PDBS_DEBUG},${GLIB2_PDBS_RELEASE}>"
2080                         "${_dll_output_dir}"
2081                 WORKING_DIRECTORY $<IF:$<CONFIG:Debug>,${GLIB2_DLL_DIR_DEBUG},${GLIB2_DLL_DIR_RELEASE}>
2082                 COMMAND_EXPAND_LISTS
2083         )
2084
2085         if (MSVC AND VLD_FOUND)
2086                 add_custom_command(TARGET copy_cli_dlls PRE_BUILD
2087                         COMMAND ${CMAKE_COMMAND} -E "$<IF:$<CONFIG:Debug>,copy_if_different,true>"
2088                         "${VLD_FILES}"
2089                         "${_dll_output_dir}"
2090                         COMMAND_EXPAND_LISTS
2091                 )
2092         endif()
2093
2094         # Third party DLLs and PDBs.
2095         set (THIRD_PARTY_DLLS)
2096         set (THIRD_PARTY_PDBS)
2097         if (AIRPCAP_FOUND)
2098                 list (APPEND THIRD_PARTY_DLLS "${AIRPCAP_DLL_DIR}/${AIRPCAP_DLL}")
2099         endif(AIRPCAP_FOUND)
2100         list (APPEND THIRD_PARTY_DLLS "${CARES_DLL_DIR}/${CARES_DLL}")
2101         list (APPEND THIRD_PARTY_PDBS "${CARES_DLL_DIR}/${CARES_PDB}")
2102         # vcpkg's libmaxminddb is static-only for now. This can be uncommented when
2103         # https://github.com/maxmind/libmaxminddb/commit/3998f42bdb6678cbaa1a543057e5c81ba1668ac2
2104         # percolates up to vcpkg.
2105         # if (MAXMINDDB_FOUND)
2106         #       list (APPEND THIRD_PARTY_DLLS "${MAXMINDDB_DLL_DIR}/${MAXMINDDB_DLL}")
2107         # endif(MAXMINDDB_FOUND)
2108         if (LIBSSH_FOUND)
2109                 foreach( _dll ${LIBSSH_DLLS} )
2110                         list (APPEND THIRD_PARTY_DLLS "${LIBSSH_DLL_DIR}/${_dll}")
2111                 endforeach(_dll)
2112         endif(LIBSSH_FOUND)
2113         foreach( _dll ${GCRYPT_DLLS} )
2114                 list (APPEND THIRD_PARTY_DLLS "${GCRYPT_DLL_DIR}/${_dll}")
2115         endforeach(_dll)
2116         foreach( _dll ${GNUTLS_DLLS} )
2117                 list (APPEND THIRD_PARTY_DLLS "${GNUTLS_DLL_DIR}/${_dll}")
2118         endforeach(_dll)
2119         foreach( _dll ${KERBEROS_DLLS} )
2120                 list (APPEND THIRD_PARTY_DLLS "${KERBEROS_DLL_DIR}/${_dll}")
2121         endforeach(_dll)
2122         if (LUA_FOUND)
2123                 list (APPEND THIRD_PARTY_DLLS "${LUA_DLL_DIR}/${LUA_DLL}")
2124         endif(LUA_FOUND)
2125         if (LZ4_FOUND)
2126                 list (APPEND THIRD_PARTY_DLLS "${LZ4_DLL_DIR}/${LZ4_DLL}")
2127                 list (APPEND THIRD_PARTY_PDBS "${LZ4_DLL_DIR}/${LZ4_PDB}")
2128         endif(LZ4_FOUND)
2129         if (ZSTD_FOUND)
2130                 list (APPEND THIRD_PARTY_DLLS "${ZSTD_DLL_DIR}/${ZSTD_DLL}")
2131         endif(ZSTD_FOUND)
2132         if (NGHTTP2_FOUND)
2133                 list (APPEND THIRD_PARTY_DLLS "${NGHTTP2_DLL_DIR}/${NGHTTP2_DLL}")
2134                 list (APPEND THIRD_PARTY_PDBS "${NGHTTP2_DLL_DIR}/${NGHTTP2_PDB}")
2135         endif(NGHTTP2_FOUND)
2136         if (PCRE2_FOUND)
2137                 list (APPEND THIRD_PARTY_DLLS "${PCRE2_DLL_DIR}/${PCRE2_DLL}")
2138                 list (APPEND THIRD_PARTY_PDBS "${PCRE2_DLL_DIR}/${PCRE2_PDB}")
2139         endif(PCRE2_FOUND)
2140         if (SBC_FOUND)
2141                 list (APPEND THIRD_PARTY_DLLS "${SBC_DLL_DIR}/${SBC_DLL}")
2142         endif(SBC_FOUND)
2143         if (SPANDSP_FOUND)
2144                 list (APPEND THIRD_PARTY_DLLS "${SPANDSP_DLL_DIR}/${SPANDSP_DLL}")
2145         endif(SPANDSP_FOUND)
2146         if (BCG729_FOUND)
2147                 list (APPEND THIRD_PARTY_DLLS "${BCG729_DLL_DIR}/${BCG729_DLL}")
2148         endif(BCG729_FOUND)
2149         if (AMRNB_FOUND)
2150                 list (APPEND OPTIONAL_DLLS "${AMRNB_DLL_DIR}/${AMRNB_DLL}")
2151         endif(AMRNB_FOUND)
2152         if (ILBC_FOUND)
2153                 list (APPEND THIRD_PARTY_DLLS "${ILBC_DLL_DIR}/${ILBC_DLL}")
2154         endif(ILBC_FOUND)
2155         if (OPUS_FOUND)
2156                 list (APPEND THIRD_PARTY_DLLS "${OPUS_DLL_DIR}/${OPUS_DLL}")
2157         endif(OPUS_FOUND)
2158         if (LIBXML2_FOUND)
2159                 foreach( _dll ${LIBXML2_DLLS} )
2160                         list (APPEND THIRD_PARTY_DLLS "${LIBXML2_DLL_DIR}/${_dll}")
2161                 endforeach(_dll)
2162                 foreach( _pdb ${LIBXML2_PDBS} )
2163                         list (APPEND THIRD_PARTY_PDBS "${LIBXML2_DLL_DIR}/${_pdb}")
2164                 endforeach(_pdb)
2165         endif(LIBXML2_FOUND)
2166         if (SMI_FOUND)
2167                 list (APPEND THIRD_PARTY_DLLS "${SMI_DLL_DIR}/${SMI_DLL}")
2168                 # Wireshark.nsi wants SMI_DIR which is the base SMI directory
2169                 get_filename_component(SMI_DIR ${SMI_DLL_DIR} DIRECTORY)
2170                 add_custom_command(TARGET copy_cli_dlls PRE_BUILD
2171                         COMMAND ${CMAKE_COMMAND} -E make_directory
2172                                 "${_dll_output_dir}/snmp"
2173                         COMMAND ${CMAKE_COMMAND} -E make_directory
2174                                 "${_dll_output_dir}/snmp/mibs"
2175                         COMMAND ${CMAKE_COMMAND} -E copy_directory
2176                                 "${SMI_SHARE_DIR}/mibs/iana"
2177                                 "${_dll_output_dir}/snmp/mibs"
2178                         COMMAND ${CMAKE_COMMAND} -E copy_directory
2179                                 "${SMI_SHARE_DIR}/mibs/ietf"
2180                                 "${_dll_output_dir}/snmp/mibs"
2181                         COMMAND ${CMAKE_COMMAND} -E copy_directory
2182                                 "${SMI_SHARE_DIR}/mibs/irtf"
2183                                 "${_dll_output_dir}/snmp/mibs"
2184                         COMMAND ${CMAKE_COMMAND} -E copy_directory
2185                                 "${SMI_SHARE_DIR}/mibs/site"
2186                                 "${_dll_output_dir}/snmp/mibs"
2187                         COMMAND ${CMAKE_COMMAND} -E copy_directory
2188                                 "${SMI_SHARE_DIR}/mibs/tubs"
2189                                 "${_dll_output_dir}/snmp/mibs"
2190                         COMMAND ${CMAKE_COMMAND} -E copy_directory
2191                                 "${SMI_SHARE_DIR}/pibs"
2192                                 "${_dll_output_dir}/snmp/mibs"
2193                         COMMAND ${CMAKE_COMMAND} -E copy_directory
2194                                 "${SMI_SHARE_DIR}/yang"
2195                                 "${_dll_output_dir}/snmp/mibs"
2196                         #remove the extra directories copied (shallow copying the above would remove the need for this)
2197                         COMMAND ${CMAKE_COMMAND} -E remove_directory
2198                                 "${_dll_output_dir}/snmp/mibs/iana"
2199                         COMMAND ${CMAKE_COMMAND} -E remove_directory
2200                                 "${_dll_output_dir}/snmp/mibs/ietf"
2201                         COMMAND ${CMAKE_COMMAND} -E remove_directory
2202                                 "${_dll_output_dir}/snmp/mibs/site"
2203                         COMMAND ${CMAKE_COMMAND} -E remove_directory
2204                                 "${_dll_output_dir}/snmp/mibs/tubs"
2205                 )
2206         endif(SMI_FOUND)
2207         if (SNAPPY_FOUND)
2208                 list (APPEND THIRD_PARTY_DLLS "${SNAPPY_DLL_DIR}/${SNAPPY_DLL}")
2209         endif(SNAPPY_FOUND)
2210         if (WINSPARKLE_FOUND)
2211                 list (APPEND THIRD_PARTY_DLLS "${WINSPARKLE_DLL_DIR}/${WINSPARKLE_DLL}")
2212         endif(WINSPARKLE_FOUND)
2213         if (ZLIB_FOUND)
2214                 list (APPEND THIRD_PARTY_DLLS "${ZLIB_DLL_DIR}/${ZLIB_DLL}")
2215                 list (APPEND THIRD_PARTY_PDBS "${ZLIB_DLL_DIR}/${ZLIB_PDB}")
2216         endif(ZLIB_FOUND)
2217         if (BROTLI_FOUND)
2218                 foreach( _dll ${BROTLI_DLLS} )
2219                         list (APPEND THIRD_PARTY_DLLS "${BROTLI_DLL_DIR}/${_dll}")
2220                 endforeach(_dll)
2221         endif(BROTLI_FOUND)
2222         if (SPEEXDSP_FOUND)
2223                 list (APPEND THIRD_PARTY_DLLS "${SPEEXDSP_DLL_DIR}/${SPEEXDSP_DLL}")
2224         endif()
2225
2226         # With libs downloaded to c:/wireshark-win64-libs this currently
2227         # (early 2018) expands to about 1900 characters.
2228         if (THIRD_PARTY_DLLS)
2229                 add_custom_command(TARGET copy_cli_dlls PRE_BUILD
2230                         COMMAND ${CMAKE_COMMAND} -E copy_if_different
2231                                 ${THIRD_PARTY_DLLS}
2232                                 "${_dll_output_dir}"
2233                         VERBATIM
2234                 )
2235                 install(FILES ${THIRD_PARTY_DLLS} DESTINATION "${CMAKE_INSTALL_BINDIR}")
2236         endif(THIRD_PARTY_DLLS)
2237
2238         if (THIRD_PARTY_PDBS)
2239                 add_custom_command(TARGET copy_cli_dlls PRE_BUILD
2240                         COMMAND ${CMAKE_COMMAND} -E copy_if_different
2241                                 ${THIRD_PARTY_PDBS}
2242                                 "${_dll_output_dir}"
2243                         VERBATIM
2244                 )
2245         endif(THIRD_PARTY_PDBS)
2246
2247         add_dependencies(epan copy_cli_dlls)
2248
2249         # We have a lot of choices for creating zip archives:
2250         # - 7z, WinZip, etc., which require a separate download+install.
2251         # - "CMake -E tar cz", which creates a tar file.
2252         # - CPack, which requires a CPack configuration.
2253         # - PowerShell via PSCX or System.IO.Compression.FileSystem.
2254         # - Python via zipfile.
2255         # For now, just look for 7z. It's installed on the Windows builders,
2256         # which might be the only systems that use this target.
2257         find_program(ZIP_EXECUTABLE 7z
2258                 PATH "$ENV{PROGRAMFILES}/7-Zip" "$ENV{PROGRAMW6432}/7-Zip"
2259                 DOC "Path to the 7z utility."
2260         )
2261         if(ZIP_EXECUTABLE)
2262                 add_custom_target(pdb_zip_package COMMENT "This packages .PDBs but will not create them.")
2263                 set_target_properties(pdb_zip_package PROPERTIES FOLDER "Packaging")
2264                 set(_pdb_zip "${CMAKE_BINARY_DIR}/Wireshark-pdb-${PROJECT_VERSION}-${WIRESHARK_TARGET_PROCESSOR_ARCHITECTURE}.zip")
2265                 file(TO_NATIVE_PATH "${_pdb_zip}" _pdb_zip_win)
2266                 add_custom_command(TARGET pdb_zip_package POST_BUILD
2267                         COMMAND ${CMAKE_COMMAND} -E remove -f "${_pdb_zip}"
2268                         COMMAND ${ZIP_EXECUTABLE} a -tzip -mmt=on "${_pdb_zip_win}"
2269                                 -bb0 -bd
2270                                 -r *.pdb *.lib
2271                         WORKING_DIRECTORY "${_dll_output_dir}"
2272                 )
2273         endif()
2274 endif()
2275
2276 # List of extra dependencies for the "copy_data_files" target
2277 set(copy_data_files_depends)
2278
2279 if(WIN32)
2280         foreach(_install_as_txt_file COPYING NEWS README.md README.windows)
2281                 # On Windows, install some files with a .txt extension so that they're
2282                 # double-clickable.
2283                 string(REGEX REPLACE ".md$" "" _no_md_file ${_install_as_txt_file})
2284                 set(_output_file "${DATAFILE_DIR}/${_no_md_file}.txt")
2285                 add_custom_command(OUTPUT ${_output_file}
2286                         COMMAND ${CMAKE_COMMAND} -E copy_if_different
2287                                 ${CMAKE_SOURCE_DIR}/${_install_as_txt_file}
2288                                 ${_output_file}
2289                         DEPENDS
2290                                 ${CMAKE_SOURCE_DIR}/${_install_as_txt_file}
2291                 )
2292                 list(APPEND copy_data_files_depends "${_output_file}")
2293         endforeach()
2294 endif()
2295
2296 foreach(_install_file ${INSTALL_FILES} ${DOC_FILES})
2297         get_filename_component(_install_file_src "${_install_file}" ABSOLUTE)
2298         get_filename_component(_install_basename "${_install_file}" NAME)
2299         set(_output_file "${DATAFILE_DIR}/${_install_basename}")
2300         add_custom_command(OUTPUT "${_output_file}"
2301                 COMMAND ${CMAKE_COMMAND} -E copy_if_different
2302                         "${_install_file_src}"
2303                         "${_output_file}"
2304                 DEPENDS
2305                         docs
2306                         "${_install_file}"
2307         )
2308         list(APPEND copy_data_files_depends "${_output_file}")
2309 endforeach()
2310
2311 if (BUILD_logray AND ENABLE_APPLICATION_BUNDLE)
2312         foreach(_install_file ${LOG_INSTALL_FILES})
2313                 get_filename_component(_install_file_src "${_install_file}" ABSOLUTE)
2314                 get_filename_component(_install_basename "${_install_file}" NAME)
2315                 set(_output_file "${LOG_DATAFILE_DIR}/${_install_basename}")
2316                 add_custom_command(OUTPUT "${_output_file}"
2317                         COMMAND ${CMAKE_COMMAND} -E copy_if_different
2318                                 "${_install_file_src}"
2319                                 "${_output_file}"
2320                         DEPENDS
2321                                 docs
2322                                 "${_install_file}"
2323                 )
2324                 list(APPEND copy_data_files_depends "${_output_file}")
2325         endforeach()
2326 endif()
2327
2328 # Install Lua files in staging directory such that Lua can used when Wireshark
2329 # is ran from the build directory. For install targets, see
2330 # epan/wslua/CMakeLists.txt
2331 if(LUA_FOUND AND ENABLE_LUA)
2332         set(_lua_files
2333                 "${CMAKE_SOURCE_DIR}/epan/wslua/init.lua"
2334                 "${CMAKE_SOURCE_DIR}/epan/wslua/console.lua"
2335                 "${CMAKE_SOURCE_DIR}/epan/wslua/dtd_gen.lua"
2336         )
2337         foreach(_lua_file ${_lua_files})
2338                 get_filename_component(_lua_filename "${_lua_file}" NAME)
2339                 list(APPEND copy_data_files_depends
2340                         "${DATAFILE_DIR}/${_lua_filename}")
2341                 add_custom_command(OUTPUT "${DATAFILE_DIR}/${_lua_filename}"
2342                         COMMAND ${CMAKE_COMMAND} -E copy_if_different
2343                                 "${_lua_file}"
2344                                 "${DATAFILE_DIR}/${_lua_filename}"
2345                         DEPENDS
2346                                 "${_lua_file}"
2347                 )
2348         endforeach()
2349 endif(LUA_FOUND AND ENABLE_LUA)
2350 # doc/*.html handled elsewhere.
2351
2352 set(_protocol_data_dir ${CMAKE_SOURCE_DIR}/resources/protocols)
2353 # Glob patterns relative to the source directory that should be copied to
2354 # ${DATAFILE_DIR} (including directory prefixes)
2355 # TODO shouldn't this use full (relative) paths instead of glob patterns?
2356 set(DATA_FILES_SRC
2357         ${_protocol_data_dir}/tpncp/tpncp.dat
2358         ${_protocol_data_dir}/wimaxasncp/*.dtd
2359         ${_protocol_data_dir}/wimaxasncp/*.xml
2360 )
2361
2362 # Copy all paths from the source tree to the data directory. Directories are
2363 # automatically created if missing as the filename is given.
2364 file(GLOB _data_files RELATIVE ${_protocol_data_dir} ${DATA_FILES_SRC})
2365 foreach(_data_file ${_data_files})
2366         add_custom_command(OUTPUT "${DATAFILE_DIR}/${_data_file}"
2367                 COMMAND ${CMAKE_COMMAND} -E copy_if_different
2368                         ${_protocol_data_dir}/${_data_file}
2369                         ${DATAFILE_DIR}/${_data_file}
2370                 DEPENDS
2371                         ${_protocol_data_dir}/${_data_file}
2372         )
2373         list(APPEND copy_data_files_depends ${DATAFILE_DIR}/${_data_file})
2374 endforeach()
2375
2376 file(GLOB _dtds_src_files RELATIVE ${_protocol_data_dir} ${_protocol_data_dir}/dtds/*.dtd)
2377
2378 set (_dtds_data_files)
2379 set (_dtds_dep_files)
2380 foreach(_data_file ${_dtds_src_files})
2381         list(APPEND _dtds_data_files ${DATAFILE_DIR}/${_data_file})
2382         list(APPEND _dtds_dep_files ${_protocol_data_dir}/${_data_file})
2383 endforeach()
2384
2385 add_custom_command(
2386         OUTPUT ${_dtds_data_files}
2387         COMMAND ${CMAKE_COMMAND} -E make_directory ${DATAFILE_DIR}/dtds
2388         COMMAND ${CMAKE_COMMAND} -E copy_if_different
2389                 ${_dtds_src_files}
2390                 ${DATAFILE_DIR}/dtds
2391         VERBATIM
2392         DEPENDS ${_dtds_dep_files}
2393         WORKING_DIRECTORY ${_protocol_data_dir}
2394 )
2395
2396 file(GLOB _diameter_src_files RELATIVE ${_protocol_data_dir}
2397         ${_protocol_data_dir}/diameter/*.dtd
2398         ${_protocol_data_dir}/diameter/*.xml
2399 )
2400
2401 set (_diameter_data_files)
2402 set (_diameter_dep_files)
2403 foreach(_data_file ${_diameter_src_files})
2404         list(APPEND _diameter_data_files ${DATAFILE_DIR}/${_data_file})
2405         list(APPEND _diameter_dep_files ${_protocol_data_dir}/${_data_file})
2406 endforeach()
2407
2408 add_custom_command(
2409         OUTPUT ${_diameter_data_files}
2410         COMMAND ${CMAKE_COMMAND} -E make_directory ${DATAFILE_DIR}/diameter
2411         COMMAND ${CMAKE_COMMAND} -E copy_if_different
2412                 ${_diameter_src_files}
2413                 ${DATAFILE_DIR}/diameter
2414         VERBATIM
2415         DEPENDS ${_diameter_dep_files}
2416         WORKING_DIRECTORY ${_protocol_data_dir}
2417 )
2418
2419 file(GLOB _radius_src_files RELATIVE ${_protocol_data_dir}
2420         ${_protocol_data_dir}/radius/README.radius_dictionary
2421         ${_protocol_data_dir}/radius/custom.includes
2422         ${_protocol_data_dir}/radius/dictionary
2423         ${_protocol_data_dir}/radius/dictionary.*
2424 )
2425
2426 set (_radius_data_files)
2427 set (_radius_dep_files)
2428 foreach(_data_file ${_radius_src_files})
2429         list(APPEND _radius_data_files ${DATAFILE_DIR}/${_data_file})
2430         list(APPEND _radius_dep_files ${_protocol_data_dir}/${_data_file})
2431 endforeach()
2432
2433 add_custom_command(
2434         OUTPUT ${_radius_data_files}
2435         COMMAND ${CMAKE_COMMAND} -E make_directory ${DATAFILE_DIR}/radius
2436         COMMAND ${CMAKE_COMMAND} -E copy_if_different
2437                 ${_radius_src_files}
2438                 ${DATAFILE_DIR}/radius
2439         VERBATIM
2440         DEPENDS ${_radius_dep_files}
2441         WORKING_DIRECTORY ${_protocol_data_dir}
2442 )
2443
2444 file(GLOB _protobuf_src_files RELATIVE ${_protocol_data_dir}
2445         ${_protocol_data_dir}/protobuf/*.proto
2446 )
2447 set (_protobuf_data_files)
2448 set (_protobuf_dep_files)
2449 foreach(_data_file ${_protobuf_src_files})
2450         list(APPEND _protobuf_data_files ${DATAFILE_DIR}/${_data_file})
2451         list(APPEND _protobuf_dep_files ${_protocol_data_dir}/${_data_file})
2452 endforeach()
2453
2454 add_custom_command(
2455         OUTPUT ${_protobuf_data_files}
2456         COMMAND ${CMAKE_COMMAND} -E make_directory ${DATAFILE_DIR}/protobuf
2457         COMMAND ${CMAKE_COMMAND} -E copy_if_different
2458                 ${_protobuf_src_files}
2459                 ${DATAFILE_DIR}/protobuf
2460         VERBATIM
2461         DEPENDS ${_protobuf_dep_files}
2462         WORKING_DIRECTORY ${_protocol_data_dir}
2463 )
2464
2465 set(_profiles_src_dir ${CMAKE_SOURCE_DIR}/resources/share/wireshark)
2466 file(GLOB _profiles_src_files RELATIVE ${_profiles_src_dir} ${_profiles_src_dir}/profiles/*/*)
2467 set (_profiles_data_files)
2468 foreach(_data_file ${_profiles_src_files})
2469         list(APPEND _profiles_data_files "${DATAFILE_DIR}/${_data_file}")
2470 endforeach()
2471
2472 add_custom_command(
2473         OUTPUT ${_profiles_data_files}
2474         COMMAND ${CMAKE_COMMAND} -E copy_directory
2475                 "${CMAKE_SOURCE_DIR}/resources/share/wireshark/profiles" "${DATAFILE_DIR}/profiles"
2476 )
2477
2478 list(APPEND copy_data_files_depends
2479         ${_dtds_data_files}
2480         ${_diameter_data_files}
2481         ${_radius_data_files}
2482         ${_protobuf_data_files}
2483         ${_profiles_data_files}
2484 )
2485
2486 # Copy files including ${INSTALL_FILES} and ${INSTALL_DIRS} to ${DATAFILE_DIR}
2487 add_custom_target(copy_data_files ALL DEPENDS ${copy_data_files_depends} )
2488 set_target_properties(copy_data_files PROPERTIES FOLDER "Copy Tasks")
2489
2490 # sources common for wireshark, tshark, rawshark and sharkd
2491 add_library(shark_common OBJECT
2492         cfile.c
2493         extcap_parser.c
2494         file_packet_provider.c
2495         frame_tvbuff.c
2496         sync_pipe_write.c
2497 )
2498 add_library(cli_main OBJECT cli_main.c)
2499 add_library(capture_opts OBJECT capture_opts.c)
2500 target_include_directories(capture_opts SYSTEM PRIVATE ${PCAP_INCLUDE_DIRS})
2501 set_target_properties(shark_common cli_main capture_opts
2502         PROPERTIES
2503         COMPILE_FLAGS "${WERROR_COMMON_FLAGS}"
2504 )
2505
2506
2507 if(BUILD_wireshark AND QT_FOUND)
2508         set(WIRESHARK_SRC
2509                 file.c
2510                 fileset.c
2511                 extcap.c
2512                 ${PLATFORM_UI_SRC}
2513         )
2514         set(wireshark_FILES
2515                 $<TARGET_OBJECTS:capture_opts>
2516                 $<TARGET_OBJECTS:qtui>
2517                 $<TARGET_OBJECTS:shark_common>
2518                 ${WIRESHARK_SRC}
2519                 ${PLATFORM_UI_RC_FILES}
2520         )
2521         set_executable_resources(wireshark "Wireshark" UNIQUE_RC)
2522 endif()
2523
2524 if(BUILD_logray AND QT_FOUND)
2525         set(LOGRAY_SRC
2526                 file.c
2527                 fileset.c
2528                 extcap.c
2529                 ${PLATFORM_UI_SRC}
2530         )
2531         set(logray_FILES
2532                 $<TARGET_OBJECTS:capture_opts>
2533                 $<TARGET_OBJECTS:ui_logray>
2534                 $<TARGET_OBJECTS:shark_common>
2535                 ${LOGRAY_SRC}
2536                 ${PLATFORM_UI_RC_FILES}
2537         )
2538         set_executable_resources(logray "Logray" UNIQUE_RC)
2539 endif()
2540
2541 if(ENABLE_APPLICATION_BUNDLE)
2542         #
2543         # Add -Wl,-single_module to the LDFLAGS used with shared
2544         # libraries, to fix some error that show up in some cases;
2545         # some Apple documentation recommends it for most shared
2546         # libraries.
2547         #
2548         set( CMAKE_SHARED_LINKER_FLAGS "-Wl,-single_module ${CMAKE_SHARED_LINKER_FLAGS}" )
2549         #
2550         # Add -Wl,-headerpad_max_install_names to the LDFLAGS, as
2551         # code-signing issues is running out of padding space.
2552         #
2553         # Add -Wl,-search_paths_first to make sure that if we search
2554         # directories A and B, in that order, for a given library, a
2555         # non-shared version in directory A, rather than a shared
2556         # version in directory B, is chosen (so we can use
2557         # --with-pcap=/usr/local to force all programs to be linked
2558         # with a static version installed in /usr/local/lib rather than
2559         # the system version in /usr/lib).
2560         #
2561
2562         set(CMAKE_EXE_LINKER_FLAGS
2563         "-Wl,-headerpad_max_install_names -Wl,-search_paths_first ${CMAKE_EXE_LINKER_FLAGS}"
2564         )
2565
2566         # Add files to the Wireshark application bundle
2567         # Wireshark.app/Contents
2568         file(WRITE ${CMAKE_BINARY_DIR}/packaging/macosx/wireshark/PkgInfo "APPLWshk\n")
2569         set(WIRESHARK_BUNDLE_CONTENTS_FILES
2570                 ${CMAKE_BINARY_DIR}/packaging/macosx/wireshark/PkgInfo
2571         )
2572         set_source_files_properties(${WIRESHARK_BUNDLE_CONTENTS_FILES} PROPERTIES
2573                 MACOSX_PACKAGE_LOCATION .
2574         )
2575
2576         # Wireshark.app/Contents/Resources
2577         set(WIRESHARK_BUNDLE_RESOURCE_FILES
2578                 ${CMAKE_SOURCE_DIR}/packaging/macosx/Wireshark.icns
2579                 ${CMAKE_SOURCE_DIR}/packaging/macosx/Wiresharkdoc.icns
2580         )
2581         set_source_files_properties(${WIRESHARK_BUNDLE_RESOURCE_FILES} PROPERTIES
2582                 MACOSX_PACKAGE_LOCATION Resources
2583         )
2584
2585         # Wireshark.app/Contents/Resources/share/man/man1
2586         set_source_files_properties(${WIRESHARK_BUNDLE_RESOURCE_SHARE_MAN1_FILES} PROPERTIES
2587                 MACOSX_PACKAGE_LOCATION Resources/share/man/man1
2588                 GENERATED 1
2589         )
2590
2591         # Wireshark.app/Contents/Resources/share/man/man4
2592         set_source_files_properties(${WIRESHARK_BUNDLE_RESOURCE_SHARE_MAN4_FILES} PROPERTIES
2593                 MACOSX_PACKAGE_LOCATION Resources/share/man/man4
2594                 GENERATED 1
2595         )
2596
2597         # INSTALL_FILES and INSTALL_DIRS are handled by copy_data_files
2598
2599         set(EXTRA_WIRESHARK_BUNDLE_FILES
2600                 ${WIRESHARK_BUNDLE_CONTENTS_FILES}
2601                 ${WIRESHARK_BUNDLE_RESOURCE_FILES}
2602                 ${WIRESHARK_BUNDLE_RESOURCE_SHARE_MAN1_FILES}
2603                 ${WIRESHARK_BUNDLE_RESOURCE_SHARE_MAN4_FILES}
2604         )
2605
2606         # Add files to the Logray application bundle
2607         # Logray.app/Contents
2608         file(WRITE ${CMAKE_BINARY_DIR}/packaging/macosx/logray/PkgInfo "APPLLgry\n")
2609         set(LOGRAY_BUNDLE_CONTENTS_FILES
2610                 ${CMAKE_BINARY_DIR}/packaging/macosx/logray/PkgInfo
2611         )
2612         set_source_files_properties(${LOGRAY_BUNDLE_CONTENTS_FILES} PROPERTIES
2613                 MACOSX_PACKAGE_LOCATION .
2614         )
2615
2616         # Logray.app/Contents/Resources
2617         set(LOGRAY_BUNDLE_RESOURCE_FILES
2618                 ${CMAKE_SOURCE_DIR}/packaging/macosx/Logray.icns
2619                 ${CMAKE_SOURCE_DIR}/packaging/macosx/Wiresharkdoc.icns
2620         )
2621         set_source_files_properties(${LOGRAY_BUNDLE_RESOURCE_FILES} PROPERTIES
2622                 MACOSX_PACKAGE_LOCATION Resources
2623         )
2624
2625         # Logray.app/Contents/Resources/share/man/man1
2626         set_source_files_properties(${LOGRAY_BUNDLE_RESOURCE_SHARE_MAN1_FILES} PROPERTIES
2627                 MACOSX_PACKAGE_LOCATION Resources/share/man/man1
2628                 GENERATED 1
2629         )
2630
2631         # Logray.app/Contents/Resources/share/man/man4
2632         set_source_files_properties(${LOGRAY_BUNDLE_RESOURCE_SHARE_MAN4_FILES} PROPERTIES
2633                 MACOSX_PACKAGE_LOCATION Resources/share/man/man4
2634                 GENERATED 1
2635         )
2636
2637         # INSTALL_FILES and INSTALL_DIRS are handled by copy_data_files
2638
2639         set(EXTRA_LOGRAY_BUNDLE_FILES
2640                 ${LOGRAY_BUNDLE_CONTENTS_FILES}
2641                 ${LOGRAY_BUNDLE_RESOURCE_FILES}
2642                 ${LOGRAY_BUNDLE_RESOURCE_SHARE_MAN1_FILES}
2643                 ${LOGRAY_BUNDLE_RESOURCE_SHARE_MAN4_FILES}
2644         )
2645
2646 else()
2647         set(EXTRA_WIRESHARK_BUNDLE_FILES)
2648         set(EXTRA_LOGRAY_BUNDLE_FILES)
2649 endif()
2650
2651 if(BUILD_wireshark AND QT_FOUND)
2652         set(wireshark_LIBS
2653                 ui
2654                 capchild
2655                 caputils
2656                 iface_monitor
2657                 wiretap
2658                 epan
2659                 summary
2660                 ${QT_LIBRARIES}
2661                 ${APPLE_APPLICATION_SERVICES_LIBRARY}
2662                 ${APPLE_APPKIT_LIBRARY}
2663                 ${APPLE_CORE_FOUNDATION_LIBRARY}
2664                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
2665                 ${SPARKLE_LIBRARIES}
2666                 ${WIN_WS2_32_LIBRARY}
2667                 ${WIN_VERSION_LIBRARY}
2668                 ${WINSPARKLE_LIBRARIES}
2669                 $<$<BOOL:${WIN32}>:uxtheme.lib>
2670                 ${SPEEXDSP_LIBRARIES}
2671                 ${ZLIB_LIBRARIES}
2672                 ${MINIZIP_LIBRARIES}
2673         )
2674
2675         add_executable(wireshark WIN32 MACOSX_BUNDLE ${wireshark_FILES} ${EXTRA_WIRESHARK_BUNDLE_FILES})
2676         if(MSVC)
2677                 set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT wireshark)
2678         endif()
2679         set(PROGLIST ${PROGLIST} wireshark)
2680         set_target_properties(wireshark PROPERTIES
2681                 LINK_FLAGS "${WS_LINK_FLAGS}"
2682                 FOLDER "Executables"
2683                 INSTALL_RPATH "${EXECUTABLE_INSTALL_RPATH}"
2684                 AUTOMOC ON
2685                 AUTOUIC ON
2686                 AUTORCC ON
2687         )
2688         if(MSVC)
2689                 set_target_properties(wireshark PROPERTIES LINK_FLAGS_DEBUG "${WS_MSVC_DEBUG_LINK_FLAGS}")
2690         endif()
2691         if (USE_MSYSTEM)
2692                 set_target_properties(wireshark PROPERTIES OUTPUT_NAME wireshark)
2693         elseif(ENABLE_APPLICATION_BUNDLE OR WIN32)
2694                 set_target_properties(wireshark PROPERTIES OUTPUT_NAME Wireshark)
2695         endif()
2696
2697         if(ENABLE_APPLICATION_BUNDLE)
2698                 if(ASCIIDOCTOR_FOUND)
2699                         # Make sure to generate files referenced by
2700                         # WIRESHARK_BUNDLE_RESOURCE_SHARE_MAN1_FILES
2701                         add_dependencies(wireshark manpages)
2702                 endif()
2703                 set_target_properties(
2704                         wireshark PROPERTIES
2705                                 MACOSX_BUNDLE_INFO_PLIST ${CMAKE_BINARY_DIR}/packaging/macosx/WiresharkInfo.plist
2706                 )
2707                 if(CMAKE_CFG_INTDIR STREQUAL ".")
2708                         # Add a wrapper script which opens the bundle. This is more convenient
2709                         # and lets Sparkle find our CFBundleIdentifier, but means that you have
2710                         # to pass the full path to run/Wireshark.app/Contents/MacOS/Wireshark
2711                         # to your debugger.
2712                         # It is not created if using Xcode
2713                         file(REMOVE ${CMAKE_BINARY_DIR}/run/wireshark)
2714                         file(WRITE ${CMAKE_BINARY_DIR}/run/wireshark "#!/bin/sh\n")
2715                         file(APPEND ${CMAKE_BINARY_DIR}/run/wireshark "# Generated by ${CMAKE_CURRENT_LIST_FILE}\n")
2716                         file(APPEND ${CMAKE_BINARY_DIR}/run/wireshark "# Wrapper script which ensures that we're properly activated via Launch Services\n")
2717                         file(APPEND ${CMAKE_BINARY_DIR}/run/wireshark "exec ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/MacOS/Wireshark \"\$\@\"\n")
2718                         execute_process(COMMAND chmod a+x ${CMAKE_BINARY_DIR}/run/wireshark)
2719                 endif()
2720         endif()
2721
2722         target_link_libraries(wireshark ${wireshark_LIBS})
2723         target_include_directories(wireshark SYSTEM PRIVATE ${SPARKLE_INCLUDE_DIRS})
2724
2725         install(
2726                 TARGETS wireshark
2727                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
2728                 BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}
2729         )
2730
2731         if(QT_WINDEPLOYQT_EXECUTABLE)
2732                 add_custom_target(copy_qt_dlls ALL)
2733                 set_target_properties(copy_qt_dlls PROPERTIES FOLDER "Copy Tasks")
2734                 # Will we ever need to use --debug? Windeployqt seems to
2735                 # be smart enough to copy debug DLLs when needed.
2736                 if (USE_MSYSTEM AND Qt${qtver}Widgets_VERSION VERSION_EQUAL 6.5.0)
2737                         # windeployqt released with Qt 6.5.0 is broken.
2738                         # https://bugreports.qt.io/browse/QTBUG-112204
2739                         message(WARNING "Qt Deploy Tool 6.5.0 is broken, skipping translations.")
2740                         list(APPEND QT_WINDEPLOYQT_EXTRA_ARGS --no-translations)
2741                         set(SKIP_QT_TRANSLATIONS True)
2742                 endif()
2743                 add_custom_command(TARGET copy_qt_dlls
2744                         POST_BUILD
2745                         COMMAND set "PATH=${QT_BIN_PATH};%PATH%"
2746                         COMMAND "${QT_WINDEPLOYQT_EXECUTABLE}"
2747                                 ${QT_WINDEPLOYQT_EXTRA_ARGS}
2748                                 --no-compiler-runtime
2749                                 --verbose 0
2750                                 $<$<BOOL:${MSVC}>:--pdb>
2751                                 "$<TARGET_FILE:wireshark>"
2752                 )
2753                 add_dependencies(copy_qt_dlls wireshark)
2754
2755                 install(CODE "execute_process(COMMAND
2756                         \"${QT_WINDEPLOYQT_EXECUTABLE}\"
2757                         --no-compiler-runtime
2758                         \"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/Wireshark.exe\")"
2759                 )
2760
2761         endif(QT_WINDEPLOYQT_EXECUTABLE)
2762 endif()
2763
2764 if(BUILD_logray AND QT_FOUND)
2765         set(logray_LIBS
2766                 ui
2767                 capchild
2768                 caputils
2769                 iface_monitor
2770                 wiretap
2771                 epan
2772                 summary
2773                 ${QT_LIBRARIES}
2774                 ${APPLE_APPLICATION_SERVICES_LIBRARY}
2775                 ${APPLE_APPKIT_LIBRARY}
2776                 ${APPLE_CORE_FOUNDATION_LIBRARY}
2777                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
2778                 ${SPARKLE_LIBRARIES}
2779                 ${WIN_WS2_32_LIBRARY}
2780                 ${WIN_VERSION_LIBRARY}
2781                 ${WINSPARKLE_LIBRARIES}
2782                 $<$<BOOL:${WIN32}>:uxtheme.lib>
2783                 ${SPEEXDSP_LIBRARIES}
2784                 ${ZLIB_LIBRARIES}
2785                 ${MINIZIP_LIBRARIES}
2786         )
2787
2788         add_executable(logray WIN32 MACOSX_BUNDLE ${logray_FILES} ${EXTRA_LOGRAY_BUNDLE_FILES})
2789         if(WIN32 AND NOT BUILD_wireshark)
2790                 set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT logray)
2791         endif()
2792         set(PROGLIST ${PROGLIST} logray)
2793         set_target_properties(logray PROPERTIES
2794                 LINK_FLAGS "${WS_LINK_FLAGS}"
2795                 FOLDER "Executables"
2796                 INSTALL_RPATH "${EXECUTABLE_INSTALL_RPATH}"
2797                 AUTOMOC ON
2798                 AUTOUIC ON
2799                 AUTORCC ON
2800         )
2801         if(MSVC)
2802                 set_target_properties(logray PROPERTIES LINK_FLAGS_DEBUG "${WS_MSVC_DEBUG_LINK_FLAGS}")
2803         endif()
2804         if(ENABLE_APPLICATION_BUNDLE OR WIN32)
2805                 set_target_properties(logray PROPERTIES OUTPUT_NAME Logray)
2806         endif()
2807
2808         if(ENABLE_APPLICATION_BUNDLE)
2809                 if(ASCIIDOCTOR_FOUND)
2810                         # Make sure to generate files referenced by
2811                         # LOGRAY_BUNDLE_RESOURCE_SHARE_MAN1_FILES
2812                         add_dependencies(logray manpages)
2813                 endif()
2814                 set_target_properties(
2815                         logray PROPERTIES
2816                                 MACOSX_BUNDLE_INFO_PLIST ${CMAKE_BINARY_DIR}/packaging/macosx/LograyInfo.plist
2817                 )
2818                 if(CMAKE_CFG_INTDIR STREQUAL ".")
2819                         # Add a wrapper script which opens the bundle. This is more convenient
2820                         # and lets Sparkle find our CFBundleIdentifier, but means that you have
2821                         # to pass the full path to run/Wireshark.app/Contents/MacOS/Logray
2822                         # to your debugger.
2823                         # It is not created if using Xcode
2824                         file(REMOVE ${CMAKE_BINARY_DIR}/run/logray)
2825                         file(WRITE ${CMAKE_BINARY_DIR}/run/logray "#!/bin/sh\n")
2826                         file(APPEND ${CMAKE_BINARY_DIR}/run/logray "# Generated by ${CMAKE_CURRENT_LIST_FILE}\n")
2827                         file(APPEND ${CMAKE_BINARY_DIR}/run/logray "# Wrapper script which ensures that we're properly activated via Launch Services\n")
2828                         file(APPEND ${CMAKE_BINARY_DIR}/run/logray "exec ${CMAKE_BINARY_DIR}/run/Logray.app/Contents/MacOS/Logray \"\$\@\"\n")
2829                         execute_process(COMMAND chmod a+x ${CMAKE_BINARY_DIR}/run/logray)
2830                 endif()
2831         endif()
2832
2833         target_link_libraries(logray ${logray_LIBS})
2834         target_include_directories(logray SYSTEM PRIVATE ${SPARKLE_INCLUDE_DIRS})
2835
2836         install(
2837                 TARGETS logray
2838                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
2839                 BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}
2840         )
2841
2842         if(QT_WINDEPLOYQT_EXECUTABLE)
2843                 add_custom_target(copy_ls_qt_dlls ALL)
2844                 set_target_properties(copy_ls_qt_dlls PROPERTIES FOLDER "Copy Tasks")
2845                 # Will we ever need to use --debug? Windeployqt seems to
2846                 # be smart enough to copy debug DLLs when needed.
2847                 add_custom_command(TARGET copy_ls_qt_dlls
2848                         POST_BUILD
2849                         COMMAND set "PATH=${QT_BIN_PATH};%PATH%"
2850                         COMMAND "${QT_WINDEPLOYQT_EXECUTABLE}"
2851                                 --no-compiler-runtime
2852                                 --verbose 0
2853                                 $<$<BOOL:${MSVC}>:--pdb>
2854                                 "$<TARGET_FILE:logray>"
2855                 )
2856                 add_dependencies(copy_ls_qt_dlls logray)
2857
2858                 install(CODE "execute_process(COMMAND
2859                         \"${QT_WINDEPLOYQT_EXECUTABLE}\"
2860                         --no-compiler-runtime
2861                         \"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/Logray.exe\")"
2862                 )
2863
2864         endif(QT_WINDEPLOYQT_EXECUTABLE)
2865 endif()
2866
2867 if (BUILD_logray AND FALCO_PLUGINS)
2868         add_custom_target(copy_falco_plugins)
2869         add_custom_command(TARGET copy_falco_plugins
2870                 COMMAND ${CMAKE_COMMAND} -E make_directory ${LOGRAY_PLUGIN_DIR}/falco
2871                 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${FALCO_PLUGINS} ${LOGRAY_PLUGIN_DIR}/falco
2872                 VERBATIM
2873         )
2874         add_dependencies(logray copy_falco_plugins)
2875 endif()
2876
2877 # Common properties for CLI executables
2878 macro(set_extra_executable_properties _executable _folder)
2879         set_target_properties(${_executable} PROPERTIES
2880                 LINK_FLAGS "${WILDCARD_OBJ} ${WS_LINK_FLAGS}"
2881                 FOLDER ${_folder}
2882                 INSTALL_RPATH "${EXECUTABLE_INSTALL_RPATH}"
2883         )
2884         if(MSVC)
2885                 set_target_properties(${_executable} PROPERTIES LINK_FLAGS_DEBUG "${WS_MSVC_DEBUG_LINK_FLAGS}")
2886         endif()
2887
2888         set(PROGLIST ${PROGLIST} ${_executable})
2889
2890         if(ENABLE_APPLICATION_BUNDLE)
2891                 if(NOT CMAKE_CFG_INTDIR STREQUAL ".")
2892                         # Xcode
2893                         set_target_properties(${_executable} PROPERTIES
2894                                 RUNTIME_OUTPUT_DIRECTORY run/$<CONFIG>/Wireshark.app/Contents/MacOS
2895                         )
2896                 else ()
2897                         set_target_properties(${_executable} PROPERTIES
2898                                 RUNTIME_OUTPUT_DIRECTORY run/Wireshark.app/Contents/MacOS
2899                         )
2900                         # Create a convenience link from run/<name> to its respective
2901                         # target in the application bundle.
2902                         add_custom_target(${_executable}-symlink
2903                                 COMMAND ln -s -f
2904                                         Wireshark.app/Contents/MacOS/${_executable}
2905                                         ${CMAKE_BINARY_DIR}/run/${_executable}
2906                         )
2907                         add_dependencies(${_executable} ${_executable}-symlink)
2908                 endif()
2909         endif()
2910 endmacro()
2911
2912 macro(executable_link_mingw_unicode _target)
2913         # target_link_options() requires CMake >= 3.13
2914         if (MINGW)
2915                 target_link_options(${_target} PRIVATE "-municode")
2916         endif()
2917 endmacro()
2918
2919 register_tap_files(tshark-tap-register.c
2920         ${TSHARK_TAP_SRC}
2921 )
2922
2923 if(BUILD_tshark)
2924         set(tshark_LIBS
2925                 ui
2926                 capchild
2927                 caputils
2928                 wiretap
2929                 epan
2930                 wsutil
2931                 ${APPLE_CORE_FOUNDATION_LIBRARY}
2932                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
2933                 ${WIN_WS2_32_LIBRARY}
2934                 ${M_LIBRARIES}
2935         )
2936         set(tshark_FILES
2937                 $<TARGET_OBJECTS:capture_opts>
2938                 $<TARGET_OBJECTS:cli_main>
2939                 $<TARGET_OBJECTS:shark_common>
2940                 tshark-tap-register.c
2941                 tshark.c
2942                 extcap.c
2943                 ${TSHARK_TAP_SRC}
2944         )
2945
2946         set_executable_resources(tshark "TShark" UNIQUE_RC)
2947         add_executable(tshark ${tshark_FILES})
2948         set_extra_executable_properties(tshark "Executables")
2949         target_link_libraries(tshark ${tshark_LIBS})
2950         executable_link_mingw_unicode(tshark)
2951         install(TARGETS tshark RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2952 endif()
2953
2954 if(BUILD_tfshark)
2955         set(tfshark_LIBS
2956                 m
2957                 ui
2958                 wiretap
2959                 epan
2960                 ${APPLE_CORE_FOUNDATION_LIBRARY}
2961                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
2962         )
2963         set(tfshark_FILES
2964                 $<TARGET_OBJECTS:cli_main>
2965                 $<TARGET_OBJECTS:shark_common>
2966                 tfshark.c
2967                 ${TSHARK_TAP_SRC}
2968         )
2969         set_executable_resources(tfshark "TFShark")
2970         add_executable(tfshark ${tfshark_FILES})
2971         set_extra_executable_properties(tfshark "Executables")
2972         target_link_libraries(tfshark ${tfshark_LIBS})
2973         install(TARGETS tfshark RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2974 endif()
2975
2976 if(BUILD_rawshark AND PCAP_FOUND)
2977         set(rawshark_LIBS
2978                 caputils
2979                 ui
2980                 wiretap
2981                 epan
2982                 ${APPLE_CORE_FOUNDATION_LIBRARY}
2983                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
2984                 ${WIN_WS2_32_LIBRARY}
2985         )
2986         set(rawshark_FILES
2987                 $<TARGET_OBJECTS:cli_main>
2988                 $<TARGET_OBJECTS:shark_common>
2989                 rawshark.c
2990         )
2991         set_executable_resources(rawshark "Rawshark")
2992         add_executable(rawshark ${rawshark_FILES})
2993         set_extra_executable_properties(rawshark "Executables")
2994         target_link_libraries(rawshark ${rawshark_LIBS})
2995         executable_link_mingw_unicode(rawshark)
2996         install(TARGETS rawshark RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2997 endif()
2998
2999 if(BUILD_sharkd)
3000         set(sharkd_LIBS
3001                 ui
3002                 wiretap
3003                 epan
3004                 ${APPLE_CORE_FOUNDATION_LIBRARY}
3005                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
3006                 ${WIN_WS2_32_LIBRARY}
3007                 ${SPEEXDSP_LIBRARIES}
3008         )
3009         set(sharkd_FILES
3010                 #
3011                 # XXX - currently doesn't work on Windows if it uses
3012                 # $<TARGET_OBJECTS:cli_main> and has real_main().
3013                 #
3014                 $<TARGET_OBJECTS:shark_common>
3015                 sharkd.c
3016                 sharkd_daemon.c
3017                 sharkd_session.c
3018         )
3019         set_executable_resources(sharkd "SharkD")
3020         add_executable(sharkd ${sharkd_FILES})
3021         set_extra_executable_properties(sharkd "Executables")
3022         target_link_libraries(sharkd ${sharkd_LIBS})
3023         target_include_directories(sharkd SYSTEM PUBLIC ${SPEEXDSP_INCLUDE_DIRS})
3024
3025         install(TARGETS sharkd RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
3026 endif()
3027
3028 if(BUILD_dftest)
3029         set(dftest_LIBS
3030                 ui
3031                 wiretap
3032                 epan
3033         )
3034         set(dftest_FILES
3035                 dftest.c
3036         )
3037         set_executable_resources(dftest "Dftest")
3038         add_executable(dftest ${dftest_FILES})
3039         set_extra_executable_properties(dftest "Tests")
3040         target_link_libraries(dftest ${dftest_LIBS})
3041 endif()
3042
3043 if(BUILD_randpkt)
3044         set(randpkt_LIBS
3045                 randpkt_core
3046                 ui
3047                 wiretap
3048                 wsutil
3049         )
3050         set(randpkt_FILES
3051                 $<TARGET_OBJECTS:cli_main>
3052                 randpkt.c
3053         )
3054         set_executable_resources(randpkt "Randpkt"
3055                 COPYRIGHT_INFO "Copyright (C) 1999 by Gilbert Ramirez <gram@alumni.rice.edu>")
3056         add_executable(randpkt ${randpkt_FILES})
3057         set_extra_executable_properties(randpkt "Executables")
3058         target_link_libraries(randpkt ${randpkt_LIBS})
3059         executable_link_mingw_unicode(randpkt)
3060         install(TARGETS randpkt RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
3061 endif()
3062
3063 if(BUILD_fuzzshark OR ENABLE_FUZZER OR OSS_FUZZ)
3064         add_subdirectory(fuzz)
3065 endif()
3066
3067 if(BUILD_text2pcap)
3068         set(text2pcap_LIBS
3069                 wiretap
3070                 wsutil
3071                 ui
3072                 epan
3073                 ${ZLIB_LIBRARIES}
3074         )
3075         set(text2pcap_FILES
3076                 $<TARGET_OBJECTS:cli_main>
3077                 text2pcap.c
3078         )
3079         set_executable_resources(text2pcap "Text2pcap"
3080                 COPYRIGHT_INFO "2001 Ashok Narayanan <ashokn@cisco.com>")
3081         add_executable(text2pcap ${text2pcap_FILES})
3082         set_extra_executable_properties(text2pcap "Executables")
3083         target_link_libraries(text2pcap ${text2pcap_LIBS})
3084         executable_link_mingw_unicode(text2pcap)
3085         install(TARGETS text2pcap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
3086 endif()
3087
3088 if(BUILD_mergecap)
3089         set(mergecap_LIBS
3090                 ui
3091                 wiretap
3092                 ${ZLIB_LIBRARIES}
3093                 ${CMAKE_DL_LIBS}
3094         )
3095         set(mergecap_FILES
3096                 $<TARGET_OBJECTS:cli_main>
3097                 mergecap.c
3098         )
3099         set_executable_resources(mergecap "Mergecap")
3100         add_executable(mergecap ${mergecap_FILES})
3101         set_extra_executable_properties(mergecap "Executables")
3102         target_link_libraries(mergecap ${mergecap_LIBS})
3103         executable_link_mingw_unicode(mergecap)
3104         install(TARGETS mergecap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
3105 endif()
3106
3107 if(BUILD_reordercap)
3108         set(reordercap_LIBS
3109                 ui
3110                 wiretap
3111                 ${ZLIB_LIBRARIES}
3112                 ${CMAKE_DL_LIBS}
3113         )
3114         set(reordercap_FILES
3115                 $<TARGET_OBJECTS:cli_main>
3116                 reordercap.c
3117         )
3118         set_executable_resources(reordercap "Reordercap")
3119         add_executable(reordercap ${reordercap_FILES})
3120         set_extra_executable_properties(reordercap "Executables")
3121         target_link_libraries(reordercap ${reordercap_LIBS})
3122         executable_link_mingw_unicode(reordercap)
3123         install(TARGETS reordercap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
3124 endif()
3125
3126 if(BUILD_capinfos)
3127         set(capinfos_LIBS
3128                 ui
3129                 wiretap
3130                 wsutil
3131                 ${ZLIB_LIBRARIES}
3132                 ${GCRYPT_LIBRARIES}
3133                 ${CMAKE_DL_LIBS}
3134         )
3135         set(capinfos_FILES
3136                 $<TARGET_OBJECTS:cli_main>
3137                 capinfos.c
3138         )
3139         set_executable_resources(capinfos "Capinfos")
3140         add_executable(capinfos ${capinfos_FILES})
3141         set_extra_executable_properties(capinfos "Executables")
3142         target_link_libraries(capinfos ${capinfos_LIBS})
3143         target_include_directories(capinfos SYSTEM PRIVATE ${GCRYPT_INCLUDE_DIRS})
3144         executable_link_mingw_unicode(capinfos)
3145         install(TARGETS capinfos RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
3146 endif()
3147
3148 if(BUILD_captype)
3149         set(captype_LIBS
3150                 ui
3151                 wiretap
3152                 wsutil
3153                 ${ZLIB_LIBRARIES}
3154                 ${CMAKE_DL_LIBS}
3155         )
3156         set(captype_FILES
3157                 $<TARGET_OBJECTS:cli_main>
3158                 captype.c
3159         )
3160         set_executable_resources(captype "Captype")
3161         add_executable(captype ${captype_FILES})
3162         set_extra_executable_properties(captype "Executables")
3163         target_link_libraries(captype ${captype_LIBS})
3164         executable_link_mingw_unicode(captype)
3165         install(TARGETS captype RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
3166 endif()
3167
3168 if(BUILD_editcap)
3169         set(editcap_LIBS
3170                 ui
3171                 wiretap
3172                 ${ZLIB_LIBRARIES}
3173                 ${GCRYPT_LIBRARIES}
3174                 ${CMAKE_DL_LIBS}
3175         )
3176         set(editcap_FILES
3177                 $<TARGET_OBJECTS:cli_main>
3178                 editcap.c
3179         )
3180         set_executable_resources(editcap "Editcap")
3181         add_executable(editcap ${editcap_FILES})
3182         set_extra_executable_properties(editcap "Executables")
3183         target_link_libraries(editcap ${editcap_LIBS})
3184         target_include_directories(editcap SYSTEM PRIVATE ${GCRYPT_INCLUDE_DIRS})
3185         executable_link_mingw_unicode(editcap)
3186         install(TARGETS editcap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
3187 endif()
3188
3189 if(BUILD_dumpcap AND PCAP_FOUND)
3190         set(dumpcap_LIBS
3191                 writecap
3192                 wsutil_static
3193                 pcap::pcap
3194                 ${CAP_LIBRARIES}
3195                 ${ZLIB_LIBRARIES}
3196                 ${NL_LIBRARIES}
3197                 ${APPLE_CORE_FOUNDATION_LIBRARY}
3198                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
3199                 ${WIN_WS2_32_LIBRARY}
3200         )
3201         if(UNIX)
3202                 list(APPEND CAPUTILS_SRC
3203                         capture/capture-pcap-util-unix.c)
3204         endif()
3205         if(WIN32)
3206                 list(APPEND CAPUTILS_SRC
3207                         capture/capture_win_ifnames.c
3208                         capture/capture-wpcap.c
3209                 )
3210         endif()
3211         list(APPEND CAPUTILS_SRC
3212                 capture/capture-pcap-util.c
3213         )
3214         if (AIRPCAP_FOUND)
3215                 list(APPEND CAPUTILS_SRC capture/airpcap_loader.c)
3216         endif()
3217         set(dumpcap_FILES
3218                 capture_opts.c
3219                 cli_main.c
3220                 dumpcap.c
3221                 ringbuffer.c
3222                 sync_pipe_write.c
3223                 capture/iface_monitor.c
3224                 capture/ws80211_utils.c
3225                 ${CAPUTILS_SRC}
3226         )
3227         set_executable_resources(dumpcap "Dumpcap" UNIQUE_RC)
3228         add_executable(dumpcap ${dumpcap_FILES})
3229         set_extra_executable_properties(dumpcap "Executables")
3230         target_link_libraries(dumpcap ${dumpcap_LIBS})
3231         target_include_directories(dumpcap SYSTEM PRIVATE ${ZLIB_INCLUDE_DIRS} ${NL_INCLUDE_DIRS})
3232         target_compile_definitions(dumpcap PRIVATE ENABLE_STATIC)
3233         executable_link_mingw_unicode(dumpcap)
3234         install(TARGETS dumpcap
3235                         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
3236                         PERMISSIONS ${DUMPCAP_SETUID}
3237                                 OWNER_READ OWNER_WRITE OWNER_EXECUTE
3238                                 GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
3239         )
3240         if(ENABLE_DUMPCAP_GROUP)
3241                 install(CODE "execute_process(COMMAND chgrp ${DUMPCAP_INSTALL_GROUP} ${CMAKE_INSTALL_FULL_BINDIR}/dumpcap)")
3242                 install(CODE "execute_process(COMMAND chmod o-x ${CMAKE_INSTALL_FULL_BINDIR}/dumpcap)")
3243         endif()
3244         if(DUMPCAP_INSTALL_OPTION STREQUAL "capabilities")
3245                 install( CODE "execute_process(
3246                         COMMAND
3247                                 ${SETCAP_EXECUTABLE}
3248                                 cap_net_raw,cap_net_admin+ep
3249                                 ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/dumpcap${CMAKE_EXECUTABLE_SUFFIX}
3250                         RESULT_VARIABLE
3251                                 _SETCAP_RESULT
3252                         )
3253                         if( _SETCAP_RESULT )
3254                                 message( WARNING \"setcap failed (${_SETCAP_RESULT}).\")
3255                         endif()"
3256                 )
3257         endif()
3258         if(BUILD_logray AND ENABLE_APPLICATION_BUNDLE)
3259                 add_custom_command(TARGET dumpcap POST_BUILD
3260                         COMMAND ${CMAKE_COMMAND} -E copy_if_different
3261                                 $<TARGET_FILE:dumpcap> run/Logray.app/Contents/MacOS/dumpcap
3262                 )
3263         endif()
3264 elseif(BUILD_dumpcap AND ENABLE_PCAP)
3265         message(WARNING "Dumpcap was requested but libpcap dependency is not available. "
3266                 "Wireshark will be built without packet capture capability.")
3267 endif()
3268
3269 # We have two idl2wrs utilities: this and the CORBA version in tools.
3270 # We probably shouldn't do that.
3271 if(BUILD_dcerpcidl2wrs)
3272         set(idl2wrs_LIBS
3273                 wsutil
3274         )
3275         set(idl2wrs_FILES
3276                 epan/dissectors/dcerpc/idl2wrs.c
3277         )
3278
3279         add_executable(idl2wrs ${idl2wrs_FILES})
3280         set_target_properties(idl2wrs PROPERTIES FOLDER "Executables")
3281         set_extra_executable_properties(idl2wrs "Executables")
3282         target_link_libraries(idl2wrs ${idl2wrs_LIBS})
3283         install(TARGETS idl2wrs RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
3284 endif()
3285
3286 if(WIN32)
3287         find_package( MSVC_REDIST )
3288
3289         # Must come after executable targets are defined.
3290         find_package( NSIS )
3291
3292         if(MAKENSIS_EXECUTABLE)
3293                 add_subdirectory( packaging/nsis EXCLUDE_FROM_ALL )
3294                 ADD_NSIS_UNINSTALLER_TARGETS()
3295                 ADD_NSIS_PACKAGE_TARGETS()
3296         endif()
3297
3298         find_package( WiX )
3299
3300         if(WIX_CANDLE_EXECUTABLE)
3301                 add_subdirectory( packaging/wix EXCLUDE_FROM_ALL )
3302                 ADD_WIX_PACKAGE_TARGET()
3303         endif()
3304
3305         find_package( PortableApps )
3306         if(PORTABLEAPPS_LAUNCHER_GENERATOR_EXECUTABLE AND PORTABLEAPPS_INSTALLER_EXECUTABLE)
3307                 add_subdirectory( packaging/portableapps EXCLUDE_FROM_ALL )
3308                 ADD_PORTABLEAPPS_PACKAGE_TARGET()
3309         endif()
3310 endif()
3311
3312 if (MAXMINDDB_FOUND)
3313         set(mmdbresolve_LIBS
3314                 # Note: libmaxminddb is not GPL-2 compatible.
3315                 ${MAXMINDDB_LIBRARY}
3316                 # Needed for CMake-built libmaxminddb.lib <= 1.43.
3317                 ${WIN_WS2_32_LIBRARY}
3318         )
3319         set(mmdbresolve_FILES
3320                 mmdbresolve.c
3321         )
3322         set_executable_resources(mmdbresolve "Mmdbresolve")
3323         add_executable(mmdbresolve ${mmdbresolve_FILES})
3324         set_extra_executable_properties(mmdbresolve "Executables")
3325         target_link_libraries(mmdbresolve ${mmdbresolve_LIBS})
3326         target_include_directories(mmdbresolve PUBLIC ${MAXMINDDB_INCLUDE_DIRS})
3327         target_compile_definitions(mmdbresolve PUBLIC ${MAXMINDDB_DEFINITIONS})
3328         install(TARGETS mmdbresolve RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
3329 endif()
3330
3331 if(ENABLE_APPLICATION_BUNDLE AND BUILD_wireshark)
3332         file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/run/${CMAKE_CFG_INTDIR}/Wireshark.app/Contents/Resources/Extras")
3333
3334         # --preserve-xattr is undocumented but ensures that we install
3335         # a signed ChmodBPF script.
3336         set (_chmodbpf_version 1.2)
3337         set (install_chmodbpf_component_pkg "${CMAKE_BINARY_DIR}/install.ChmodBPF.pkg")
3338         add_custom_command(OUTPUT "${install_chmodbpf_component_pkg}"
3339                 COMMAND find
3340                         "${CMAKE_SOURCE_DIR}/packaging/macosx/ChmodBPF/root"
3341                         -type d
3342                         -exec chmod 755 "{}" +
3343                 COMMAND chmod 644
3344                         "${CMAKE_SOURCE_DIR}/packaging/macosx/ChmodBPF/root/Library/LaunchDaemons/org.wireshark.ChmodBPF.plist"
3345                 COMMAND chmod 755
3346                         "${CMAKE_SOURCE_DIR}/packaging/macosx/ChmodBPF/root/Library/Application Support/Wireshark/ChmodBPF/ChmodBPF"
3347                 COMMAND "${CMAKE_SOURCE_DIR}/packaging/macosx/osx-extras.sh"
3348                 COMMAND pkgbuild
3349                         --identifier org.wireshark.ChmodBPF.pkg
3350                         --version ${_chmodbpf_version}
3351                         --preserve-xattr
3352                         --root "${CMAKE_SOURCE_DIR}/packaging/macosx/ChmodBPF/root"
3353                         --scripts "${CMAKE_SOURCE_DIR}/packaging/macosx/ChmodBPF/install-scripts"
3354                         ${install_chmodbpf_component_pkg}
3355                 DEPENDS
3356                         "${CMAKE_SOURCE_DIR}/packaging/macosx/ChmodBPF/root/Library/Application Support/Wireshark/ChmodBPF/ChmodBPF"
3357                         "${CMAKE_SOURCE_DIR}/packaging/macosx/ChmodBPF/root/Library/LaunchDaemons/org.wireshark.ChmodBPF.plist"
3358                         "${CMAKE_SOURCE_DIR}/packaging/macosx/ChmodBPF/install-scripts/postinstall"
3359         )
3360         set (install_chmodbpf_pkg "${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/Resources/Extras/Install ChmodBPF.pkg")
3361         add_custom_command(OUTPUT "${install_chmodbpf_pkg}"
3362                 COMMAND productbuild
3363                         --identifier org.wireshark.install.ChmodBPF.product
3364                         --version ${_chmodbpf_version}
3365                         --distribution "${CMAKE_SOURCE_DIR}/packaging/macosx/ChmodBPF/install-distribution.xml"
3366                         --package-path "${CMAKE_BINARY_DIR}"
3367                         ${install_chmodbpf_pkg}
3368                 DEPENDS
3369                         "${CMAKE_SOURCE_DIR}/packaging/macosx/ChmodBPF/install-distribution.xml"
3370                         ${install_chmodbpf_component_pkg}
3371         )
3372
3373         set (uninstall_chmodbpf_component_pkg "${CMAKE_BINARY_DIR}/uninstall.ChmodBPF.pkg")
3374         add_custom_command(OUTPUT "${uninstall_chmodbpf_component_pkg}"
3375                 COMMAND pkgbuild
3376                         --identifier org.wireshark.uninstall.ChmodBPF.pkg
3377                         --version ${_chmodbpf_version}
3378                         --nopayload
3379                         --scripts "${CMAKE_SOURCE_DIR}/packaging/macosx/ChmodBPF/uninstall-scripts"
3380                         ${uninstall_chmodbpf_component_pkg}
3381                 DEPENDS
3382                         "${CMAKE_SOURCE_DIR}/packaging/macosx/ChmodBPF/uninstall-scripts/postinstall"
3383         )
3384         set (uninstall_chmodbpf_pkg "${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/Resources/Extras/Uninstall ChmodBPF.pkg")
3385         add_custom_command(OUTPUT "${uninstall_chmodbpf_pkg}"
3386                 COMMAND productbuild
3387                         --identifier org.wireshark.uninstall.ChmodBPF.product
3388                         --version ${_chmodbpf_version}
3389                         --distribution "${CMAKE_SOURCE_DIR}/packaging/macosx/ChmodBPF/uninstall-distribution.xml"
3390                         --package-path "${CMAKE_BINARY_DIR}"
3391                         ${uninstall_chmodbpf_pkg}
3392                 DEPENDS
3393                         "${CMAKE_SOURCE_DIR}/packaging/macosx/ChmodBPF/uninstall-distribution.xml"
3394                         ${uninstall_chmodbpf_component_pkg}
3395         )
3396
3397         add_custom_target(chmodbpf DEPENDS ${install_chmodbpf_pkg} ${uninstall_chmodbpf_pkg})
3398
3399         set (_path_helper_version 1.1)
3400         set (install_path_helper_component_pkg "${CMAKE_BINARY_DIR}/install.path_helper.pkg")
3401         add_custom_command(OUTPUT "${install_path_helper_component_pkg}"
3402                 COMMAND find
3403                         "${CMAKE_SOURCE_DIR}/packaging/macosx/path_helper/root"
3404                         -type d
3405                         -exec chmod 755 "{}" +
3406                 COMMAND find
3407                         "${CMAKE_SOURCE_DIR}/packaging/macosx/path_helper/root"
3408                         -type f
3409                         -exec chmod 644 "{}" +
3410                 COMMAND pkgbuild
3411                         --identifier org.wireshark.path_helper.pkg
3412                         --version ${_path_helper_version}
3413                         --root "${CMAKE_SOURCE_DIR}/packaging/macosx/path_helper/root/etc"
3414                         --install-location /private/etc
3415                         ${install_path_helper_component_pkg}
3416                 DEPENDS
3417                         "${CMAKE_SOURCE_DIR}/packaging/macosx/path_helper/root/etc/paths.d/Wireshark"
3418                         "${CMAKE_SOURCE_DIR}/packaging/macosx/path_helper/root/etc/manpaths.d/Wireshark"
3419         )
3420         set (install_path_helper_pkg "${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/Resources/Extras/Add Wireshark to the system path.pkg")
3421         add_custom_command(OUTPUT "${install_path_helper_pkg}"
3422                 COMMAND productbuild
3423                         --identifier org.wireshark.install.path_helper.product
3424                         --version ${_path_helper_version}
3425                         --distribution "${CMAKE_SOURCE_DIR}/packaging/macosx/path_helper/install-distribution.xml"
3426                         --package-path "${CMAKE_BINARY_DIR}"
3427                         ${install_path_helper_pkg}
3428                 DEPENDS
3429                         "${CMAKE_SOURCE_DIR}/packaging/macosx/path_helper/install-distribution.xml"
3430                         ${install_path_helper_component_pkg}
3431         )
3432
3433         set (uninstall_path_helper_component_pkg "${CMAKE_BINARY_DIR}/uninstall.path_helper.pkg")
3434         add_custom_command(OUTPUT "${uninstall_path_helper_component_pkg}"
3435                 COMMAND pkgbuild
3436                         --identifier org.wireshark.uninstall.path_helper.pkg
3437                         --version ${_path_helper_version}
3438                         --nopayload
3439                         --scripts "${CMAKE_SOURCE_DIR}/packaging/macosx/path_helper/uninstall-scripts"
3440                         ${uninstall_path_helper_component_pkg}
3441                 DEPENDS
3442                         "${CMAKE_SOURCE_DIR}/packaging/macosx/path_helper/uninstall-scripts/postinstall"
3443         )
3444         set (uninstall_path_helper_pkg "${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/Resources/Extras/Remove Wireshark from the system path.pkg")
3445         add_custom_command(OUTPUT "${uninstall_path_helper_pkg}"
3446                 COMMAND productbuild
3447                         --identifier org.wireshark.uninstall.path_helper.product
3448                         --version ${_path_helper_version}
3449                         --distribution "${CMAKE_SOURCE_DIR}/packaging/macosx/path_helper/uninstall-distribution.xml"
3450                         --package-path "${CMAKE_BINARY_DIR}"
3451                         ${uninstall_path_helper_pkg}
3452                 DEPENDS
3453                         ${CMAKE_SOURCE_DIR}/packaging/macosx/path_helper/uninstall-distribution.xml
3454                         ${uninstall_path_helper_component_pkg}
3455         )
3456
3457         add_custom_target(path_helper DEPENDS ${install_path_helper_pkg} ${uninstall_path_helper_pkg})
3458
3459         add_custom_target(wireshark_app_bundle)
3460         set_target_properties(wireshark_app_bundle PROPERTIES FOLDER "Copy Tasks")
3461         add_custom_command(TARGET wireshark_app_bundle
3462                 POST_BUILD
3463                 COMMAND "${CMAKE_BINARY_DIR}/packaging/macosx/osx-app.sh"
3464                 WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/run"
3465         )
3466         add_dependencies(wireshark_app_bundle ${PROGLIST} chmodbpf path_helper)
3467
3468         add_custom_target(wireshark_dmg_prep DEPENDS wireshark_app_bundle)
3469
3470         FILE(MAKE_DIRECTORY packaging/macosx/wireshark)
3471
3472         set(_wireshark_read_me_first "packaging/macosx/wireshark/Read me first.html")
3473         ADD_CUSTOM_COMMAND(
3474         OUTPUT
3475                 ${_wireshark_read_me_first}
3476         COMMAND ${ASCIIDOCTOR_EXECUTABLE}
3477                 --backend html
3478                 --out-file ${_wireshark_read_me_first}
3479                 --attribute include-dir=${CMAKE_SOURCE_DIR}/docbook
3480                 --attribute min-macos-version=${MIN_MACOS_VERSION}
3481                 ${CMAKE_CURRENT_SOURCE_DIR}/packaging/macosx/Wireshark_read_me_first.adoc
3482         DEPENDS
3483                 ${CMAKE_CURRENT_SOURCE_DIR}/packaging/macosx/Wireshark_read_me_first.adoc
3484         )
3485
3486         set(_wireshark_donate "packaging/macosx/wireshark/Donate to the Wireshark Foundation.html")
3487         ADD_CUSTOM_COMMAND(
3488         OUTPUT
3489                 ${_wireshark_donate}
3490         COMMAND ${ASCIIDOCTOR_EXECUTABLE}
3491                 --backend html
3492                 --out-file ${_wireshark_donate}
3493                 --attribute include-dir=${CMAKE_SOURCE_DIR}/docbook
3494                 --attribute min-macos-version=${MIN_MACOS_VERSION}
3495                 ${CMAKE_CURRENT_SOURCE_DIR}/packaging/macosx/Donate_to_the_Wireshark_Foundation.adoc
3496         DEPENDS
3497                 ${CMAKE_CURRENT_SOURCE_DIR}/packaging/macosx/Donate_to_the_Wireshark_Foundation.adoc
3498         )
3499
3500         set(_wireshark_dsym_installation "packaging/macosx/wireshark/Debugging symbols installation.html")
3501         ADD_CUSTOM_COMMAND(
3502         OUTPUT
3503                 ${_wireshark_dsym_installation}
3504         COMMAND ${ASCIIDOCTOR_EXECUTABLE}
3505                 --backend html
3506                 --out-file ${_wireshark_dsym_installation}
3507                 --attribute include-dir=${CMAKE_SOURCE_DIR}/docbook
3508                 ${CMAKE_CURRENT_SOURCE_DIR}/packaging/macosx/Wireshark_dsym_installation.adoc
3509         DEPENDS
3510                 ${CMAKE_CURRENT_SOURCE_DIR}/packaging/macosx/Wireshark_dsym_installation.adoc
3511         )
3512
3513         add_custom_target(wireshark_dmg_readmes DEPENDS ${_wireshark_read_me_first} ${_wireshark_donate} ${_wireshark_dsym_installation} )
3514         add_dependencies(wireshark_dmg_prep wireshark_dmg_readmes)
3515
3516         ADD_CUSTOM_TARGET( wireshark_dmg
3517                 COMMAND bash -x ${CMAKE_BINARY_DIR}/packaging/macosx/osx-dmg.sh
3518                 # Unlike wireshark_nsis_prep + wireshark_nsis, we can add a direct
3519                 # dependency here.
3520                 DEPENDS wireshark_dmg_prep
3521                 # We create Wireshark.app in "run". Do our work there.
3522                 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/run
3523         )
3524
3525 endif()
3526
3527 if(ENABLE_APPLICATION_BUNDLE AND BUILD_logray)
3528         add_custom_target(logray_app_bundle)
3529         set_target_properties(logray_app_bundle PROPERTIES FOLDER "Copy Tasks")
3530         add_custom_command(TARGET logray_app_bundle
3531                 POST_BUILD
3532                 COMMAND "${CMAKE_BINARY_DIR}/packaging/macosx/osx-app.sh" --bundle Logray.app
3533                 WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/run"
3534         )
3535
3536         add_custom_target(logray_dmg_prep DEPENDS logray_app_bundle)
3537
3538         FILE(MAKE_DIRECTORY packaging/macosx/logray)
3539
3540         set(_logray_read_me_first "packaging/macosx/logray/Read me first.html")
3541         ADD_CUSTOM_COMMAND(
3542         OUTPUT
3543                 ${_logray_read_me_first}
3544         COMMAND ${ASCIIDOCTOR_EXECUTABLE}
3545                 --backend html
3546                 --out-file ${_logray_read_me_first}
3547                 --attribute include-dir=${CMAKE_SOURCE_DIR}/docbook
3548                 --attribute min-macos-version=${MIN_MACOS_VERSION}
3549                 ${CMAKE_CURRENT_SOURCE_DIR}/packaging/macosx/Logray_read_me_first.adoc
3550         DEPENDS
3551                 ${CMAKE_CURRENT_SOURCE_DIR}/packaging/macosx/Logray_read_me_first.adoc
3552         )
3553
3554         set(_logray_dsym_installation "packaging/macosx/logray/Debugging symbols installation.html")
3555         ADD_CUSTOM_COMMAND(
3556         OUTPUT
3557                 ${_logray_dsym_installation}
3558         COMMAND ${ASCIIDOCTOR_EXECUTABLE}
3559                 --backend html
3560                 --out-file ${_logray_dsym_installation}
3561                 --attribute include-dir=${CMAKE_SOURCE_DIR}/docbook
3562                 ${CMAKE_CURRENT_SOURCE_DIR}/packaging/macosx/Logray_dsym_installation.adoc
3563         DEPENDS
3564                 ${CMAKE_CURRENT_SOURCE_DIR}/packaging/macosx/Logray_dsym_installation.adoc
3565         )
3566
3567         add_custom_target(logray_dmg_readmes DEPENDS ${_logray_read_me_first} ${_logray_dsym_installation} )
3568         add_dependencies(logray_dmg_prep logray_dmg_readmes)
3569
3570         ADD_CUSTOM_TARGET( logray_dmg
3571                 COMMAND bash -x ${CMAKE_BINARY_DIR}/packaging/macosx/osx-dmg.sh --app-name Logray
3572                 # Unlike wireshark_nsis_prep + wireshark_nsis, we can add a direct
3573                 # dependency here.
3574                 DEPENDS logray_dmg_prep
3575                 # We create Wireshark.app in "run". Do our work there.
3576                 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/run
3577         )
3578
3579 endif()
3580
3581 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
3582         find_program(RPMBUILD_EXECUTABLE rpmbuild)
3583         find_program(GIT_EXECUTABLE git)
3584         # Should we add appimaged's monitored directories
3585         # as HINTS?
3586         # https://github.com/AppImage/appimaged
3587         find_program(LINUXDEPLOY_EXECUTABLE NAMES linuxdeploy-x86_64.AppImage linuxdeploy)
3588         find_program(_linuxdeploy_plugin_qt NAMES linuxdeploy-plugin-qt-x86_64.AppImage linuxdeploy-plugin-qt)
3589         find_program(APPIMAGETOOL_EXECUTABLE NAMES appimagetool-x86_64.AppImage
3590  appimagetool)
3591 endif()
3592
3593
3594 string(REPLACE "-" "_" RPM_VERSION "${PROJECT_VERSION}")
3595 configure_file(packaging/rpm/wireshark.spec.in ${CMAKE_BINARY_DIR}/packaging/rpm/SPECS/wireshark.spec)
3596 if(RPMBUILD_EXECUTABLE)
3597         foreach(_rpm_dir BUILD RPMS SOURCES SPECS SRPMS)
3598                 file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/packaging/rpm/${_rpm_dir}")
3599         endforeach()
3600
3601         set(_rpmbuild_with_args)
3602         #
3603         # This is ugly.
3604         #
3605         # At least some versions of rpmbuild define the cmake_build
3606         # macro to run "cmake --build" with the "--verbose" option,
3607         # with no obvious way to easily override that, so, if you
3608         # are doing a build with lots of source files, and with
3609         # lots of compiler options (for example, a log of -W flags),
3610         # you can get a lot of output from rpmbuild.
3611         #
3612         # Wireshark is a program with lots of source files and
3613         # lots of compiler options.
3614         #
3615         # GitLab's shared builders have a limit of 4MB on logs
3616         # from build jobs.
3617         #
3618         # Wireshark uses the shared builders, and can produce
3619         # more than 4MB with the Fedora RPM build; this causes
3620         # the builds to fail.
3621         #
3622         # Forcibly overriding the cmake_build macro with a
3623         # version that lacks the --version file should
3624         # prevent ninja from being run with the -v flag,
3625         # so that it prints the compact output rather
3626         # than the raw command.
3627         #
3628         # We don't do that by default; if the build has the
3629         # FORCE_CMAKE_NINJA_QUIET environment variable set,
3630         # it will add it.
3631         #
3632         if(DEFINED ENV{FORCE_CMAKE_NINJA_NON_VERBOSE})
3633                 #
3634                 # Get the output of a pipeline running
3635                 # "rpmbuild --showrc", to find the settings
3636                 # of all macros, piped to an awk script
3637                 # to extract the value of the cmake_build
3638                 # macro.
3639                 #
3640                 execute_process(
3641                         COMMAND rpmbuild --showrc
3642                         COMMAND awk "/: cmake_build/ { getline; print \$0; exit }"
3643                         OUTPUT_VARIABLE CMAKE_BUILD_VALUE
3644                         OUTPUT_STRIP_TRAILING_WHITESPACE)
3645                 if (CMAKE_BUILD_VALUE MATCHES ".*--verbose.*")
3646                         #
3647                         # OK, the setting contains "--verbose".
3648                         # Rip it out.
3649                         #
3650                         string(REPLACE "--verbose" ""
3651                                 NON_VERBOSE_CMAKE_BUILD_VALUE
3652                                 ${CMAKE_BUILD_VALUE})
3653                         list(APPEND _rpmbuild_with_args --define "cmake_build ${NON_VERBOSE_CMAKE_BUILD_VALUE}")
3654                 endif()
3655         else()
3656                 if(CMAKE_VERBOSE_MAKEFILE)
3657                         list(APPEND _rpmbuild_with_args -v)
3658                 endif()
3659         endif()
3660         if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
3661                 list(APPEND _rpmbuild_with_args --with toolchain_clang)
3662         endif()
3663         if(CMAKE_GENERATOR STREQUAL "Ninja")
3664                 list(APPEND _rpmbuild_with_args --with ninja)
3665         endif()
3666         if(CCACHE_EXECUTABLE)
3667                 list(APPEND _rpmbuild_with_args --with ccache)
3668         endif()
3669         if(NOT BUILD_wireshark)
3670                 list(APPEND _rpmbuild_with_args --without qt5 --without qt6)
3671         elseif(USE_qt6)
3672                 list(APPEND _rpmbuild_with_args --without qt5 --with qt6)
3673         else()
3674                 list(APPEND _rpmbuild_with_args --with qt5 --without qt6)
3675         endif()
3676         if (MAXMINDDB_FOUND)
3677                 list(APPEND _rpmbuild_with_args --with mmdbresolve)
3678         endif()
3679         if (LUA_FOUND)
3680                 list(APPEND _rpmbuild_with_args --with lua)
3681         endif()
3682         if (LZ4_FOUND AND SNAPPY_FOUND)
3683                 list(APPEND _rpmbuild_with_args --with lz4_and_snappy)
3684         endif()
3685         if (SPANDSP_FOUND)
3686                 list(APPEND _rpmbuild_with_args --with spandsp)
3687         endif()
3688         if (BCG729_FOUND)
3689                 list(APPEND _rpmbuild_with_args --with bcg729)
3690         endif()
3691         if (AMRNB_FOUND)
3692                 list(APPEND _rpmbuild_with_args --with amrnb)
3693         endif()
3694         if (ILBC_FOUND)
3695                 list(APPEND _rpmbuild_with_args --with ilbc)
3696         endif()
3697         if (OPUS_FOUND)
3698                 list(APPEND _rpmbuild_with_args --with opus)
3699         endif()
3700         if (LIBXML2_FOUND)
3701                 list(APPEND _rpmbuild_with_args --with libxml2)
3702         endif()
3703         if (NGHTTP2_FOUND)
3704                 list(APPEND _rpmbuild_with_args --with nghttp2)
3705         endif()
3706         if (SYSTEMD_FOUND)
3707                 list(APPEND _rpmbuild_with_args --with sdjournal)
3708         endif()
3709         if (BROTLI_FOUND)
3710                 list(APPEND _rpmbuild_with_args --with brotli)
3711         endif()
3712
3713         execute_process(
3714                 COMMAND ${PYTHON_EXECUTABLE}
3715                         ${CMAKE_SOURCE_DIR}/tools/make-version.py
3716                         ${CMAKE_SOURCE_DIR}
3717         )
3718
3719         add_custom_target(copy-dist
3720                 COMMAND cp ${CMAKE_BINARY_DIR}/wireshark*tar* ${CMAKE_BINARY_DIR}/packaging/rpm/SOURCES/
3721                 DEPENDS dist
3722         )
3723         add_custom_target(wireshark_rpm
3724                 COMMAND ${RPMBUILD_EXECUTABLE}
3725                         --define "_topdir ${CMAKE_BINARY_DIR}/packaging/rpm"
3726                         --define "_prefix ${CMAKE_INSTALL_PREFIX}"
3727                         ${_rpmbuild_with_args}
3728                         -ba SPECS/wireshark.spec
3729                 DEPENDS copy-dist
3730                 WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/packaging/rpm"
3731                 COMMENT "Create a rpm from the current git commit."
3732         )
3733 endif()
3734
3735 if(BUILD_wireshark AND QT_FOUND AND LINUXDEPLOY_EXECUTABLE AND _linuxdeploy_plugin_qt AND APPIMAGETOOL_EXECUTABLE)
3736         configure_file(packaging/appimage/Wireshark-AppRun.in ${CMAKE_BINARY_DIR}/packaging/appimage/Wireshark-AppRun @ONLY)
3737         # Require production builds (/usr + Release).
3738         if (CMAKE_BUILD_TYPE STREQUAL "Release" AND CMAKE_INSTALL_PREFIX STREQUAL "/usr" )
3739                 add_custom_target(wireshark_appimage_prerequisites)
3740                 add_dependencies(wireshark_appimage_prerequisites ${PROGLIST})
3741         else()
3742                 add_custom_target(wireshark_appimage_prerequisites
3743                         COMMAND echo "CMAKE_BUILD_TYPE isn't Release or CMAKE_INSTALL_PREFIX isn't /usr."
3744                         COMMAND false
3745                 )
3746         endif()
3747         set (_wireshark_ai_appdir ${CMAKE_BINARY_DIR}/packaging/appimage/wireshark.appdir)
3748         add_custom_target(wireshark_appimage_appdir
3749                 COMMAND ${CMAKE_COMMAND} -E make_directory ${_wireshark_ai_appdir}
3750                 COMMAND env DESTDIR=${_wireshark_ai_appdir}
3751                         ${CMAKE_COMMAND} --build . --target install
3752                 DEPENDS wireshark_appimage_prerequisites
3753         )
3754         set(_wireshark_appimage_exe_args)
3755         foreach(_prog ${PROGLIST})
3756                 # XXX This needs to be more robust.
3757                 if (${_prog} STREQUAL "dftest" OR ${_prog} STREQUAL "logray")
3758                         continue()
3759                 endif()
3760                 list(APPEND _wireshark_appimage_exe_args --executable=${_wireshark_ai_appdir}/usr/bin/${_prog})
3761         endforeach()
3762         # It looks like linuxdeploy can't handle executables in nonstandard
3763         # locations, so use it to prep our staging directory here and use
3764         # appimagetool to to build the appimage.
3765         add_custom_target(wireshark_appimage_prep
3766                 COMMAND env LD_LIBRARY_PATH=${_wireshark_ai_appdir}/${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} ${LINUXDEPLOY_EXECUTABLE}
3767                         --appdir=${_wireshark_ai_appdir}
3768                         ${_wireshark_appimage_exe_args}
3769                         --desktop-file=${_wireshark_ai_appdir}/usr/share/applications/org.wireshark.Wireshark.desktop
3770                         --icon-file=${CMAKE_SOURCE_DIR}/resources/icons/wsicon256.png
3771                         --custom-apprun=${CMAKE_BINARY_DIR}/packaging/appimage/Wireshark-AppRun
3772                         --plugin=qt
3773                 DEPENDS wireshark_appimage_appdir
3774         )
3775         add_custom_target(wireshark_appimage
3776                 COMMAND env VERSION=${PROJECT_VERSION} ${APPIMAGETOOL_EXECUTABLE} ${_wireshark_ai_appdir}
3777                 DEPENDS wireshark_appimage_prep
3778         )
3779 endif()
3780
3781 if(BUILD_logray AND QT_FOUND AND LINUXDEPLOY_EXECUTABLE AND _linuxdeploy_plugin_qt AND APPIMAGETOOL_EXECUTABLE)
3782         configure_file(packaging/appimage/Logray-AppRun.in ${CMAKE_BINARY_DIR}/packaging/appimage/Logray-AppRun @ONLY)
3783         # Require production builds (/usr + Release).
3784         if (CMAKE_BUILD_TYPE STREQUAL "Release" AND CMAKE_INSTALL_PREFIX STREQUAL "/usr" )
3785                 add_custom_target(logray_appimage_prerequisites)
3786                 add_dependencies(logray_appimage_prerequisites ${PROGLIST})
3787         else()
3788                 add_custom_target(logray_appimage_prerequisites
3789                         COMMAND echo "CMAKE_BUILD_TYPE isn't Release or CMAKE_INSTALL_PREFIX isn't /usr."
3790                         COMMAND false
3791                 )
3792         endif()
3793         set (_logray_ai_appdir ${CMAKE_BINARY_DIR}/packaging/appimage/logray.appdir)
3794         add_custom_target(logray_appimage_appdir
3795                 COMMAND ${CMAKE_COMMAND} -E make_directory ${_logray_ai_appdir}
3796                 COMMAND env DESTDIR=${_logray_ai_appdir}
3797                         ${CMAKE_COMMAND} --build . --target install
3798                 DEPENDS logray_appimage_prerequisites
3799         )
3800         set(_logray_appimage_exe_args)
3801         foreach(_prog ${PROGLIST})
3802                 # XXX This needs to be more robust.
3803                 if (${_prog} STREQUAL "dftest" OR ${_prog} STREQUAL "logray")
3804                         continue()
3805                 endif()
3806                 list(APPEND _logray_appimage_exe_args --executable=${_logray_ai_appdir}/usr/bin/${_prog})
3807         endforeach()
3808         # It looks like linuxdeploy can't handle executables in nonstandard
3809         # locations, so use it to prep our staging directory here and use
3810         # appimagetool to to build the appimage.
3811         add_custom_target(logray_appimage_prep
3812                 COMMAND env LD_LIBRARY_PATH=${_logray_ai_appdir}/${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} ${LINUXDEPLOY_EXECUTABLE}
3813                         --appdir=${_logray_ai_appdir}
3814                         ${_logray_appimage_exe_args}
3815                         --desktop-file=${_logray_ai_appdir}/usr/share/applications/org.wireshark.Logray.desktop
3816                         --icon-file=${CMAKE_SOURCE_DIR}/resources/icons/lricon256.png
3817                         --custom-apprun=${CMAKE_BINARY_DIR}/packaging/appimage/Logray-AppRun
3818                         --plugin=qt
3819                 DEPENDS logray_appimage_appdir
3820         )
3821         add_custom_target(logray_appimage
3822                 COMMAND env VERSION=${LOG_PROJECT_VERSION} ${APPIMAGETOOL_EXECUTABLE} ${_logray_ai_appdir}
3823                 DEPENDS logray_appimage_prep
3824         )
3825 endif()
3826
3827 set(CLEAN_C_FILES
3828         ${dumpcap_FILES}
3829         ${wireshark_FILES}
3830         ${logray_FILES}
3831         ${tshark_FILES}
3832         ${tfshark_FILES}
3833         ${rawshark_FILES}
3834         ${dftest_FILES}
3835         ${randpkt_FILES}
3836         ${randpktdump_FILES}
3837         ${etwdump_FILES}
3838         ${falcodump_FILES}
3839         ${udpdump_FILES}
3840         ${text2pcap_FILES}
3841         ${mergecap_FILES}
3842         ${capinfos_FILES}
3843         ${captype_FILES}
3844         ${editcap_FILES}
3845         ${idl2wrs_FILES}
3846         ${mmdbresolve_FILES}
3847         ${sharkd_FILES}
3848 )
3849
3850 if(CLEAN_C_FILES)
3851         # Make sure we don't pass /WX to rc.exe. Rc doesn't have a /WX flag,
3852         # but it does have /W (warn about invalid code pages) and /X (ignore
3853         # the INCLUDE environment variable).
3854         # This should apparently be handled for us via CMAKE_RC_FLAG_REGEX
3855         # in CMakeRCInformation.cmake but that doesn't appear to work.
3856         if(WIN32)
3857                 list(FILTER CLEAN_C_FILES EXCLUDE REGEX ".*\\.rc")
3858         endif()
3859
3860         # XXX This also contains object files ($<TARGET_OBJECTS:...>), is that an issue?
3861         set_source_files_properties(
3862                 ${CLEAN_C_FILES}
3863                 PROPERTIES
3864                 COMPILE_FLAGS "${WERROR_COMMON_FLAGS}"
3865         )
3866 endif()
3867
3868 install(
3869         FILES
3870                 ${INSTALL_FILES}
3871         PERMISSIONS
3872                 OWNER_WRITE OWNER_READ
3873                 GROUP_READ
3874                 WORLD_READ
3875         DESTINATION
3876                 ${CMAKE_INSTALL_DATADIR}
3877 )
3878
3879 install(
3880         FILES
3881                 ${DOC_FILES}
3882         DESTINATION
3883                 ${CMAKE_INSTALL_DOCDIR}
3884 )
3885
3886 if(ASCIIDOCTOR_FOUND AND XSLTPROC_EXECUTABLE)
3887         install(
3888                 DIRECTORY "${CMAKE_BINARY_DIR}/docbook/wsug_html_chunked"
3889                 DESTINATION "${CMAKE_INSTALL_DOCDIR}"
3890                 COMPONENT "UserGuide"
3891                 EXCLUDE_FROM_ALL
3892         )
3893         install(
3894                 DIRECTORY "${CMAKE_BINARY_DIR}/docbook/wsdg_html_chunked"
3895                 DESTINATION "${CMAKE_INSTALL_DOCDIR}"
3896                 COMPONENT "DeveloperGuide"
3897                 EXCLUDE_FROM_ALL
3898         )
3899 endif()
3900
3901 set(SHARK_PUBLIC_HEADERS
3902         cfile.h
3903         cli_main.h
3904         file.h
3905         include/ws_attributes.h
3906         include/ws_codepoints.h
3907         include/ws_compiler_tests.h
3908         include/ws_diag_control.h
3909         include/ws_exit_codes.h
3910         include/ws_log_defs.h
3911         include/ws_posix_compat.h
3912         include/ws_symbol_export.h
3913         include/wireshark.h
3914         ${CMAKE_BINARY_DIR}/ws_version.h
3915 )
3916
3917 install(FILES ${SHARK_PUBLIC_HEADERS}
3918         DESTINATION ${PROJECT_INSTALL_INCLUDEDIR}
3919         COMPONENT "Development"
3920         EXCLUDE_FROM_ALL
3921 )
3922
3923 # Install icons and other desktop files for Freedesktop.org-compliant desktops.
3924 if(BUILD_wireshark AND QT_FOUND AND NOT APPLE AND (NOT WIN32 OR USE_MSYSTEM))
3925         install(FILES resources/freedesktop/org.wireshark.Wireshark-mime.xml
3926                 DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/mime/packages"
3927                 RENAME org.wireshark.Wireshark.xml
3928         )
3929         install(FILES resources/freedesktop/org.wireshark.Wireshark.metainfo.xml
3930                 DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/metainfo"
3931         )
3932         if(BUILD_wireshark AND QT_FOUND)
3933                 install(FILES resources/freedesktop/org.wireshark.Wireshark.desktop
3934                         DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications")
3935         endif()
3936         foreach(size 16 24 32 48 64 128 256)
3937                 install(FILES resources/icons/wsicon${size}.png
3938                         DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/${size}x${size}/apps"
3939                         RENAME org.wireshark.Wireshark.png)
3940                 install(FILES resources/icons/WiresharkDoc-${size}.png
3941                         DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/${size}x${size}/mimetypes"
3942                         RENAME org.wireshark.Wireshark-mimetype.png)
3943         endforeach()
3944 endif()
3945
3946 if(BUILD_logray AND QT_FOUND AND NOT APPLE AND (NOT WIN32 OR USE_MSYSTEM))
3947         install(FILES resources/freedesktop/org.wireshark.Logray-mime.xml
3948                 DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/mime/packages"
3949                 RENAME org.wireshark.Logray.xml
3950         )
3951         install(FILES resources/freedesktop/org.wireshark.Logray.metainfo.xml
3952                 DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/metainfo"
3953         )
3954         if(BUILD_wireshark AND QT_FOUND)
3955                 install(FILES resources/freedesktop/org.wireshark.Logray.desktop
3956                         DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications")
3957         endif()
3958         foreach(size 16 32 48 64 128 256)
3959                 install(FILES resources/icons/lricon${size}.png
3960                         DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/${size}x${size}/apps"
3961                         RENAME org.wireshark.Logray.png)
3962                 install(FILES resources/icons/WiresharkDoc-${size}.png
3963                         DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/${size}x${size}/mimetypes"
3964                         RENAME org.wireshark.Logray-mimetype.png)
3965         endforeach()
3966         install(FILES resources/icons/lricon.svg
3967                 DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/apps"
3968                 RENAME org.wireshark.Logray.svg)
3969 endif()
3970
3971 install(
3972         FILES
3973                 "${CMAKE_BINARY_DIR}/wireshark.pc"
3974         DESTINATION
3975                 ${CMAKE_INSTALL_LIBDIR}/pkgconfig
3976         COMPONENT
3977                 "Development"
3978         EXCLUDE_FROM_ALL
3979 )
3980
3981 install(
3982         DIRECTORY
3983                 ${INSTALL_DIRS}
3984         DESTINATION
3985                 ${CMAKE_INSTALL_DATADIR}
3986         FILE_PERMISSIONS
3987                 OWNER_WRITE OWNER_READ
3988                 GROUP_READ
3989                 WORLD_READ
3990         DIRECTORY_PERMISSIONS
3991                 OWNER_EXECUTE OWNER_WRITE OWNER_READ
3992                 GROUP_EXECUTE GROUP_READ
3993                 WORLD_EXECUTE WORLD_READ
3994         PATTERN ".git" EXCLUDE
3995         PATTERN ".svn" EXCLUDE
3996         PATTERN "Makefile.*" EXCLUDE
3997 )
3998
3999 if(WIN32 AND NOT USE_MSYSTEM)
4000         # Note: CMake export mechanism misbehaves with a '.' in the
4001         # path (incorrect relative path computation).
4002         set(WIRESHARK_INSTALL_CMAKEDIR "cmake")
4003 else()
4004         set(WIRESHARK_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/cmake")
4005 endif()
4006
4007 include(CMakePackageConfigHelpers)
4008
4009 configure_package_config_file(WiresharkConfig.cmake.in
4010         ${CMAKE_BINARY_DIR}/WiresharkConfig.cmake
4011         INSTALL_DESTINATION ${WIRESHARK_INSTALL_CMAKEDIR}
4012         PATH_VARS
4013                 CMAKE_INSTALL_LIBDIR
4014                 CMAKE_INSTALL_INCLUDEDIR
4015                 PLUGIN_INSTALL_VERSION_LIBDIR
4016                 EXTCAP_INSTALL_LIBDIR
4017 )
4018
4019 write_basic_package_version_file(
4020         ${CMAKE_BINARY_DIR}/WiresharkConfigVersion.cmake
4021         COMPATIBILITY AnyNewerVersion
4022 )
4023
4024 install(
4025         FILES
4026                 ${CMAKE_BINARY_DIR}/WiresharkConfig.cmake
4027                 ${CMAKE_BINARY_DIR}/WiresharkConfigVersion.cmake
4028         DESTINATION
4029                 ${WIRESHARK_INSTALL_CMAKEDIR}
4030         COMPONENT
4031                 "Development"
4032         EXCLUDE_FROM_ALL
4033 )
4034
4035 install(EXPORT WiresharkTargets
4036         DESTINATION ${WIRESHARK_INSTALL_CMAKEDIR}
4037         COMPONENT "Development"
4038         EXCLUDE_FROM_ALL
4039 )
4040
4041 # This isn't strictly needed but it makes working around debhelper's
4042 # cleverness a lot easier.
4043 add_custom_target(install-headers
4044         COMMAND ${CMAKE_COMMAND} -DCOMPONENT=Development -P cmake_install.cmake
4045 )
4046
4047 if (DOXYGEN_EXECUTABLE)
4048         # API reference
4049         # We don't have a good way of tracking dependencies, so we simply
4050         # recreate the whole thing from scratch each time.
4051         add_custom_target(wsar_html
4052                 COMMAND ${CMAKE_COMMAND} -E remove_directory wsar_html
4053                 COMMAND ${DOXYGEN_EXECUTABLE} doxygen.cfg
4054         )
4055
4056         if(WIN32 AND NOT USE_MSYSTEM)
4057                 add_custom_target(wsar_html_perms DEPENDS wsar_html)
4058         else()
4059                 add_custom_target(wsar_html_perms
4060                         COMMAND find wsar_html
4061                                 -type d
4062                                 -exec chmod 755 "{}" +
4063                         COMMAND find wsar_html
4064                                 -type f
4065                                 -exec chmod 644 "{}" +
4066                         DEPENDS wsar_html)
4067         endif()
4068
4069         add_custom_target(wsar_html_zip
4070                 COMMAND ${CMAKE_COMMAND} -E tar "cfv" "wsar_html.zip" --format=zip wsar_html
4071                 DEPENDS wsar_html_perms
4072         )
4073         set_target_properties(wsar_html wsar_html_zip PROPERTIES
4074                 FOLDER "Documentation"
4075                 EXCLUDE_FROM_DEFAULT_BUILD True
4076         )
4077 endif(DOXYGEN_EXECUTABLE)
4078
4079 add_custom_target(test-programs
4080         DEPENDS exntest
4081                 oids_test
4082                 reassemble_test
4083                 tvbtest
4084                 wmem_test
4085                 wscbor_test
4086                 test_epan
4087                 test_wsutil
4088         COMMENT "Building unit test programs and wrapper"
4089 )
4090 set_target_properties(test-programs PROPERTIES
4091         FOLDER "Tests"
4092         EXCLUDE_FROM_DEFAULT_BUILD True
4093 )
4094
4095 # Add target to enable capturing from the build directory. Requires Linux capabilities
4096 # and running with sudo.
4097 if(TARGET dumpcap AND SETCAP_EXECUTABLE)
4098         add_custom_target(test-capture
4099                 COMMAND ${SETCAP_EXECUTABLE} cap_net_raw,cap_net_admin+ep $<TARGET_FILE:dumpcap>
4100         )
4101 endif()
4102
4103 add_custom_target(test
4104         COMMAND ${CMAKE_COMMAND} -E env PYTHONIOENCODING=UTF-8
4105                 ${PYTHON_EXECUTABLE} -m pytest
4106         WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
4107         DEPENDS test-programs
4108         USES_TERMINAL
4109 )
4110
4111 # Make it possible to run pytest without passing the full path as argument.
4112 if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
4113         file(READ "${CMAKE_CURRENT_SOURCE_DIR}/pytest.ini" pytest_ini)
4114         string(REGEX REPLACE "\naddopts = ([^\n]+)"
4115                 "\naddopts = ${CMAKE_CURRENT_SOURCE_DIR}/test \\1"
4116                 pytest_ini "${pytest_ini}")
4117         file(WRITE "${CMAKE_BINARY_DIR}/pytest.ini" "${pytest_ini}")
4118 endif()
4119
4120 if (GIT_EXECUTABLE)
4121         # Update AUTHORS file with entries from git shortlog
4122         add_custom_target(
4123                 gen-authors
4124                 COMMAND ${PYTHON_EXECUTABLE} tools/generate_authors.py AUTHORS
4125                 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
4126         )
4127 else (GIT_EXECUTABLE)
4128         add_custom_target( gen-authors COMMAND ${CMAKE_COMMAND} -E echo "Git not found." )
4129 endif (GIT_EXECUTABLE)
4130 set_target_properties(gen-authors PROPERTIES FOLDER "Documentation")
4131
4132 if(WIN32 AND NOT USE_MSYSTEM)
4133         file (TO_NATIVE_PATH ${CMAKE_SOURCE_DIR}/tools/Get-HardenFlags.ps1 _win_harden_flags)
4134         add_custom_target(hardening-check
4135                 COMMAND ${POWERSHELL_COMMAND} "${_win_harden_flags}" "${_dll_output_dir_win}"
4136                 DEPENDS ${PROGLIST}
4137                 COMMENT "Checking binaries for security features"
4138         )
4139         set_target_properties(hardening-check PROPERTIES FOLDER "Tests")
4140 else()
4141         find_program(HARDENING_CHECK_EXECUTABLE hardening-check
4142                 DOC "Path to the hardening-check utility."
4143         )
4144         if(HARDENING_CHECK_EXECUTABLE)
4145                 foreach(_prog ${PROGLIST})
4146                         get_target_property(_prog_dir ${_prog} RUNTIME_OUTPUT_DIRECTORY)
4147                         if(NOT _prog_dir)
4148                                 set(_prog_dir "${CMAKE_BINARY_DIR}/run")
4149                         endif()
4150                         set(_prog_paths ${_prog_paths} "${_prog_dir}/${_prog}")
4151                 endforeach()
4152                 add_custom_target(hardening-check
4153                         COMMAND ${HARDENING_CHECK_EXECUTABLE} ${_prog_paths}
4154                         DEPENDS ${PROGLIST}
4155                         COMMENT "Checking binaries for security features"
4156                 )
4157         endif()
4158 endif()
4159
4160 CHECKAPI(
4161         NAME
4162           main
4163         SWITCHES
4164         SOURCES
4165           ${WIRESHARK_SRC}
4166           ${TSHARK_TAP_SRC}
4167 )
4168
4169 find_program(SHELLCHECK_EXECUTABLE shellcheck
4170         DOC "Path to the shellcheck utility."
4171 )
4172 if(SHELLCHECK_EXECUTABLE)
4173         add_custom_target(shellcheck)
4174         set_target_properties(shellcheck PROPERTIES FOLDER "Tests")
4175         # --external-sources requires 0.4.0 or later.
4176         # ChmodBPF uses "shellcheck shell=bash". Not sure which version
4177         # added support for that.
4178         add_custom_command(TARGET shellcheck POST_BUILD
4179                 COMMAND shellcheck --external-sources
4180                         resources/stock_icons/svg-to-png.sh
4181                         packaging/appimage/Logray-AppRun.in
4182                         packaging/appimage/Wireshark-AppRun.in
4183                         "packaging/macosx/ChmodBPF/root/Library/Application Support/Wireshark/ChmodBPF/ChmodBPF"
4184                         packaging/macosx/osx-app.sh.in
4185                         packaging/macosx/osx-dmg.sh.in
4186                         packaging/source/git-export-release.sh.in
4187                         tools/debian-setup.sh
4188                         tools/fuzz-test.sh
4189                         tools/gen-bugnote
4190                         tools/pre-commit
4191                         tools/randpkt-test.sh
4192                         tools/release-update-debian-soversions.sh
4193                         tools/test-captures.sh
4194                         tools/update-tx
4195                         tools/valgrind-wireshark.sh
4196                 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
4197         )
4198 endif()
4199
4200 # uninstall target
4201 configure_file(
4202         "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
4203         "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
4204         IMMEDIATE @ONLY)
4205
4206 add_custom_target(uninstall
4207         COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
4208
4209 # Break on programmer errors when debugging in Visual Studio
4210 if(MSVC)
4211         get_property(_targets DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY BUILDSYSTEM_TARGETS)
4212         foreach(_target ${_targets})
4213                 set_target_properties(${_target} PROPERTIES VS_DEBUGGER_ENVIRONMENT "G_DEBUG=fatal-criticals")
4214         endforeach()
4215 endif()
4216
4217 #
4218 # Editor modelines  -  https://www.wireshark.org/tools/modelines.html
4219 #
4220 # Local variables:
4221 # c-basic-offset: 8
4222 # tab-width: 8
4223 # indent-tabs-mode: t
4224 # End:
4225 #
4226 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
4227 # :indentSize=8:tabSize=8:noTabs=false:
4228 #