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