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