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