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