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