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