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