fix for netmon 3.x captures
[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
10 if(WIN32)
11         # Needed for GREATER_EQUAL operator
12         cmake_minimum_required(VERSION 3.7)
13 else()
14         cmake_minimum_required(VERSION 3.5)
15 endif()
16 if(POLICY CMP0083)
17         cmake_policy(SET CMP0083 NEW)
18 endif()
19 project(Wireshark C CXX)
20
21 # Updated by tools/make-version.pl
22 set(GIT_REVISION 0)
23 set(PROJECT_MAJOR_VERSION 2)
24 set(PROJECT_MINOR_VERSION 9)
25 set(PROJECT_PATCH_VERSION 1)
26 set(PROJECT_BUILD_VERSION ${GIT_REVISION})
27 set(PROJECT_VERSION_EXTENSION "")
28 set(PROJECT_RELEASE_VERSION "${PROJECT_MAJOR_VERSION}.${PROJECT_MINOR_VERSION}")
29
30 if(DEFINED ENV{WIRESHARK_VERSION_EXTRA})
31         set(PROJECT_VERSION_EXTENSION "$ENV{WIRESHARK_VERSION_EXTRA}")
32 endif()
33
34 set(PROJECT_VERSION "${PROJECT_MAJOR_VERSION}.${PROJECT_MINOR_VERSION}.${PROJECT_PATCH_VERSION}${PROJECT_VERSION_EXTENSION}")
35
36 # packaging information
37 if(WIN32)
38         set(CPACK_PACKAGE_NAME Wireshark)
39 else()
40         set(CPACK_PACKAGE_NAME wireshark)
41 endif()
42
43 set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
44
45 message(STATUS "Generating build using CMake ${CMAKE_VERSION}")
46
47 #Where to find local cmake scripts
48 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
49
50 # If our target platform is enforced by our generator, set
51 # WIRESHARK_TARGET_PLATFORM accordingly. Otherwise use
52 # %WIRESHARK_TARGET_PLATFORM%.
53
54 if(WIN32)
55         find_package(PowerShell REQUIRED)
56
57         if(CMAKE_CL_64 OR CMAKE_GENERATOR MATCHES "Win64")
58                 set(WIRESHARK_TARGET_PLATFORM win64)
59         elseif(CMAKE_GENERATOR MATCHES "Visual Studio")
60                 set(WIRESHARK_TARGET_PLATFORM win32)
61         else()
62                 set(WIRESHARK_TARGET_PLATFORM $ENV{WIRESHARK_TARGET_PLATFORM})
63         endif()
64
65         if(WIRESHARK_TARGET_PLATFORM MATCHES "win64")
66                 set(WIRESHARK_TARGET_PROCESSOR_ARCHITECTURE amd64)
67         else()
68                 set(WIRESHARK_TARGET_PROCESSOR_ARCHITECTURE x86)
69         endif()
70
71         # Sanity check
72         if(DEFINED ENV{PLATFORM})
73                 string(TOLOWER $ENV{PLATFORM} _vs_platform)
74         else()
75                 set(_vs_platform "[undefined]") # x86
76         endif()
77         if(
78                 (_vs_platform STREQUAL "x64" AND NOT WIRESHARK_TARGET_PLATFORM STREQUAL "win64")
79                 OR
80                 (_vs_platform STREQUAL "[undefined]" AND NOT WIRESHARK_TARGET_PLATFORM STREQUAL "win32")
81         )
82                 message(FATAL_ERROR "The PLATFORM environment variable (${_vs_platform})"
83                         " doesn't match the generator platform (${WIRESHARK_TARGET_PLATFORM})")
84         endif()
85         message(STATUS "Building for ${WIRESHARK_TARGET_PLATFORM} using ${CMAKE_GENERATOR}")
86
87         # Determine where the 3rd party libraries will be
88         if( DEFINED ENV{WIRESHARK_LIB_DIR} )
89                 # The buildbots set WIRESHARK_LIB_DIR but not WIRESHARK_BASE_DIR.
90                 file( TO_CMAKE_PATH "$ENV{WIRESHARK_LIB_DIR}" _PROJECT_LIB_DIR )
91         elseif( DEFINED ENV{WIRESHARK_BASE_DIR} )
92                 file( TO_CMAKE_PATH "$ENV{WIRESHARK_BASE_DIR}" _WS_BASE_DIR )
93                 set( _PROJECT_LIB_DIR "${_WS_BASE_DIR}/wireshark-${WIRESHARK_TARGET_PLATFORM}-libs" )
94         else()
95                 # Don't know what to do
96                 message(FATAL_ERROR "Neither WIRESHARK_BASE_DIR or WIRESHARK_LIB_DIR are defined")
97         endif()
98
99         # Download third-party libraries
100         file (TO_NATIVE_PATH ${CMAKE_SOURCE_DIR}/tools/win-setup.ps1 _win_setup)
101         file (TO_NATIVE_PATH ${_PROJECT_LIB_DIR} _ws_lib_dir)
102
103         # Is it possible to have a one-time, non-cached option in CMake? If
104         # so, we could add a "-DFORCE_WIN_SETUP" which passes -Force to
105         # win-setup.ps1.
106         execute_process(
107                 COMMAND ${POWERSHELL_COMMAND} "\"${_win_setup}\"" -Destination "${_ws_lib_dir}" -Platform ${WIRESHARK_TARGET_PLATFORM}
108                 RESULT_VARIABLE _win_setup_failed
109         )
110         if(_win_setup_failed)
111                 message(FATAL_ERROR "Windows setup (win-setup.ps1) failed.")
112         endif()
113
114         # XXX Add a dependency on ${_ws_lib_dir}/current_tag.txt?
115
116         # Prepopulate some ConfigureChecks values. Compilation checks
117         # on Windows can be slow.
118         set(HAVE_FCNTL_H TRUE)
119         set(HAVE_FLOORL TRUE)
120         set(HAVE_LRINT TRUE)
121
122         # It looks like we call check_type_size somewhere, which checks
123         # for these.
124         set(HAVE_SYS_TYPES_H TRUE)
125         set(HAVE_STDINT_H TRUE)
126         set(HAVE_STDDEF_H TRUE)
127 endif(WIN32)
128
129 include(UseCustomIncludes)
130 ADD_CUSTOM_CMAKE_INCLUDE()
131
132 # This cannot be implemented via option(...)
133 if( NOT CMAKE_BUILD_TYPE )
134         set( CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
135                 "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
136                 FORCE)
137 endif()
138 message(STATUS "Configuration types: ${CMAKE_CONFIGURATION_TYPES}")
139 string(TOUPPER "${CMAKE_BUILD_TYPE}" _build_type)
140 message(STATUS "CMAKE_C_FLAGS_${_build_type}: ${CMAKE_C_FLAGS_${_build_type}}")
141 message(STATUS "CMAKE_CXX_FLAGS_${_build_type}: ${CMAKE_CXX_FLAGS_${_build_type}}")
142
143 # Ensure that all executables and libraries end up in the same directory. Actual
144 # files might end up in a configuration subdirectory, e.g. run/Debug or
145 # run/Release. We try to set DATAFILE_DIR to actual location below.
146 if(NOT ARCHIVE_OUTPUT_PATH)
147         set(ARCHIVE_OUTPUT_PATH ${Wireshark_BINARY_DIR}/run CACHE INTERNAL
148                    "Single output directory for building all archives.")
149 endif()
150 if(NOT EXECUTABLE_OUTPUT_PATH)
151         set(EXECUTABLE_OUTPUT_PATH ${Wireshark_BINARY_DIR}/run CACHE INTERNAL
152                    "Single output directory for building all executables.")
153 endif()
154 if(NOT LIBRARY_OUTPUT_PATH)
155         set(LIBRARY_OUTPUT_PATH ${Wireshark_BINARY_DIR}/run CACHE INTERNAL
156                    "Single output directory for building all libraries.")
157 endif()
158
159 #
160 # The release mode (CMAKE_BUILD_TYPE=release) defines NDEBUG for
161 # the Unix Makefile generator.
162 #
163
164 # Defines CMAKE_INSTALL_BINDIR, CMAKE_INSTALL_DATADIR, etc ...
165 if(WIN32)
166         # Override some values on Windows, to match the existing
167         # convention of installing everything to a single root folder.
168         set(CMAKE_INSTALL_BINDIR ".")
169         set(CMAKE_INSTALL_LIBDIR ".")
170         set(CMAKE_INSTALL_INCLUDEDIR "include")
171         set(CMAKE_INSTALL_DATADIR ".")
172 else()
173         # By default INSTALL_DATADIR is set to INSTALL_DATAROOTDIR, set the
174         # proper value here.
175         set(CMAKE_INSTALL_DATADIR "share/${CPACK_PACKAGE_NAME}"
176                 CACHE PATH "Read-only architecture-independent data"
177         )
178 endif()
179 include(GNUInstallDirs)
180
181 # Make sure our executables can can load our libraries if we install into
182 # a non-default directory on Unix-like systems other than macOS.
183 # https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling
184 if(NOT CMAKE_INSTALL_RPATH AND NOT (WIN32 OR APPLE))
185         # Try to set a RPATH for installed binaries if the library directory is
186         # not already included in the default search list.
187         list(FIND CMAKE_C_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_FULL_LIBDIR}" IS_SYSTEM_DIR)
188         if(IS_SYSTEM_DIR EQUAL -1)
189                 # Some systems support $ORIGIN in RPATH to enable relocatable
190                 # binaries. In other cases, only absolute paths can be used.
191                 # https://www.lekensteyn.nl/rpath.html
192                 if(CMAKE_SYSTEM_NAME MATCHES "^(Linux|SunOS|FreeBSD)$")
193                         set(ENABLE_RPATH_ORIGIN TRUE CACHE BOOL
194                                 "Use $ORIGIN with INSTALL_RPATH")
195                         mark_as_advanced(ENABLE_RPATH_ORIGIN)
196                 else()
197                         set(ENABLE_RPATH_ORIGIN FALSE)
198                 endif()
199                 if(ENABLE_RPATH_ORIGIN)
200                         set(CMAKE_INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")
201                 else()
202                         set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")
203                 endif()
204                 # Include non-standard external libraries by default in RPATH.
205                 if(NOT DEFINED CMAKE_INSTALL_RPATH_USE_LINK_PATH)
206                         set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
207                 endif()
208         endif()
209 endif()
210
211 # Ensure that executables in the build directory always have the same RPATH.
212 # This ensures relocatable binaries and reproducible builds (invariant of the
213 # build directory location). (Requires CMake 3.14)
214 set(CMAKE_BUILD_RPATH_USE_ORIGIN ON)
215
216 if(WIN32)
217     # Linking with wsetargv.obj enables "wildcard expansion" of
218     # command-line arguments.
219     set(WILDCARD_OBJ wsetargv.obj)
220 endif(WIN32)
221
222 # Banner shown at top right of Qt welcome screen.
223 if(DEFINED ENV{WIRESHARK_VERSION_FLAVOR})
224         set(VERSION_FLAVOR "$ENV{WIRESHARK_VERSION_FLAVOR}")
225 else()
226         set(VERSION_FLAVOR "Development Build")
227 endif()
228
229 # These are required in .rc files and manifests
230 set(VERSION_MAJOR ${PROJECT_MAJOR_VERSION})
231 set(VERSION_MINOR ${PROJECT_MINOR_VERSION})
232 set(VERSION_MICRO ${PROJECT_PATCH_VERSION})
233 set(VERSION_BUILD ${PROJECT_BUILD_VERSION})
234 set(RC_VERSION ${PROJECT_MAJOR_VERSION},${PROJECT_MINOR_VERSION},${PROJECT_PATCH_VERSION},${PROJECT_BUILD_VERSION})
235
236 message(STATUS "V: ${PROJECT_VERSION}, MaV: ${PROJECT_MAJOR_VERSION}, MiV: ${PROJECT_MINOR_VERSION}, PL: ${PROJECT_PATCH_VERSION}, EV: ${PROJECT_VERSION_EXTENSION}.")
237
238 include(UseLemon)
239 include(UseMakePluginReg)
240 include(UseMakeTaps)
241 include(UseExecutableResources)
242 include(UseAsn2Wrs)
243
244 # The following snippet has been taken from
245 # https://github.com/USESystemEngineeringBV/cmake-eclipse-helper/wiki/HowToWorkaroundIndexer
246 # The eclipse indexer otherwise assumes __cplusplus=199711L which will lead to broken
247 # lookup tables for the epan libraries
248 # Check if CXX flags have been set to c++11 -> Setup Eclipse Indexer correctly!
249 # Also setup the project slightly different
250 if(CMAKE_EXTRA_GENERATOR MATCHES "Eclipse CDT4")
251         SET(CXX_ENABLED 0)
252         LIST(LENGTH CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS LIST_LEN)
253         if(LIST_LEN GREATER 0)
254                 SET(CXX_ENABLED 1)
255         endif()
256         SET(C_ENABLED 0)
257         LIST(LENGTH CMAKE_EXTRA_GENERATOR_C_SYSTEM_DEFINED_MACROS LIST_LEN)
258         if(LIST_LEN GREATER 0)
259                 SET(C_ENABLED 1)
260         endif()
261         if(C_ENABLED EQUAL 1 AND CXX_ENABLED EQUAL 1)
262                 # Combined project (C and CXX). This will confuse the indexer. For that reason
263                 # we unsert set the __cplusplus variable for the indexer
264                 list(FIND CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS "__cplusplus" GEN_MACRO_INDEX)
265                 if(GEN_MACRO_INDEX GREATER -1)
266                         list(REMOVE_AT CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS ${GEN_MACRO_INDEX})
267                         list(REMOVE_AT CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS ${GEN_MACRO_INDEX})
268                 endif()
269                 SET(CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS ${CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS} CACHE INTERNAL "")
270         elseif((CXX_ENABLED EQUAL 1) AND (CMAKE_CXX_FLAGS MATCHES ".*-std=c\\+\\+11.*"))
271                 #add_definitions (-D__cplusplus=201103L)
272                 # CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS
273                 list(FIND CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS "199711L" GEN_MACRO_INDEX)
274                 if(GEN_MACRO_INDEX GREATER -1)
275                         list(REMOVE_AT CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS ${GEN_MACRO_INDEX})
276                         list(INSERT CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS ${GEN_MACRO_INDEX} "201103L")
277                         SET(CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS ${CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS} CACHE INTERNAL "")
278                 endif()
279         endif()
280 endif()
281
282 include_directories(
283         ${CMAKE_BINARY_DIR}
284         ${CMAKE_SOURCE_DIR}
285 )
286
287 include( CMakeOptions.txt )
288 if( DUMPCAP_INSTALL_OPTION STREQUAL "suid" )
289         set( DUMPCAP_SETUID "SETUID" )
290 else()
291         set( DUMPCAP_SETUID )
292 endif()
293 if( NOT CMAKE_SYSTEM_NAME STREQUAL "Linux" AND
294         DUMPCAP_INSTALL_OPTION STREQUAL "capabilities" )
295         message( WARNING "Capabilities are only supported on Linux" )
296         set( DUMPCAP_INSTALL_OPTION )
297 endif()
298
299 set(OSS_FUZZ OFF CACHE BOOL "Whether building for oss-fuzz")
300 mark_as_advanced(OSS_FUZZ)
301 if(OSS_FUZZ)
302         if(ENABLE_FUZZER)
303                 # In oss-fuzz mode, the fuzzing engine can be afl or libFuzzer.
304                 message(FATAL_ERROR "Cannot force libFuzzer when using oss-fuzz")
305         endif()
306         # Must not depend on external dependencies so statically link all libs.
307         set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
308 endif()
309
310 #
311 # Linking can consume a lot of memory, especially when built with ASAN and
312 # static libraries (like oss-fuzz) or Debug mode. With Ninja, the number of
313 # parallel linker processes is constrained by job parallelism (-j), but this can
314 # be reduced further by setting "job pools" to a lower number.
315 #
316 if(CMAKE_MAKE_PROGRAM MATCHES "ninja" AND OSS_FUZZ)
317         # Assume oss-fuzz linker jobs do not require more than 1.2G per task
318         set(per_job_memory_mb 1200)
319         cmake_host_system_information(RESULT total_memory_mb QUERY TOTAL_PHYSICAL_MEMORY)
320         math(EXPR parallel_link_jobs "${total_memory_mb} / ${per_job_memory_mb}")
321         if(parallel_link_jobs LESS 1)
322                 set(parallel_link_jobs 1)
323         endif()
324         set_property(GLOBAL APPEND PROPERTY JOB_POOLS link_job_pool=${parallel_link_jobs})
325         set(CMAKE_JOB_POOL_LINK link_job_pool)
326         message(STATUS "Ninja job pool size: ${parallel_link_jobs}")
327 endif()
328
329 # Always enable position-independent code when compiling, even for
330 # executables, so you can build position-independent executables.
331 # -pie is added below for non-MSVC, but requires objects to be built with
332 # -fPIC/-fPIE (so set CMAKE_POSITION_INDEPENDENT_CODE to enable that).
333 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
334
335 # Path to our generated executables (or wrapper scripts)
336 if(WIN32)
337         set(WS_PROGRAM_PATH ./run/$<CONFIG>)
338 else()
339         set(WS_PROGRAM_PATH ./run)
340 endif()
341
342 if( CMAKE_C_COMPILER_ID MATCHES "MSVC")
343         if ((MSVC_VERSION LESS "1900") OR (MSVC_VERSION GREATER_EQUAL "2000"))
344                 message(FATAL_ERROR "You are using an unsupported version of MSVC")
345         endif()
346
347         add_definitions(
348                 /DWIN32_LEAN_AND_MEAN
349                 /D_CRT_SECURE_NO_DEPRECATE
350                 # NOMINMAX keeps windows.h from defining "min" and "max" via windef.h.
351                 # This avoids conflicts with the C++ standard library.
352                 /DNOMINMAX
353                 # -DPSAPI_VERSION=1                 Programs that must run on earlier versions of Windows as well as Windows 7 and later
354                 #                                   versions should always call this function as GetProcessMemoryInfo. To ensure correct
355                 #                                   resolution of symbols, add Psapi.lib to the TARGETLIBS macro and compile the program
356                 #                                   with -DPSAPI_VERSION=1.To use run-time dynamic linking, load Psapi.dll.
357                 #                                   http://msdn.microsoft.com/en-us/library/windows/desktop/ms683219(v=vs.85).aspx
358                 # -D_ALLOW_KEYWORD_MACROS           For VS2012 onwards the, C++ STL does not permit macro redefinitions of keywords
359                 #                                   (see http://msdn.microsoft.com/en-us/library/bb531344(v=vs.110).aspx)
360                 #                                   This definition prevents the complaint about the redefinition of inline by WinPCap
361                 #                                   in pcap-stdinc.h when compiling C++ files, e.g. the Qt UI
362                 /DPSAPI_VERSION=1
363                 /D_ALLOW_KEYWORD_MACROS
364         )
365
366         if(NOT WIRESHARK_TARGET_PLATFORM STREQUAL "win64")
367                 add_definitions("/D_BIND_TO_CURRENT_CRT_VERSION=1")
368         endif()
369
370         set(LOCAL_CFLAGS
371                 /MP
372         )
373
374         set(WS_LINK_FLAGS "/LARGEADDRESSAWARE /MANIFEST:NO /INCREMENTAL:NO /RELEASE")
375
376         # To do: Add /external:... See https://blogs.msdn.microsoft.com/vcblog/2017/12/13/broken-warnings-theory/
377         #
378         # /Zo                               Enhanced debugging of optimised code
379         # /utf-8                            Set Source and Executable character sets to UTF-8
380         #                                   VS2015(MSVC14): On by default when /Zi or /Z7 used.
381         # /guard:cf                         Control Flow Guard (compile and link).
382         #                                   See https://msdn.microsoft.com/en-us/library/windows/desktop/mt637065.aspx
383         #                                   Note: This requires CMake 3.9.0 or newer.
384         #                                   https://gitlab.kitware.com/cmake/cmake/commit/f973d49ab9d4c59b93f6dac812a94bb130200836
385         # /Qspectre                         Speculative execution attack mitigation
386         #                                   See https://blogs.msdn.microsoft.com/vcblog/2018/01/15/spectre-mitigations-in-msvc/
387         list(APPEND LOCAL_CFLAGS /Zo /utf-8 /guard:cf)
388         set(WS_LINK_FLAGS "${WS_LINK_FLAGS} /guard:cf")
389         # /Qspectre is not available for VS2015 or older VS2017. Test for its availability.
390         set(WIRESHARK_COMMON_FLAGS /Qspectre)
391
392         if(ENABLE_CODE_ANALYSIS)
393                 list(APPEND LOCAL_CFLAGS /analyze:WX-)
394         endif()
395
396         # Additional compiler warnings to be treated as "Level 3"
397         # when compiling Wireshark sources. (Selected from "level 4" warnings).
398         ## 4295: array is too small to include a terminating null character
399         ## 4189: local variable is initialized but not referenced
400         # Disable warnings about about use of flexible array members:
401         ## 4200: nonstandard extension used : zero-sized array in struct/union
402         list(APPEND LOCAL_CFLAGS /w34295 /w34189 /wd4200)
403
404         # We've matched these to specific compiler versions using the
405         # checks above. There's no need to pass them to check_c_compiler_flag
406         # or check_cxx_compiler_flag, which can be slow.
407         string(REPLACE ";" " " _flags "${LOCAL_CFLAGS}")
408         set(CMAKE_C_FLAGS "${_flags} ${CMAKE_C_FLAGS}")
409         set(CMAKE_CXX_FLAGS "${_flags} ${CMAKE_CXX_FLAGS}")
410
411 else() # ! MSVC
412         if(APPLE)
413                 set(MIN_MACOS_VERSION 10.6) # Arbitrary.
414                 if(CMAKE_OSX_DEPLOYMENT_TARGET)
415                         if(CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS MIN_MACOS_VERSION)
416                                 message(FATAL_ERROR "We don't support building for macOS < ${MIN_MACOS_VERSION}")
417                         endif()
418                         set(MIN_MACOS_VERSION ${CMAKE_OSX_DEPLOYMENT_TARGET})
419                         message(STATUS "Building for Mac OS X/OS X/macOS ${CMAKE_OSX_DEPLOYMENT_TARGET}")
420                 endif()
421         elseif(CMAKE_OSX_DEPLOYMENT_TARGET)
422                 message(FATAL_ERROR "CMAKE_OSX_DEPLOYMENT_TARGET only applies when building for macOS")
423         endif()
424
425         #
426         # Do whatever is necessary to enable as much C99 support as
427         # possible in the C compiler.  Newer versions of compilers
428         # might default to supporting C99, but older versions may
429         # require a special flag.
430         #
431         # We do not want strict C99 support, as we may also want to
432         # use compiler extensions.
433         #
434         # Prior to CMake 3.1, setting CMAKE_C_STANDARD will not have
435         # any effect, so, unless and until we require CMake 3.1 or
436         # later, we have to do it ourselves on pre-3.1 CMake, so we
437         # just do it ourselves on all versions of CMake.
438         #
439         # Note: with CMake 3.1 through 3.5, the only compilers for
440         # which CMake handles CMAKE_C_STANDARD are GCC and Clang.
441         # 3.6 adds support only for Intel C; 3.9 adds support for
442         # PGI C, Sun C, and IBM XL C, and 3.10 adds support for
443         # Cray C and IAR C, but no version of CMake has support for
444         # HP C.  Therefore, even if we use CMAKE_C_STANDARD with
445         # compilers for which CMake supports it, we may still have
446         # to do it ourselves on other compilers.
447         #
448         # In addition, CMake 3.5.2 seems to think that GCC versions
449         # less than 4.4 don't support -std=gnu99, which we need in
450         # order to get support for "for (int i = 0; i < n; i++) ;",
451         # which is another reason not to rely on CMake's CMAKE_C_STANDARD
452         # support.
453         #
454         # See the CMake documentation for the CMAKE_<LANG>_COMPILER_ID
455         # variables for a list of compiler IDs.
456         #
457         # We don't worry about MSVC; it doesn't have such a flag -
458         # either it doesn't support the C99 features we need at all,
459         # or it supports them regardless of the compiler flag.
460         #
461         # XXX - we add the flag for a given compiler to CMAKE_C_FLAGS,
462         # so we test whether it works and add it if we do.  We don't
463         # test whether it's necessary in order to get the C99 features
464         # that we use; if we ever have a user who tries to compile with
465         # a compiler that can't be made to support those features, we
466         # can add a test to make sure we actually *have* C99 support.
467         #
468         if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR
469            CMAKE_C_COMPILER_ID MATCHES "Clang")
470                 #
471                 # We use -std=gnu99 rather than -std=c99 because, for
472                 # some older compilers such as GCC 4.4.7, -std=gnu99
473                 # is required to avoid errors about C99 constructs
474                 # such as "for (int i = 0; i < n; i++) ;".
475                 #
476                 set(CMAKE_C_FLAGS "-std=gnu99 ${CMAKE_C_FLAGS}")
477         elseif(CMAKE_C_COMPILER_ID MATCHES "XL")
478                 #
479                 # We want support for extensions picked up for
480                 # GNU C compatibility, so we use -qlanglvl=extc99.
481                 #
482                 set(CMAKE_C_FLAGS "-qlanglvl=extc99 ${CMAKE_C_FLAGS}")
483         elseif(CMAKE_C_COMPILER_ID MATCHES "HP")
484                 #
485                 # We also need to add -Wp,-H200000 to handle some large
486                 # #defines we have; that flag is not necessary for the
487                 # C++ compiler unless the "legacy" C++ preprocessor is
488                 # being used (+legacy_cpp).  We don't want the legacy
489                 # preprocessor if it's not the default, so we just add
490                 # -Wp,-H200000 to the C flags.  (If there are older
491                 # versions of aC++ that only support the legacy
492                 # preprocessor, and require that we boost the table
493                 # size, we'd have to check whether -Wp,-H200000 is
494                 # supported by the C++ compiler and add it only if it is.)
495                 #
496                 set(CMAKE_C_FLAGS "-AC99 -Wp,-H200000 $WS_CFLAGS ${CMAKE_C_FLAGS}")
497         elseif(CMAKE_C_COMPILER_ID MATCHES "Sun")
498                 #
499                 # We also crank up the warning level.
500                 #
501                 set(CMAKE_C_FLAGS "-xc99 -v ${CMAKE_C_FLAGS}")
502         elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
503                 set(CMAKE_C_FLAGS "-c99 ${CMAKE_C_FLAGS}")
504         endif()
505
506         if(CMAKE_C_COMPILER_ID MATCHES "Clang")
507                 set(WIRESHARK_COMMON_FLAGS ${WIRESHARK_COMMON_FLAGS}
508                         # avoid "argument unused during compilation" warnings
509                         # (for example, when getting the -gsplit-dwarf option or
510                         # when combining -fwrapv with -fno-strict-overflow)
511                         -Qunused-arguments
512                 )
513         else()
514                 set(WIRESHARK_COMMON_FLAGS ${WIRESHARK_COMMON_FLAGS}
515                         -fexcess-precision=fast
516                 )
517         endif()
518
519         list(APPEND WIRESHARK_COMMON_FLAGS
520                 # The following are for C and C++
521                 # -O<X> and -g get set by the CMAKE_BUILD_TYPE
522                 -Wall
523                 -Wextra
524                 -Wendif-labels
525                 -Wpointer-arith
526                 -Wformat-security
527                 -fwrapv
528                 -fno-strict-overflow
529                 -Wvla
530                 -Waddress
531                 -Wattributes
532                 -Wdiv-by-zero
533                 -Wignored-qualifiers
534                 -Wpragmas
535                 -Wno-overlength-strings
536                 -Wno-long-long
537                 -Wheader-guard
538                 -Wcomma
539                 -Wshorten-64-to-32
540         )
541
542         #
543         # Code that may be worth looking into (coding practices)
544         #
545         if((NOT ENABLE_ASAN) AND (NOT ENABLE_TSAN) AND (NOT ENABLE_UBSAN) AND (NOT DISABLE_FRAME_LARGER_THAN_WARNING))
546                 #
547                 # Only do this if none of ASan, TSan, and UBSan are
548                 # enabled; the instrumentation they add increases
549                 # the stack usage - we only care about stack
550                 # usage in normal operation.
551                 #
552                 set(WIRESHARK_COMMON_FLAGS ${WIRESHARK_COMMON_FLAGS}
553                         -Wframe-larger-than=32768
554                 )
555         endif()
556
557         list(APPEND WIRESHARK_C_ONLY_FLAGS
558                 # The following are C only, not C++
559                 -Wc++-compat
560                 -Wunused-const-variable
561                 #
562                 # XXX - some versions of GCC, including the one in at
563                 # least some Xcode versions that come with Mac OS X
564                 # 10.5, complain about variables in function and
565                 # function pointer *declarations* shadowing other
566                 # variables.  The autoconf script checked for that; we
567                 # don't.
568                 -Wshadow
569                 -Wno-pointer-sign
570                 -Wold-style-definition
571                 -Wstrict-prototypes
572                 #
573                 # Some versions of GCC, such as 4.3.2 and 4.4.5,
574                 # generate logical-op warnings when strchr() is given a
575                 # constant string.  The autoconf script checked for that;
576                 # we don't.
577                 #
578                 -Wlogical-op
579                 -Wjump-misses-init
580                 #
581                 # Implicit function declarations are an error in C++ and most
582                 # likely a programming error in C. Turn -Wimplicit-int and
583                 # -Wimplicit-function-declaration into an error by default.
584                 #
585                 -Werror=implicit
586         )
587
588         #
589         # The universal zero initializer (in C: struct s x = { 0 };) for
590         # structures with multiple members is perfectly legal, but some older
591         # compilers warn about it. Silence those older compilers.
592         #
593         if((CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "5.1") OR
594            (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "6.0") OR
595            (CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "10.0"))
596                 if(NOT CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_VERSION VERSION_LESS "4.7")
597                         list(APPEND WIRESHARK_C_ONLY_FLAGS -Wno-missing-field-initializers)
598                 endif()
599                 # Silence warnings for initialization of nested structs like
600                 # struct { struct { int a, b; } s; int c; } v = { 0 };
601                 list(APPEND WIRESHARK_C_ONLY_FLAGS -Wno-missing-braces)
602         endif()
603
604
605         list(APPEND WIRESHARK_CXX_ONLY_FLAGS
606                 -Wextra-semi
607         )
608
609         #
610         # These are not enabled by default, because the warnings they
611         # produce are very hard or impossible to eliminate.
612         #
613         if(ENABLE_EXTRA_COMPILER_WARNINGS)   # This overrides -Werror
614                 list(APPEND WIRESHARK_COMMON_FLAGS
615                         # The following are for C and C++
616                         -Wpedantic
617                         #
618                         # As we use variadic macros, we don't want warnings
619                         # about them, even with -Wpedantic.
620                         #
621                         -Wno-variadic-macros
622                         #
623                         # Various code blocks this one.
624                         #
625                         -Woverflow
626                         -fstrict-overflow -Wstrict-overflow=4
627                         #
628                         # Due to various places where APIs we don't control
629                         # require us to cast away constness, we can probably
630                         # never enable this one with -Werror.
631                         #
632                         -Wcast-qual
633                         #
634                         # Some generated ASN.1 dissectors block this one;
635                         # multiple function declarations for the same
636                         # function are being generated.
637                         #
638                         -Wredundant-decls
639                         #
640                         # Some loops are safe, but it's hard to convince the
641                         # compiler of that.
642                         #
643                         -Wunsafe-loop-optimizations
644                         #
645                         # All the registration functions block these for now.
646                         #
647                         -Wmissing-prototypes
648                         -Wmissing-declarations
649                         #
650                         # A bunch of "that might not work on SPARC" code blocks
651                         # this one for now; some of it is code that *will* work
652                         # on SPARC, such as casts of "struct sockaddr *" to
653                         # "struct sockaddr_in *", which are required by some
654                         # APIs such as getifaddrs().
655                         #
656                         -Wcast-align
657                         #
658                         # Works only with Clang
659                         #
660                         -Wunreachable-code
661                         #
662                         # Works only with Clang but generates a lot of warnings
663                         # (about glib library not using Doxygen)
664                         #
665                         -Wdocumentation
666                         #
667                         # Works only with GCC 7
668                         #
669                         -Wduplicated-branches
670                         #
671                         # No longer supported by El Capitan clang on C++
672                         # XXX - is this one of those where CMake's check
673                         # doesn't fail, so it won't reject this?
674                         #
675                         -fno-delete-null-pointer-checks
676                 )
677
678                 list(APPEND WIRESHARK_C_ONLY_FLAGS
679                         # The following are C only, not C++
680                         #
681                         # Due to various places where APIs we don't control
682                         # require us to cast away constness, we can probably
683                         # never enable this one with -Werror.
684                         #
685                         -Wbad-function-cast
686                 )
687
688                 list(APPEND WIRESHARK_CXX_ONLY_FLAGS
689                 )
690         endif()
691
692         add_definitions(
693                 -DG_DISABLE_DEPRECATED
694                 -DG_DISABLE_SINGLE_INCLUDES
695         )
696
697         set(WIRESHARK_LD_FLAGS
698                 # See also CheckCLinkerFlag.cmake
699                 -Wl,--as-needed
700                 # -flto
701                 # -fwhopr
702                 # -fwhole-program
703         )
704 endif() # ! MSVC
705
706 # Counterhack to work around some cache magic in CHECK_C_SOURCE_COMPILES
707 include(CheckCCompilerFlag)
708 include(CheckCXXCompilerFlag)
709
710 if(ENABLE_STATIC)
711         set(BUILD_SHARED_LIBS 0)
712 else()
713         set(BUILD_SHARED_LIBS 1)
714 endif()
715
716 function(test_compiler_flag _lang _this_flag _valid_flags_var)
717         string(MAKE_C_IDENTIFIER "${_lang}${_this_flag}_VALID" _flag_var)
718         set(_test_flags "${${_valid_flags_var}} ${_this_flag}")
719         if(_lang STREQUAL "C")
720                 check_c_compiler_flag("${_test_flags}" ${_flag_var})
721         elseif(_lang STREQUAL "CXX")
722                 check_cxx_compiler_flag("${_test_flags}" ${_flag_var})
723         else()
724                 message(FATAL_ERROR "Language must be C or CXX")
725         endif()
726         if (${_flag_var})
727                 set(${_valid_flags_var} "${_test_flags}" PARENT_SCOPE)
728         endif()
729 endfunction()
730
731 foreach(THIS_FLAG ${WIRESHARK_COMMON_FLAGS} ${WIRESHARK_C_ONLY_FLAGS})
732         test_compiler_flag(C ${THIS_FLAG} ADDED_CMAKE_C_FLAGS)
733 endforeach()
734 set(CMAKE_C_FLAGS "${ADDED_CMAKE_C_FLAGS} ${CMAKE_C_FLAGS}")
735
736 foreach(THIS_FLAG ${WIRESHARK_COMMON_FLAGS} ${WIRESHARK_CXX_ONLY_FLAGS})
737         test_compiler_flag(CXX ${THIS_FLAG} ADDED_CMAKE_CXX_FLAGS)
738 endforeach()
739 set(CMAKE_CXX_FLAGS "${ADDED_CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS}")
740
741 include(CMakePushCheckState)
742
743 if(ENABLE_ASAN)
744         cmake_push_check_state()
745         set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=address")
746         check_c_compiler_flag(-fsanitize=address C__fsanitize_address_VALID)
747         check_cxx_compiler_flag(-fsanitize=address CXX__fsanitize_address_VALID)
748         cmake_pop_check_state()
749         if(NOT C__fsanitize_address_VALID OR NOT CXX__fsanitize_address_VALID)
750                 message(FATAL_ERROR "ENABLE_ASAN was requested, but not supported!")
751         endif()
752         set(CMAKE_C_FLAGS "-fsanitize=address ${CMAKE_C_FLAGS}")
753         set(CMAKE_CXX_FLAGS "-fsanitize=address ${CMAKE_CXX_FLAGS}")
754         # Disable ASAN for build-time tools, e.g. lemon
755         check_c_compiler_flag(-fno-sanitize=all C__fno_sanitize_all_VALID)
756         if(C__fno_sanitize_all_VALID)
757                 set(NO_SANITIZE_CFLAGS "-fno-sanitize=all")
758                 set(NO_SANITIZE_LDFLAGS "-fno-sanitize=all")
759         endif()
760 endif()
761
762 if(ENABLE_TSAN)
763         # Available since Clang >= 3.2 and GCC >= 4.8
764         cmake_push_check_state()
765         set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=thread")
766         check_c_compiler_flag(-fsanitize=thread C__fsanitize_thread_VALID)
767         check_cxx_compiler_flag(-fsanitize=thread CXX__fsanitize_thread_VALID)
768         cmake_pop_check_state()
769         if(NOT C__fsanitize_thread_VALID OR NOT CXX__fsanitize_thread_VALID)
770                 message(FATAL_ERROR "ENABLE_TSAN was requested, but not supported!")
771         endif()
772         set(CMAKE_C_FLAGS "-fsanitize=thread ${CMAKE_C_FLAGS}")
773         set(CMAKE_CXX_FLAGS "-fsanitize=thread ${CMAKE_CXX_FLAGS}")
774         set(WS_LINK_FLAGS "-fsanitize=thread ${WS_LINK_FLAGS}")
775 endif()
776
777 if(ENABLE_UBSAN)
778         # Available since Clang >= 3.3 and GCC >= 4.9
779         cmake_push_check_state()
780         set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=undefined")
781         check_c_compiler_flag(-fsanitize=undefined C__fsanitize_undefined_VALID)
782         check_cxx_compiler_flag(-fsanitize=undefined CXX__fsanitize_undefined_VALID)
783         cmake_pop_check_state()
784         if(NOT C__fsanitize_undefined_VALID OR NOT CXX__fsanitize_undefined_VALID)
785                 message(FATAL_ERROR "ENABLE_UBSAN was requested, but not supported!")
786         endif()
787         set(CMAKE_C_FLAGS "-fsanitize=undefined ${CMAKE_C_FLAGS}")
788         set(CMAKE_CXX_FLAGS "-fsanitize=undefined ${CMAKE_CXX_FLAGS}")
789 endif()
790
791 if(ENABLE_FUZZER)
792         # Available since Clang >= 6
793         # Will enable coverage flags which can be used by the fuzzshark target.
794         cmake_push_check_state()
795         set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=fuzzer-no-link")
796         check_c_compiler_flag(-fsanitize=fuzzer C__fsanitize_fuzzer_no_link_VALID)
797         check_cxx_compiler_flag(-fsanitize=fuzzer CXX__fsanitize_fuzzer_no_link_VALID)
798         cmake_pop_check_state()
799         if(NOT C__fsanitize_fuzzer_no_link_VALID OR NOT CXX__fsanitize_fuzzer_no_link_VALID)
800                 message(FATAL_ERROR "ENABLE_FUZZER was requested, but not supported!")
801         endif()
802         set(CMAKE_C_FLAGS "-fsanitize=fuzzer-no-link ${CMAKE_C_FLAGS}")
803         set(CMAKE_CXX_FLAGS "-fsanitize=fuzzer-no-link ${CMAKE_CXX_FLAGS}")
804 endif()
805
806 set(WERROR_COMMON_FLAGS "")
807 if(NOT DISABLE_WERROR AND NOT ENABLE_EXTRA_COMPILER_WARNINGS)
808         if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
809                 set(WERROR_COMMON_FLAGS "/WX")
810         else()
811                 #
812                 # If a warning has been enabled by -Wall or -W,
813                 # and have specified -Werror, there appears to be
814                 # no way, in Apple's llvm-gcc, to prevent that
815                 # particular warning from giving an error - not
816                 # with a pragma, not with -Wno-{warning}, and not
817                 # with -Wno-error={warning}.
818                 #
819                 # Therefore, with that compiler, we just disable
820                 # -Werror.
821                 #
822                 if ((NOT APPLE) OR CMAKE_C_COMPILER_ID MATCHES "Clang")
823                         check_c_compiler_flag(-Werror WERROR)
824                         if (WERROR)
825                                 set(WERROR_COMMON_FLAGS "-Werror")
826                         endif()
827                 endif()
828         endif()
829 endif()
830
831 #
832 # Try to have the compiler default to hiding symbols, so that only
833 # symbols explicitly exported with WS_DLL_PUBLIC will be visible
834 # outside (shared) libraries; that way, more UN*X builds will catch
835 # failures to export symbols, rather than having that fail only on
836 # Windows.
837 #
838 # We don't need that with MSVC, as that's the default.
839 #
840 if( NOT CMAKE_C_COMPILER_ID MATCHES "MSVC")
841         #
842         # Try the GCC-and-compatible -fvisibility-hidden first.
843         #
844         check_c_compiler_flag(-fvisibility=hidden FVHIDDEN)
845         if(FVHIDDEN)
846                 set(CMAKE_C_FLAGS "-fvisibility=hidden ${CMAKE_C_FLAGS}")
847         else()
848                 #
849                 # OK, try the Sun^WOracle C -xldscope=hidden
850                 #
851                 check_c_compiler_flag(-xldscope=hidden XLDSCOPEHIDDEN)
852                 if(XLDSCOPEHIDDEN)
853                         set(CMAKE_C_FLAGS "-xldscope=hidden ${CMAKE_C_FLAGS}")
854                 else()
855                         #
856                         # Anything else?
857                         # If there is anything else, we might want to
858                         # make a list of options to try, and try them
859                         # in a loop.
860                         #
861                         message(WARNING "Hiding shared library symbols is not supported by the compiler."
862                                 " All shared library symbols will be exported.")
863                 endif()
864         endif()
865 endif()
866
867 include(CheckCLinkerFlag)
868
869 if(NOT CMAKE_C_COMPILER_ID MATCHES "MSVC" AND NOT OSS_FUZZ)
870         #
871         # The -pie linker option produces a position-independent executable.
872         # Some Linux distributions have this enabled by default in the compiler,
873         # so setting it here will be superfluous though.
874         #
875         # Note that linking with static libraries that are not position
876         # independent may fail, the user can set CMAKE_EXE_LINKER_FLAGS=-no-pie
877         # as a workaround.
878         #
879         if(CMAKE_VERSION VERSION_GREATER "3.13.999")
880                 include(CheckPIESupported)
881                 check_pie_supported()
882         else()
883                 check_c_linker_flag(-pie LINK_pie_VALID)
884                 if(LINK_pie_VALID)
885                         set(CMAKE_EXE_LINKER_FLAGS "-pie ${CMAKE_EXE_LINKER_FLAGS}")
886                 endif()
887         endif()
888 endif()
889
890 foreach(THIS_FLAG ${WIRESHARK_LD_FLAGS})
891         string(MAKE_C_IDENTIFIER "LINK${THIS_FLAG}_VALID" _flag_var)
892         check_c_linker_flag(${THIS_FLAG} ${_flag_var})
893         if (${_flag_var})
894                 set(WS_LINK_FLAGS "${WS_LINK_FLAGS} ${THIS_FLAG}")
895         endif()
896 endforeach()
897 message(STATUS "Linker flags: ${WS_LINK_FLAGS}")
898
899 if(APPLE AND EXISTS /usr/local/opt/gettext)
900         # GLib on macOS requires libintl. Homebrew installs gettext (and
901         # libintl) in /usr/local/opt/gettext
902         include_directories(/usr/local/opt/gettext/include)
903         link_directories(/usr/local/opt/gettext/lib)
904 endif()
905
906 # ws_find_package(<PackageName>
907 #             <CMakeOptions.txt boolean variable>
908 #             <cmakeconfig.h.in macro definition>
909 #             [remaining find_package() arguments])
910 macro(ws_find_package _package_name _enable_package _package_cmakedefine)
911         if(${_enable_package})
912                 find_package(${_package_name} ${ARGN})
913                 if(${_package_name}_FOUND)
914                         set(${_package_cmakedefine} 1)
915                 endif()
916         endif()
917 endmacro()
918
919 # The minimum package list
920 find_package(Git)
921 set(GLIB2_MIN_VERSION 2.32.0)
922 find_package(GLIB2 REQUIRED)
923 include_directories(SYSTEM ${GLIB2_INCLUDE_DIRS})
924 find_package(GMODULE2)
925 find_package(GTHREAD2 REQUIRED)
926 find_package(GCRYPT "1.4.2" REQUIRED)
927 find_package(LEX REQUIRED)
928 find_package(YACC REQUIRED)
929 find_package(Perl REQUIRED)
930
931 if(CMAKE_VERSION VERSION_LESS "3.12")
932         # Locate the Python interpreter. Finds the wrong (Python 2) version if:
933         # - PATH contains python3.6, but not python3 (3.4). Affects RHEL7+EPEL.
934         # - Path contains C:\Python27 but not C:\Python37 (which is installed,
935         #   but not present in PATH).
936         find_package(PythonInterp 3.4 REQUIRED)
937 else()
938         find_package(Python3 3.4 REQUIRED)
939         # Several files (including LocatePythonModule) still use the old name
940         # from FindPythonInterp, let's stick to it for now.
941         set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
942 endif()
943
944 if (NOT WIN32)
945         find_package(Gettext)
946         find_package(M REQUIRED)
947 endif()
948
949 if(BUILD_sshdump OR BUILD_ciscodump)
950         set(ENABLE_LIBSSH ON)
951 else()
952         set(ENABLE_LIBSSH OFF)
953 endif()
954 ws_find_package(LIBSSH ENABLE_LIBSSH HAVE_LIBSSH "0.6")
955
956 ws_find_package(PCAP ENABLE_PCAP HAVE_LIBPCAP)
957 ws_find_package(AIRPCAP ENABLE_AIRPCAP HAVE_AIRPCAP)
958 ws_find_package(Systemd BUILD_sdjournal HAVE_SYSTEMD)
959
960 # Build the Qt GUI?
961 if(BUILD_wireshark)
962         # Untested, may not work if CMAKE_PREFIX_PATH gets overwritten
963         # somewhere. The if WIN32 in this place is annoying as well.
964         if(WIN32)
965                 set(QT5_BASE_PATH "$ENV{QT5_BASE_DIR}")
966                 set(CMAKE_PREFIX_PATH "${QT5_BASE_PATH}")
967         endif()
968         if(APPLE AND EXISTS /usr/local/opt/qt5)
969                 # Homebrew installs Qt5 (up to at least 5.11.0) in
970                 # /usr/local/qt5. Ensure that it can be found by CMake
971                 # since it is not in the default /usr/local prefix.
972                 # Add it to PATHS so that it doesn't override the
973                 # CMAKE_PREFIX_PATH environment variable.
974                 # QT_FIND_PACKAGE_OPTIONS should be passed to find_package,
975                 # e.g. find_package(Qt5Core ${QT_FIND_PACKAGE_OPTIONS})
976                 list(APPEND QT_FIND_PACKAGE_OPTIONS PATHS /usr/local/opt/qt5)
977         endif()
978         set(QT_PACKAGELIST
979                 Qt5Core
980                 Qt5LinguistTools
981                 Qt5Multimedia
982                 Qt5PrintSupport
983                 Qt5Svg
984                 Qt5Widgets
985         )
986         if(APPLE)
987                 list(APPEND QT_PACKAGELIST Qt5MacExtras)
988         endif()
989         if(WIN32)
990                 list(APPEND QT_PACKAGELIST Qt5WinExtras)
991         endif()
992         foreach(_qt_package IN LISTS QT_PACKAGELIST)
993                 find_package(${_qt_package} REQUIRED ${QT_FIND_PACKAGE_OPTIONS})
994                 list(APPEND QT_LIBRARIES ${${_qt_package}_LIBRARIES})
995                 list(APPEND QT_INCLUDE_DIRS ${${_qt_package}_INCLUDE_DIRS})
996                 list(APPEND QT_COMPILE_DEFINITIONS ${${_qt_package}_COMPILE_DEFINITIONS})
997         endforeach()
998         set(QT_FOUND ON)
999         if(Qt5MacExtras_FOUND)
1000                 set(QT_MACEXTRAS_LIB 1)
1001         endif()
1002 endif()
1003
1004 # MaxMind DB address resolution
1005 ws_find_package(MaxMindDB BUILD_mmdbresolve HAVE_MAXMINDDB)
1006
1007 # SMI SNMP
1008 ws_find_package(SMI ENABLE_SMI HAVE_LIBSMI)
1009
1010 # Support for TLS decryption using RSA private keys.
1011 ws_find_package(GNUTLS ENABLE_GNUTLS HAVE_LIBGNUTLS "3.2.0")
1012
1013 # Kerberos
1014 ws_find_package(KERBEROS ENABLE_KERBEROS HAVE_KERBEROS)
1015
1016 # C Asynchronous resolver
1017 ws_find_package(CARES ENABLE_CARES HAVE_C_ARES "1.5.0")
1018 if(NOT CARES_FOUND)
1019         message(WARNING "Not using c-ares.")
1020         message(WARNING "DNS name resolution for captures will be disabled.")
1021 endif()
1022
1023 # Zlib compression
1024 if(ENABLE_ZLIB)
1025         if (WIN32)
1026                 # On Windows we build our own version of zlib, so add the paths
1027                 set(ZLIB_SRC_DIR "${_PROJECT_LIB_DIR}/zlib-1.2.11-2-ws")
1028                 set(SKIP_INSTALL_STATIC True)
1029                 set(SKIP_INSTALL_HEADERS True)
1030                 set(SKIP_INSTALL_FILES True)
1031                 set(ZLIB_EXPORTS "WiresharkTargets")
1032                 add_subdirectory("${ZLIB_SRC_DIR}" "${CMAKE_BINARY_DIR}/zlib")
1033                 unset(SKIP_INSTALL_STATIC)
1034                 unset(SKIP_INSTALL_HEADERS)
1035                 unset(SKIP_INSTALL_FILES)
1036                 set(ZLIB_INCLUDE_DIR  "${ZLIB_SRC_DIR}" "${CMAKE_BINARY_DIR}/zlib")
1037                 set(ZLIB_LIBRARY zlib)
1038                 set(ZLIB_DLL "zlib1.dll")
1039                 set_target_properties(zlib PROPERTIES FOLDER "Libs/zlib")
1040                 # Annoyingly zlib also builds some other stuff we aren't interested in
1041                 set_target_properties(zlibstatic PROPERTIES
1042                         FOLDER "Libs/zlib"
1043                         EXCLUDE_FROM_ALL True
1044                         EXCLUDE_FROM_DEFAULT_BUILD True
1045                 )
1046         endif()
1047         ws_find_package(ZLIB ENABLE_ZLIB HAVE_ZLIB)
1048 endif()
1049
1050 # LZ4 compression
1051 ws_find_package(LZ4 ENABLE_LZ4 HAVE_LZ4)
1052
1053 # Snappy compression
1054 ws_find_package(SNAPPY ENABLE_SNAPPY HAVE_SNAPPY)
1055
1056 # Enhanced HTTP/2 dissection
1057 ws_find_package(NGHTTP2 ENABLE_NGHTTP2 HAVE_NGHTTP2)
1058
1059 # Embedded Lua interpreter
1060 ws_find_package(LUA ENABLE_LUA HAVE_LUA "5.1")
1061
1062 ws_find_package(NL ENABLE_NETLINK HAVE_LIBNL)
1063
1064 ws_find_package(SBC ENABLE_SBC HAVE_SBC)
1065
1066 ws_find_package(SPANDSP ENABLE_SPANDSP HAVE_SPANDSP)
1067
1068 ws_find_package(BCG729 ENABLE_BCG729 HAVE_BCG729)
1069
1070 ws_find_package(LibXml2 ENABLE_LIBXML2 HAVE_LIBXML2)
1071 if(NOT LIBXML2_FOUND)
1072         # The (official) FindLibXml2.cmake file sets this cache variable to a
1073         # non-empty value, be sure to clear it when not found.
1074         set(LIBXML2_LIBRARIES "")
1075 endif()
1076
1077 # Capabilities
1078 ws_find_package(CAP ENABLE_CAP HAVE_LIBCAP)
1079 if(NOT WIN32)
1080         find_package(SETCAP)
1081 endif()
1082
1083 # Windows version updates
1084 ws_find_package(WINSPARKLE ENABLE_WINSPARKLE HAVE_SOFTWARE_UPDATE)
1085
1086 find_package(POD)
1087
1088 find_package(DOXYGEN)
1089
1090 # dist target that prepares source dir
1091 # XXX Duplicated in the RPM section below.
1092 add_custom_target(dist
1093         COMMAND ${CMAKE_BINARY_DIR}/packaging/source/git-export-release.sh -d "${CMAKE_BINARY_DIR}"
1094         WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
1095 )
1096
1097 if(GNUTLS_FOUND AND NOT GNUTLS_VERSION VERSION_LESS "3.4.0")
1098         # While all Linux and Windows builds have PKCS #11 support enabled,
1099         # macos-setup.sh explicitly disables it using --without-p11-kit.
1100         #
1101         # Require at least GnuTLS 3.4.0 such that public keys can be calculated
1102         # from PKCS #11 private keys.
1103         include(CheckSymbolExists)
1104         cmake_push_check_state()
1105         if(WIN32)
1106                 set(CMAKE_REQUIRED_DEFINITIONS -Dssize_t=int)
1107         endif()
1108         set(CMAKE_REQUIRED_INCLUDES ${GNUTLS_INCLUDE_DIRS})
1109         set(CMAKE_REQUIRED_LIBRARIES ${GNUTLS_LIBRARIES})
1110         check_symbol_exists(gnutls_pkcs11_obj_list_import_url4 gnutls/pkcs11.h HAVE_GNUTLS_PKCS11)
1111         cmake_pop_check_state()
1112 endif()
1113
1114 if (QT_FOUND)
1115         if (Qt5Widgets_VERSION VERSION_LESS 5.2)
1116                 message(FATAL_ERROR "Qt 5.2 or later is required.")
1117         endif()
1118         if (Qt5Widgets_VERSION VERSION_GREATER 5.6
1119             AND (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang"))
1120                 # Qt 5.7 and later require C++ 11.
1121                 set(CMAKE_CXX_STANDARD 11)
1122                 set(CMAKE_CXX_STANDARD_REQUIRED ON)
1123         endif()
1124         if(NOT DEFINED MOC_OPTIONS)
1125                 # Squelch moc verbose "nothing to do" output
1126                 set(MOC_OPTIONS -nn)
1127         endif()
1128
1129         # CMake uses qmake to find Qt4. It relies on Qt's CMake modules
1130         # to find Qt5. This means that we can't assume that the qmake
1131         # in our PATH is the correct one. We can fetch qmake's location
1132         # from Qt5::qmake, which is is defined in Qt5CoreConfigExtras.cmake.
1133         get_target_property(QT_QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION)
1134         get_filename_component(_qt_bin_path "${QT_QMAKE_EXECUTABLE}" DIRECTORY)
1135         set(QT_BIN_PATH "${_qt_bin_path}" CACHE INTERNAL
1136                 "Path to qmake, macdeployqt, windeployqt, and other Qt utilities."
1137         )
1138         # Use qmake to find windeployqt and macdeployqt. Ideally one of
1139         # the modules in ${QTDIR}/lib/cmake would do this for us.
1140         if(WIN32)
1141                 find_program(QT_WINDEPLOYQT_EXECUTABLE windeployqt
1142                         HINTS "${QT_BIN_PATH}"
1143                         DOC "Path to the windeployqt utility."
1144                 )
1145         elseif(APPLE)
1146                 find_program(QT_MACDEPLOYQT_EXECUTABLE macdeployqt
1147                         HINTS "${QT_BIN_PATH}"
1148                         DOC "Path to the macdeployqt utility."
1149                 )
1150                 # https://doc.qt.io/qt-5.11/supported-platforms-and-configurations.html
1151                 # CMake < 3.7 doesn't support VERSION_GREATER_EQUAL.
1152                 if(Qt5Widgets_VERSION VERSION_GREATER "5.11.999")
1153                         set(MIN_MACOS_VERSION 10.12)
1154                 elseif(Qt5Widgets_VERSION VERSION_GREATER "5.9.999")
1155                         set(MIN_MACOS_VERSION 10.11)
1156                 elseif(Qt5Widgets_VERSION VERSION_GREATER "5.8.999")
1157                         set(MIN_MACOS_VERSION 10.10)
1158                 elseif(Qt5Widgets_VERSION VERSION_GREATER "5.7.999")
1159                         set(MIN_MACOS_VERSION 10.9)
1160                 elseif(Qt5Widgets_VERSION VERSION_GREATER "5.4.999")
1161                         set(MIN_MACOS_VERSION 10.8)
1162                 endif()
1163                 if(CMAKE_OSX_DEPLOYMENT_TARGET AND CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS MIN_MACOS_VERSION)
1164                         message(FATAL_ERROR "Qt version ${Qt5Widgets_VERSION} requires CMAKE_OSX_DEPLOYMENT_TARGET (${CMAKE_OSX_DEPLOYMENT_TARGET}) >= ${MIN_MACOS_VERSION}")
1165                 endif()
1166         endif()
1167
1168 endif()
1169
1170 if(ENABLE_CHECKHF_CONFLICT)
1171         set(ENABLE_CHECK_FILTER 1)
1172 endif()
1173
1174 #
1175 # Platform-specific additional libraries.
1176 #
1177 if(WIN32)
1178         set(WIN_PSAPI_LIBRARY    psapi.lib)
1179         set(WIN_WSOCK32_LIBRARY  wsock32.lib)
1180         set(WIN_COMCTL32_LIBRARY comctl32.lib )
1181         set(WIN_VERSION_LIBRARY  version.lib)
1182 endif()
1183
1184 if(APPLE)
1185         #
1186         # We assume that APPLE means macOS so that we have the macOS
1187         # frameworks.
1188         #
1189         set(HAVE_MACOS_FRAMEWORKS 1)
1190         FIND_LIBRARY (APPLE_APPLICATION_SERVICES_LIBRARY ApplicationServices)
1191         FIND_LIBRARY (APPLE_APPKIT_LIBRARY AppKit)
1192         FIND_LIBRARY (APPLE_CORE_FOUNDATION_LIBRARY CoreFoundation)
1193         FIND_LIBRARY (APPLE_SYSTEM_CONFIGURATION_LIBRARY SystemConfiguration)
1194 endif()
1195
1196 include(ConfigureChecks.cmake)
1197
1198 # Global properties
1199 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
1200
1201 if(ENABLE_CCACHE AND (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang"))
1202         # http://stackoverflow.com/a/24305849/82195
1203         find_program(CCACHE_EXECUTABLE ccache)
1204         if(CCACHE_EXECUTABLE)
1205                 set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_EXECUTABLE}")
1206                 set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCACHE_EXECUTABLE}")
1207         endif()
1208 endif()
1209
1210 # The top level checkAPIs target, add before subdirectory calls so it's avaiable to all
1211 add_custom_target(checkAPI)
1212 set_target_properties(checkAPI
1213         PROPERTIES
1214                 FOLDER "Auxiliary"
1215                 EXCLUDE_FROM_ALL True
1216                 EXCLUDE_FROM_DEFAULT_BUILD True
1217 )
1218
1219 include( UseCheckAPI )
1220
1221 # Target platform locations
1222 # UN*X in general, including macOS if not building an app bundle:
1223 # $DESTDIR/lib/wireshark/extcap
1224 # Windows: $DESTDIR/extcap
1225 # macOS app bundle: Wireshark.app/Contents/Resources/share/wireshark/extcap
1226 # If you change the nesting level be sure to check also the INSTALL_RPATH
1227 # target property.
1228 if (WIN32)
1229         set(EXTCAP_INSTALL_LIBDIR "extcap" CACHE INTERNAL "The extcap dir")
1230 else ()
1231         set(EXTCAP_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/${CPACK_PACKAGE_NAME}/extcap" CACHE INTERNAL "The extcap dir")
1232 endif()
1233
1234 # Directory where plugins and Lua dissectors can be found.
1235 if(WIN32)
1236         set(PLUGIN_INSTALL_LIBDIR "plugins" CACHE INTERNAL "The plugin dir")
1237 else()
1238         set(PLUGIN_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/${CPACK_PACKAGE_NAME}/plugins" CACHE INTERNAL "The plugin dir")
1239 endif()
1240 set(PLUGIN_INSTALL_VERSION_LIBDIR "${PLUGIN_INSTALL_LIBDIR}/${PROJECT_RELEASE_VERSION}")
1241 set(PLUGIN_VERSION_DIR "plugins/${PROJECT_RELEASE_VERSION}")
1242
1243 add_subdirectory( capchild )
1244 add_subdirectory( caputils )
1245 add_subdirectory( codecs )
1246 add_subdirectory( doc )
1247 add_subdirectory( docbook EXCLUDE_FROM_ALL )
1248 add_subdirectory( epan )
1249 add_subdirectory( extcap )
1250 add_subdirectory( randpkt_core )
1251 add_subdirectory( tools/lemon )
1252 add_subdirectory( ui )
1253 add_subdirectory( wiretap )
1254 add_subdirectory( writecap )
1255
1256 # Location of our data files. This should be set to a value that allows
1257 # running from the build directory on Windows, on macOS when building an
1258 # application bundle, and on UNIX in general if
1259 # WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set.
1260 if(ENABLE_APPLICATION_BUNDLE)
1261         if(CMAKE_CFG_INTDIR STREQUAL ".")
1262                 set(_datafile_dir "${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/Resources/share/wireshark")
1263         else()
1264                 # Xcode
1265                 set(_datafile_dir "${CMAKE_BINARY_DIR}/run/${CMAKE_CFG_INTDIR}/Wireshark.app/Contents/Resources/share/wireshark")
1266         endif()
1267 elseif(NOT CMAKE_CFG_INTDIR STREQUAL ".")
1268         # Visual Studio, Xcode, etc.
1269         set(_datafile_dir "${CMAKE_BINARY_DIR}/run/${CMAKE_CFG_INTDIR}")
1270 else()
1271         # Makefile, Ninja, etc.
1272         set(_datafile_dir "${CMAKE_BINARY_DIR}/run")
1273 endif()
1274
1275 set(DATAFILE_DIR ${_datafile_dir} CACHE INTERNAL "Build time data file location.")
1276
1277 # wsutil must be added after DATAFILE_DIR is set such that filesystem.c can
1278 # learn about the directory location.
1279 add_subdirectory( wsutil )
1280
1281 if(NOT WIN32)
1282         add_custom_target(dumpabi DEPENDS dumpabi-libwireshark dumpabi-libwiretap dumpabi-libwsutil)
1283 endif()
1284
1285 if(BUILD_wireshark AND QT_FOUND)
1286         add_subdirectory( ui/qt )
1287 endif()
1288
1289 # Location of our plugins. PLUGIN_DIR should allow running
1290 # from the build directory similar to DATAFILE_DIR above.
1291 if(ENABLE_PLUGINS)
1292         # Target platform locations
1293         # UN*X in general, including macOS if not building an app bundle:
1294         # $DESTDIR/lib/wireshark/plugins/$VERSION
1295         # Windows: $DESTDIR/wireshark/plugins/$VERSION
1296         # macOS app bundle: Wireshark.app/Contents/PlugIns/wireshark
1297         set(HAVE_PLUGINS 1)
1298         add_custom_target(plugins)
1299         set_target_properties(plugins PROPERTIES FOLDER "Plugins")
1300         set(PLUGIN_SRC_DIRS
1301                 plugins/epan/ethercat
1302                 plugins/epan/gryphon
1303                 plugins/epan/irda
1304                 plugins/epan/mate
1305                 plugins/epan/opcua
1306                 plugins/epan/profinet
1307                 plugins/epan/stats_tree
1308                 plugins/epan/transum
1309                 plugins/epan/unistim
1310                 plugins/epan/wimax
1311                 plugins/epan/wimaxasncp
1312                 plugins/epan/wimaxmacphy
1313                 plugins/wiretap/usbdump
1314                 plugins/codecs/l16_mono
1315                 ${CUSTOM_PLUGIN_SRC_DIR}
1316         )
1317
1318         # Build demo plugin, only if asked explicitly
1319         if(ENABLE_PLUGIN_IFDEMO)
1320                 set(PLUGIN_SRC_DIRS
1321                         ${PLUGIN_SRC_DIRS}
1322                         plugins/epan/pluginifdemo
1323                 )
1324         endif()
1325
1326 else()
1327         set(PLUGIN_SRC_DIRS )
1328 endif()
1329
1330 if(ENABLE_APPLICATION_BUNDLE)
1331         if(CMAKE_CFG_INTDIR STREQUAL ".")
1332                 set(_plugin_dir "${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/PlugIns/wireshark/${PROJECT_RELEASE_VERSION}")
1333         else()
1334           # Xcode
1335                 set(_plugin_dir "${CMAKE_BINARY_DIR}/run/$<CONFIG>/Wireshark.app/Contents/PlugIns/wireshark/${PROJECT_RELEASE_VERSION}")
1336         endif()
1337 elseif(WIN32 AND NOT CMAKE_CFG_INTDIR STREQUAL ".")
1338         set(_plugin_dir "${CMAKE_BINARY_DIR}/run/$<CONFIG>/${PLUGIN_VERSION_DIR}")
1339 else()
1340         set(_plugin_dir "${DATAFILE_DIR}/${PLUGIN_VERSION_DIR}")
1341 endif()
1342 set (PLUGIN_DIR ${_plugin_dir} CACHE INTERNAL "Build time plugin location.")
1343
1344 foreach(_plugin_src_dir ${PLUGIN_SRC_DIRS})
1345         add_subdirectory( ${_plugin_src_dir} )
1346 endforeach()
1347
1348 if(ENABLE_PCAP_NG_DEFAULT)
1349         set(PCAP_NG_DEFAULT 1)
1350 endif()
1351
1352 # Large file support (e.g. make off_t 64 bit if supported)
1353 include(gmxTestLargeFiles)
1354 gmx_test_large_files(GMX_LARGEFILES)
1355
1356 set( VERSION ${PROJECT_VERSION} )
1357 add_custom_target(version
1358         BYPRODUCTS version.h
1359         COMMAND ${PERL_EXECUTABLE}
1360                 ${CMAKE_SOURCE_DIR}/tools/make-version.pl
1361                 ${CMAKE_SOURCE_DIR}
1362 )
1363 set_target_properties(version PROPERTIES FOLDER "Auxiliary")
1364
1365 set( configure_input "Built with CMake ${CMAKE_VERSION}" )
1366 configure_file(${CMAKE_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_BINARY_DIR}/config.h)
1367
1368 configure_file(${CMAKE_SOURCE_DIR}/ws_version.h.in ${CMAKE_BINARY_DIR}/ws_version.h)
1369
1370 set( prefix "${CMAKE_INSTALL_PREFIX}" )
1371 set( exec_prefix "\${prefix}" )
1372 set( libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}" )
1373 set( includedir  "\${prefix}/include" )
1374 set( plugindir "\${libdir}/wireshark/${PLUGIN_VERSION_DIR}" )
1375
1376 # Doxygen variables
1377 file(GLOB TOP_LEVEL_SOURCE_LIST *.c *.cpp *.h)
1378 string (REPLACE ";" " " DOXYGEN_TOP_LEVEL_SOURCES "${TOP_LEVEL_SOURCE_LIST}")
1379 set(DOXYGEN_INPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
1380 set(DOXYGEN_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
1381
1382 set(CFG_OUT_FILES
1383         doxygen.cfg
1384         image/libwireshark.rc
1385         image/wireshark.rc
1386         image/dumpcap.rc
1387         image/libwscodecs.rc
1388         image/libwsutil.rc
1389         image/wiretap.rc
1390         image/wireshark.exe.manifest
1391         packaging/macosx/Info.plist
1392         packaging/macosx/osx-app.sh
1393         packaging/macosx/osx-dmg.sh
1394         packaging/macosx/Read_me_first.rtf
1395         packaging/macosx/Wireshark_package.pmdoc/index.xml
1396         packaging/source/git-export-release.sh
1397         wireshark.pc
1398 )
1399 foreach( _cfg_file ${CFG_OUT_FILES} )
1400         configure_file( ${CMAKE_SOURCE_DIR}/${_cfg_file}.in ${CMAKE_BINARY_DIR}/${_cfg_file} @ONLY )
1401 endforeach()
1402
1403 include(FeatureSummary)
1404 set_package_properties(SBC PROPERTIES
1405         DESCRIPTION "Bluetooth low-complexity, subband codec (SBC) decoder"
1406         URL "https://git.kernel.org/pub/scm/bluetooth/sbc.git"
1407         PURPOSE "Support for playing SBC codec in RTP player"
1408 )
1409 set_package_properties(SPANDSP PROPERTIES
1410         DESCRIPTION "a library of many DSP functions for telephony"
1411         URL "http://www.soft-switch.org/"
1412         PURPOSE "Support for G.722 and G.726 codecs in RTP player"
1413 )
1414 set_package_properties(BCG729 PROPERTIES
1415         DESCRIPTION "G.729 decoder"
1416         URL "https://www.linphone.org/technical-corner/bcg729/overview"
1417         PURPOSE "Support for G.729 codec in RTP player"
1418 )
1419 set_package_properties(LIBXML2 PROPERTIES
1420         DESCRIPTION "XML parsing library"
1421         URL "http://xmlsoft.org/"
1422         PURPOSE "Read XML configuration files in EPL dissector"
1423 )
1424 set_package_properties(LIBSSH PROPERTIES
1425         DESCRIPTION "Library for implementing SSH clients"
1426         URL "https://www.libssh.org/"
1427         PURPOSE "extcap remote SSH interfaces (sshdump, ciscodump)"
1428 )
1429 set_package_properties(LZ4 PROPERTIES
1430         DESCRIPTION "LZ4 is lossless compression algorithm used in some protocol (CQL...)"
1431         URL "http://www.lz4.org"
1432         PURPOSE "LZ4 decompression in CQL and Kafka dissectors"
1433 )
1434 set_package_properties(SNAPPY PROPERTIES
1435         DESCRIPTION "A fast compressor/decompressor from Google"
1436         URL "http://google.github.io/snappy/"
1437         PURPOSE "Snappy decompression in CQL and Kafka dissectors"
1438 )
1439 set_package_properties(NGHTTP2 PROPERTIES
1440         DESCRIPTION "HTTP/2 C library and tools"
1441         URL "https://nghttp2.org"
1442         PURPOSE "Header decompression in HTTP2"
1443 )
1444
1445 message(STATUS "C-Flags: ${CMAKE_C_FLAGS}")
1446 message(STATUS "CXX-Flags: ${CMAKE_CXX_FLAGS}")
1447 message(STATUS "Warnings as errors: ${WERROR_COMMON_FLAGS}")
1448
1449 feature_summary(WHAT ALL)
1450
1451 if(WIN32)
1452         set(PLATFORM_UI_SRC
1453                 ui/win32/console_win32.c
1454                 ui/win32/file_dlg_win32.c
1455         )
1456         set(PLATFORM_UI_RC_FILES
1457                 image/file_dlg_win32.rc
1458         )
1459 elseif(APPLE)
1460         set(PLATFORM_UI_SRC
1461                 ui/macosx/cocoa_bridge.mm
1462         )
1463 endif()
1464
1465 set(TSHARK_TAP_SRC
1466         ${CMAKE_SOURCE_DIR}/ui/cli/tap-camelsrt.c
1467         ${CMAKE_SOURCE_DIR}/ui/cli/tap-diameter-avp.c
1468         ${CMAKE_SOURCE_DIR}/ui/cli/tap-expert.c
1469         ${CMAKE_SOURCE_DIR}/ui/cli/tap-exportobject.c
1470         ${CMAKE_SOURCE_DIR}/ui/cli/tap-endpoints.c
1471         ${CMAKE_SOURCE_DIR}/ui/cli/tap-flow.c
1472         ${CMAKE_SOURCE_DIR}/ui/cli/tap-follow.c
1473         ${CMAKE_SOURCE_DIR}/ui/cli/tap-funnel.c
1474         ${CMAKE_SOURCE_DIR}/ui/cli/tap-gsm_astat.c
1475         ${CMAKE_SOURCE_DIR}/ui/cli/tap-hosts.c
1476         ${CMAKE_SOURCE_DIR}/ui/cli/tap-httpstat.c
1477         ${CMAKE_SOURCE_DIR}/ui/cli/tap-icmpstat.c
1478         ${CMAKE_SOURCE_DIR}/ui/cli/tap-icmpv6stat.c
1479         ${CMAKE_SOURCE_DIR}/ui/cli/tap-iostat.c
1480         ${CMAKE_SOURCE_DIR}/ui/cli/tap-iousers.c
1481         ${CMAKE_SOURCE_DIR}/ui/cli/tap-macltestat.c
1482         ${CMAKE_SOURCE_DIR}/ui/cli/tap-protocolinfo.c
1483         ${CMAKE_SOURCE_DIR}/ui/cli/tap-protohierstat.c
1484         ${CMAKE_SOURCE_DIR}/ui/cli/tap-rlcltestat.c
1485         ${CMAKE_SOURCE_DIR}/ui/cli/tap-rpcprogs.c
1486         ${CMAKE_SOURCE_DIR}/ui/cli/tap-rtd.c
1487         ${CMAKE_SOURCE_DIR}/ui/cli/tap-rtp.c
1488         ${CMAKE_SOURCE_DIR}/ui/cli/tap-rtspstat.c
1489         ${CMAKE_SOURCE_DIR}/ui/cli/tap-sctpchunkstat.c
1490         ${CMAKE_SOURCE_DIR}/ui/cli/tap-simple_stattable.c
1491         ${CMAKE_SOURCE_DIR}/ui/cli/tap-sipstat.c
1492         ${CMAKE_SOURCE_DIR}/ui/cli/tap-smbsids.c
1493         ${CMAKE_SOURCE_DIR}/ui/cli/tap-srt.c
1494         ${CMAKE_SOURCE_DIR}/ui/cli/tap-stats_tree.c
1495         ${CMAKE_SOURCE_DIR}/ui/cli/tap-sv.c
1496         ${CMAKE_SOURCE_DIR}/ui/cli/tap-wspstat.c
1497 )
1498
1499 set(INSTALL_DIRS
1500         diameter
1501         dtds
1502         profiles
1503         radius
1504         tpncp
1505         wimaxasncp
1506 )
1507
1508 # FIXME: The help files are textfified on Windows into the staging dir.
1509 # The DATAFILE_DIR depends on CMAKE_CFG_INTDIR therefore it cannot be
1510 # added to an install() command with build systems supporting multiple
1511 # configurations in the build tree (e.g.: Visual Studio).
1512 if(NOT WIN32)
1513         list(APPEND INSTALL_DIRS help)
1514 endif()
1515
1516
1517 set(INSTALL_FILES
1518         cfilters
1519         colorfilters
1520         dfilters
1521         enterprises.tsv
1522         manuf
1523         pdml2html.xsl
1524         services
1525         smi_modules
1526         wka
1527         docbook/ws.css
1528         ${CMAKE_BINARY_DIR}/doc/AUTHORS-SHORT
1529         ${CMAKE_BINARY_DIR}/doc/androiddump.html
1530         ${CMAKE_BINARY_DIR}/doc/udpdump.html
1531         ${CMAKE_BINARY_DIR}/doc/capinfos.html
1532         ${CMAKE_BINARY_DIR}/doc/captype.html
1533         ${CMAKE_BINARY_DIR}/doc/ciscodump.html
1534         ${CMAKE_BINARY_DIR}/doc/dftest.html
1535         ${CMAKE_BINARY_DIR}/doc/dumpcap.html
1536         ${CMAKE_BINARY_DIR}/doc/editcap.html
1537         ${CMAKE_BINARY_DIR}/doc/extcap.html
1538         ${CMAKE_BINARY_DIR}/doc/mergecap.html
1539         ${CMAKE_BINARY_DIR}/doc/randpkt.html
1540         ${CMAKE_BINARY_DIR}/doc/randpktdump.html
1541         ${CMAKE_BINARY_DIR}/doc/rawshark.html
1542         ${CMAKE_BINARY_DIR}/doc/reordercap.html
1543         ${CMAKE_BINARY_DIR}/doc/sshdump.html
1544         ${CMAKE_BINARY_DIR}/doc/text2pcap.html
1545         ${CMAKE_BINARY_DIR}/doc/tshark.html
1546         ${CMAKE_BINARY_DIR}/doc/wireshark.html
1547         ${CMAKE_BINARY_DIR}/doc/wireshark-filter.html
1548 )
1549
1550 if(MAXMINDDB_FOUND)
1551         list(APPEND INSTALL_FILES ${CMAKE_BINARY_DIR}/doc/mmdbresolve.html)
1552 endif()
1553
1554 if (BUILD_corbaidl2wrs)
1555         list(APPEND INSTALL_FILES ${CMAKE_BINARY_DIR}/doc/idl2wrs.html)
1556 endif()
1557 if (BUILD_xxx2deb)
1558         list(APPEND INSTALL_FILES
1559                 ${CMAKE_BINARY_DIR}/doc/asn2deb.html
1560                 ${CMAKE_BINARY_DIR}/doc/idl2deb.html
1561         )
1562 endif()
1563
1564 if(WIN32)
1565         set(TEXTIFY_FILES COPYING NEWS README.windows)
1566         set(TEXTIFY_MD_FILES README.md)
1567         foreach(_text_file ${TEXTIFY_FILES} ${TEXTIFY_MD_FILES})
1568                 string(REGEX REPLACE ".md$" "" _out_file ${_text_file})
1569                 set(INSTALL_FILES ${CMAKE_BINARY_DIR}/${_out_file}.txt ${INSTALL_FILES})
1570         endforeach()
1571 else()
1572         set(INSTALL_FILES COPYING ${INSTALL_FILES})
1573 endif()
1574
1575 set(VERSION_INFO_LIBS
1576         ${ZLIB_LIBRARIES}
1577 )
1578 set(VERSION_INFO_INCLUDE_DIRS
1579         ${ZLIB_INCLUDE_DIRS}
1580 )
1581
1582 if(WIN32)
1583         set(_dll_output_dir "${DATAFILE_DIR}")
1584         add_custom_target(copy_cli_dlls)
1585         set_target_properties(copy_cli_dlls PROPERTIES FOLDER "Copy Tasks")
1586         add_custom_command(TARGET copy_cli_dlls PRE_BUILD
1587                 COMMAND ${CMAKE_COMMAND} -E make_directory "${_dll_output_dir}"
1588         )
1589
1590         # XXX Can (and should) we iterate over these similar to the way
1591         # the top-level CMakeLists.txt iterates over the package list?
1592
1593         # Required DLLs.
1594         # The gio, gnutls, png, and other OBS-generated DLLs depend on
1595         # zlib1.dll. We compile zlib locally but the Debug configuration
1596         # (the default) creates zlibd1.dll.
1597         add_custom_command(TARGET copy_cli_dlls PRE_BUILD
1598                 COMMAND ${CMAKE_COMMAND} -E copy_if_different
1599                         ${GLIB2_DLLS} $<$<CONFIG:Debug>:zlib1.dll>
1600                         "${_dll_output_dir}"
1601                 WORKING_DIRECTORY "${GLIB2_DLL_DIR}"
1602         )
1603
1604         # Optional DLLs and PDBs.
1605         set (OPTIONAL_DLLS)
1606         set (OPTIONAL_PDBS)
1607         if (AIRPCAP_FOUND)
1608                 list (APPEND OPTIONAL_DLLS "${AIRPCAP_DLL_DIR}/${AIRPCAP_DLL}")
1609         endif(AIRPCAP_FOUND)
1610         if (CARES_FOUND)
1611                 list (APPEND OPTIONAL_DLLS "${CARES_DLL_DIR}/${CARES_DLL}")
1612                 list (APPEND OPTIONAL_PDBS "${CARES_DLL_DIR}/${CARES_PDB}")
1613         endif(CARES_FOUND)
1614         if (MAXMINDDB_FOUND)
1615                 list (APPEND OPTIONAL_DLLS "${MAXMINDDB_DLL_DIR}/${MAXMINDDB_DLL}")
1616         endif(MAXMINDDB_FOUND)
1617         if (LIBSSH_FOUND)
1618                 list (APPEND OPTIONAL_DLLS "${LIBSSH_DLL_DIR}/${LIBSSH_DLL}")
1619         endif(LIBSSH_FOUND)
1620         foreach( _dll ${GCRYPT_DLLS} )
1621                 list (APPEND OPTIONAL_DLLS "${GCRYPT_DLL_DIR}/${_dll}")
1622         endforeach(_dll)
1623         foreach( _dll ${GNUTLS_DLLS} )
1624                 list (APPEND OPTIONAL_DLLS "${GNUTLS_DLL_DIR}/${_dll}")
1625         endforeach(_dll)
1626         foreach( _dll ${KERBEROS_DLLS} )
1627                 list (APPEND OPTIONAL_DLLS "${KERBEROS_DLL_DIR}/${_dll}")
1628         endforeach(_dll)
1629         if (LUA_FOUND)
1630                 list (APPEND OPTIONAL_DLLS "${LUA_DLL_DIR}/${LUA_DLL}")
1631         endif(LUA_FOUND)
1632         if (LZ4_FOUND)
1633                 list (APPEND OPTIONAL_DLLS "${LZ4_DLL_DIR}/${LZ4_DLL}")
1634         endif(LZ4_FOUND)
1635         if (NGHTTP2_FOUND)
1636                 list (APPEND OPTIONAL_DLLS "${NGHTTP2_DLL_DIR}/${NGHTTP2_DLL}")
1637         endif(NGHTTP2_FOUND)
1638         if (SBC_FOUND)
1639                 list (APPEND OPTIONAL_DLLS "${SBC_DLL_DIR}/${SBC_DLL}")
1640         endif(SBC_FOUND)
1641         if (SPANDSP_FOUND)
1642                 list (APPEND OPTIONAL_DLLS "${SPANDSP_DLL_DIR}/${SPANDSP_DLL}")
1643         endif(SPANDSP_FOUND)
1644         if (BCG729_FOUND)
1645                 list (APPEND OPTIONAL_DLLS "${BCG729_DLL_DIR}/${BCG729_DLL}")
1646         endif(BCG729_FOUND)
1647         if (LIBXML2_FOUND)
1648                 list (APPEND OPTIONAL_DLLS "${LIBXML2_DLL_DIR}/${LIBXML2_DLL}")
1649         endif(LIBXML2_FOUND)
1650         if (SMI_FOUND)
1651                 list (APPEND OPTIONAL_DLLS "${SMI_DLL_DIR}/${SMI_DLL}")
1652                 # Wireshark.nsi wants SMI_DIR which is the base SMI directory
1653                 get_filename_component(SMI_DIR ${SMI_DLL_DIR} DIRECTORY)
1654                 add_custom_command(TARGET copy_cli_dlls PRE_BUILD
1655                         COMMAND ${CMAKE_COMMAND} -E make_directory
1656                                 "${_dll_output_dir}/snmp"
1657                         COMMAND ${CMAKE_COMMAND} -E make_directory
1658                                 "${_dll_output_dir}/snmp/mibs"
1659                         COMMAND ${CMAKE_COMMAND} -E copy_directory
1660                                 "${SMI_SHARE_DIR}/mibs/iana"
1661                                 "${_dll_output_dir}/snmp/mibs"
1662                         COMMAND ${CMAKE_COMMAND} -E copy_directory
1663                                 "${SMI_SHARE_DIR}/mibs/ietf"
1664                                 "${_dll_output_dir}/snmp/mibs"
1665                         COMMAND ${CMAKE_COMMAND} -E copy_directory
1666                                 "${SMI_SHARE_DIR}/mibs/irtf"
1667                                 "${_dll_output_dir}/snmp/mibs"
1668                         COMMAND ${CMAKE_COMMAND} -E copy_directory
1669                                 "${SMI_SHARE_DIR}/mibs/site"
1670                                 "${_dll_output_dir}/snmp/mibs"
1671                         COMMAND ${CMAKE_COMMAND} -E copy_directory
1672                                 "${SMI_SHARE_DIR}/mibs/tubs"
1673                                 "${_dll_output_dir}/snmp/mibs"
1674                         COMMAND ${CMAKE_COMMAND} -E copy_directory
1675                                 "${SMI_SHARE_DIR}/pibs"
1676                                 "${_dll_output_dir}/snmp/mibs"
1677                         COMMAND ${CMAKE_COMMAND} -E copy_directory
1678                                 "${SMI_SHARE_DIR}/yang"
1679                                 "${_dll_output_dir}/snmp/mibs"
1680                         #remove the extra directories copied (shallow copying the above would remove the need for this)
1681                         COMMAND ${CMAKE_COMMAND} -E remove_directory
1682                                 "${_dll_output_dir}/snmp/mibs/iana"
1683                         COMMAND ${CMAKE_COMMAND} -E remove_directory
1684                                 "${_dll_output_dir}/snmp/mibs/ietf"
1685                         COMMAND ${CMAKE_COMMAND} -E remove_directory
1686                                 "${_dll_output_dir}/snmp/mibs/site"
1687                         COMMAND ${CMAKE_COMMAND} -E remove_directory
1688                                 "${_dll_output_dir}/snmp/mibs/tubs"
1689                 )
1690         endif(SMI_FOUND)
1691         if (SNAPPY_FOUND)
1692                 list (APPEND OPTIONAL_DLLS "${SNAPPY_DLL_DIR}/${SNAPPY_DLL}")
1693         endif(SNAPPY_FOUND)
1694         if (WINSPARKLE_FOUND)
1695                 list (APPEND OPTIONAL_DLLS "${WINSPARKLE_DLL_DIR}/${WINSPARKLE_DLL}")
1696         endif(WINSPARKLE_FOUND)
1697
1698         # With libs downloaded to c:/wireshark-win64-libs this currently
1699         # (early 2018) expands to about 1900 characters.
1700         if (OPTIONAL_DLLS)
1701                 add_custom_command(TARGET copy_cli_dlls PRE_BUILD
1702                         COMMAND ${CMAKE_COMMAND} -E copy_if_different
1703                                 ${OPTIONAL_DLLS}
1704                                 "${_dll_output_dir}"
1705                         VERBATIM
1706                 )
1707                 install(FILES ${OPTIONAL_DLLS} DESTINATION "${CMAKE_INSTALL_BINDIR}")
1708         endif(OPTIONAL_DLLS)
1709
1710         if (OPTIONAL_PDBS)
1711                 add_custom_command(TARGET copy_cli_dlls PRE_BUILD
1712                         COMMAND ${CMAKE_COMMAND} -E copy_if_different
1713                                 ${OPTIONAL_PDBS}
1714                                 "${_dll_output_dir}"
1715                         VERBATIM
1716                 )
1717         endif(OPTIONAL_PDBS)
1718
1719         add_dependencies(epan copy_cli_dlls)
1720
1721         # We have a lot of choices for creating zip archives:
1722         # - 7z, WinZip, etc., which require a separate download+install.
1723         # - "CMake -E tar cz", which creates a tar file.
1724         # - CPack, which requires a CPack configuration.
1725         # - PowerShell via PSCX or System.IO.Compression.FileSystem.
1726         # - Python via zipfile.
1727         # For now, just look for 7z. It's installed on the Windows builders,
1728         # which might be the only systems that use this target.
1729         find_program(ZIP_EXECUTABLE 7z
1730                 PATH "$ENV{PROGRAMFILES}/7-Zip" "$ENV{PROGRAMW6432}/7-Zip"
1731                 DOC "Path to the 7z utility."
1732         )
1733         if(ZIP_EXECUTABLE)
1734                 add_custom_target(pdb_zip_package COMMENT "This packages .PDBs but will not create them.")
1735                 set_target_properties(pdb_zip_package PROPERTIES FOLDER "Packaging")
1736                 set(_pdb_zip "${CMAKE_BINARY_DIR}/Wireshark-pdb-${WIRESHARK_TARGET_PLATFORM}-${VERSION}.zip")
1737                 file(TO_NATIVE_PATH "${_pdb_zip}" _pdb_zip_win)
1738                 add_custom_command(TARGET pdb_zip_package POST_BUILD
1739                         COMMAND ${CMAKE_COMMAND} -E remove -f "${_pdb_zip}"
1740                         COMMAND ${ZIP_EXECUTABLE} a -tzip -mmt=on "${_pdb_zip_win}"
1741                                 *.pdb *.lib
1742                                 extcap/*.pdb
1743                                 ${PLUGIN_VERSION_DIR}/epan/*.pdb
1744                                 ${PLUGIN_VERSION_DIR}/wiretap/*.pdb
1745                         WORKING_DIRECTORY "${_dll_output_dir}"
1746                 )
1747         endif()
1748 endif(WIN32)
1749
1750 # List of extra dependencies for the "copy_data_files" target
1751 set(copy_data_files_depends)
1752
1753 # glob patterns relative to the source directory that should be copied to
1754 # ${DATAFILE_DIR} (including directory prefixes)
1755 set(DATA_FILES_SRC
1756         "help/toc"
1757 )
1758
1759 if(WIN32)
1760         foreach(_text_file ${TEXTIFY_FILES})
1761                 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${_text_file}.txt
1762                         COMMAND ${POWERSHELL_COMMAND} "${CMAKE_SOURCE_DIR}/tools/textify.ps1"
1763                                 -Destination ${CMAKE_BINARY_DIR}
1764                                 ${CMAKE_SOURCE_DIR}/${_text_file}
1765                         DEPENDS
1766                                 ${CMAKE_SOURCE_DIR}/${_text_file}
1767                 )
1768         endforeach()
1769         foreach(_md_file ${TEXTIFY_MD_FILES})
1770                 string(REGEX REPLACE ".md$" ".txt" _text_file ${_md_file})
1771                 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${_text_file}
1772                         COMMAND ${POWERSHELL_COMMAND} "${CMAKE_SOURCE_DIR}/tools/textify.ps1"
1773                                 -Destination ${CMAKE_BINARY_DIR}
1774                                 ${CMAKE_SOURCE_DIR}/${_md_file}
1775                         COMMAND ${CMAKE_COMMAND} -E rename
1776                                 ${CMAKE_BINARY_DIR}/${_md_file}.txt
1777                                 ${CMAKE_BINARY_DIR}/${_text_file}
1778                         DEPENDS
1779                                 ${CMAKE_SOURCE_DIR}/${_text_file}
1780                 )
1781         endforeach()
1782 endif()
1783
1784 foreach(_install_file ${INSTALL_FILES})
1785         get_filename_component(_install_file_src "${_install_file}" ABSOLUTE)
1786         get_filename_component(_install_basename "${_install_file}" NAME)
1787         set(_output_file "${DATAFILE_DIR}/${_install_basename}")
1788         add_custom_command(OUTPUT "${_output_file}"
1789                 COMMAND ${CMAKE_COMMAND} -E copy_if_different
1790                         "${_install_file_src}"
1791                         "${_output_file}"
1792                 DEPENDS
1793                         docs
1794                         "${_install_file}"
1795         )
1796         list(APPEND copy_data_files_depends "${_output_file}")
1797 endforeach()
1798
1799 # faq.txt is handled separately below.
1800 set(_help_source_files
1801         help/capture_filters.txt
1802         help/capturing.txt
1803         help/display_filters.txt
1804         help/getting_started.txt
1805         help/overview.txt
1806 )
1807
1808 if(WIN32)
1809         file(TO_NATIVE_PATH "${DATAFILE_DIR}/help" _help_dest_dir)
1810         foreach(_help_file IN LISTS _help_source_files)
1811                 add_custom_command(OUTPUT "${DATAFILE_DIR}/${_help_file}"
1812                         COMMAND ${CMAKE_COMMAND} -E make_directory "${DATAFILE_DIR}/help"
1813                         COMMAND ${POWERSHELL_COMMAND} "${CMAKE_SOURCE_DIR}/tools/textify.ps1"
1814                                 -Destination "${_help_dest_dir}"
1815                                 "${CMAKE_SOURCE_DIR}/${_help_file}"
1816                         DEPENDS
1817                                 "${CMAKE_SOURCE_DIR}/${_help_file}"
1818                 )
1819                 list(APPEND copy_data_files_depends "${DATAFILE_DIR}/${_help_file}")
1820         endforeach()
1821 else()
1822         list(APPEND DATA_FILES_SRC ${_help_source_files})
1823 endif(WIN32)
1824
1825 # Create help/faq.txt when missing
1826 add_custom_command(OUTPUT "${DATAFILE_DIR}/help/faq.txt"
1827         COMMAND ${CMAKE_COMMAND} -E make_directory "${DATAFILE_DIR}/help"
1828         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/help/faq.py -b > faq.tmp.html
1829         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/html2text.py
1830                 faq.tmp.html > "${DATAFILE_DIR}/help/faq.txt"
1831         COMMAND ${CMAKE_COMMAND} -E remove faq.tmp.html
1832         DEPENDS
1833                 "${CMAKE_SOURCE_DIR}/help/faq.py"
1834                 "${CMAKE_SOURCE_DIR}/tools/html2text.py"
1835 )
1836 list(APPEND copy_data_files_depends "${DATAFILE_DIR}/help/faq.txt")
1837
1838 # Install LUA files in staging directory such that LUA can used when Wireshark
1839 # is ran from the build directory. For install targets, see
1840 # epan/wslua/CMakeLists.txt
1841 if(LUA_FOUND AND ENABLE_LUA)
1842         set(_lua_files
1843                 "${CMAKE_BINARY_DIR}/epan/wslua/init.lua"
1844                 "${CMAKE_SOURCE_DIR}/epan/wslua/console.lua"
1845                 "${CMAKE_SOURCE_DIR}/epan/wslua/dtd_gen.lua"
1846         )
1847         foreach(_lua_file ${_lua_files})
1848                 get_filename_component(_lua_filename "${_lua_file}" NAME)
1849                 list(APPEND copy_data_files_depends
1850                         "${DATAFILE_DIR}/${_lua_filename}")
1851                 add_custom_command(OUTPUT "${DATAFILE_DIR}/${_lua_filename}"
1852                         COMMAND ${CMAKE_COMMAND} -E copy_if_different
1853                                 "${_lua_file}"
1854                                 "${DATAFILE_DIR}/${_lua_filename}"
1855                         DEPENDS
1856                                 wsluaauxiliary
1857                                 "${_lua_file}"
1858                 )
1859         endforeach()
1860 endif(LUA_FOUND AND ENABLE_LUA)
1861 # doc/*.html handled elsewhere.
1862
1863 # TODO shouldn't this use full (relative) paths instead of glob patterns?
1864 list(APPEND DATA_FILES_SRC
1865         "tpncp/tpncp.dat"
1866         "wimaxasncp/*.dtd"
1867         "wimaxasncp/*.xml"
1868 )
1869
1870 # Copy all paths from the source tree to the data directory. Directories are
1871 # automatically created if missing as the filename is given.
1872 file(GLOB _data_files RELATIVE "${CMAKE_SOURCE_DIR}" ${DATA_FILES_SRC})
1873 foreach(_data_file ${_data_files})
1874         add_custom_command(OUTPUT "${DATAFILE_DIR}/${_data_file}"
1875                 COMMAND ${CMAKE_COMMAND} -E copy_if_different
1876                         "${CMAKE_SOURCE_DIR}/${_data_file}"
1877                         "${DATAFILE_DIR}/${_data_file}"
1878                 DEPENDS
1879                         "${CMAKE_SOURCE_DIR}/${_data_file}"
1880         )
1881         list(APPEND copy_data_files_depends "${DATAFILE_DIR}/${_data_file}")
1882 endforeach()
1883
1884 file(GLOB _dtds_src_files RELATIVE "${CMAKE_SOURCE_DIR}" "dtds/*.dtd")
1885
1886 set (_dtds_data_files)
1887 foreach(_data_file ${_dtds_src_files})
1888         list(APPEND _dtds_data_files "${DATAFILE_DIR}/${_data_file}")
1889 endforeach()
1890
1891 add_custom_command(
1892         OUTPUT ${_dtds_data_files}
1893         COMMAND ${CMAKE_COMMAND} -E make_directory "${DATAFILE_DIR}/dtds"
1894         COMMAND ${CMAKE_COMMAND} -E copy_if_different
1895                 ${_dtds_src_files}
1896                 "${DATAFILE_DIR}/dtds"
1897         VERBATIM
1898         DEPENDS ${_dtds_src_files}
1899         WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
1900 )
1901
1902 file(GLOB _diameter_src_files RELATIVE "${CMAKE_SOURCE_DIR}"
1903         diameter/*.dtd
1904         diameter/*.xml
1905 )
1906
1907 set (_diameter_data_files)
1908 foreach(_data_file ${_diameter_src_files})
1909         list(APPEND _diameter_data_files "${DATAFILE_DIR}/${_data_file}")
1910 endforeach()
1911
1912 add_custom_command(
1913         OUTPUT ${_diameter_data_files}
1914         COMMAND ${CMAKE_COMMAND} -E make_directory "${DATAFILE_DIR}/diameter"
1915         COMMAND ${CMAKE_COMMAND} -E copy_if_different
1916                 ${_diameter_src_files}
1917                 "${DATAFILE_DIR}/diameter"
1918         VERBATIM
1919         DEPENDS ${_diameter_src_files}
1920         WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
1921 )
1922
1923 file(GLOB _radius_src_files RELATIVE "${CMAKE_SOURCE_DIR}"
1924         radius/README.radius_dictionary
1925         radius/custom.includes
1926         radius/dictionary
1927         radius/dictionary.*
1928 )
1929
1930 set (_radius_data_files)
1931 foreach(_data_file ${_radius_src_files})
1932         list(APPEND _radius_data_files "${DATAFILE_DIR}/${_data_file}")
1933 endforeach()
1934
1935 add_custom_command(
1936         OUTPUT ${_radius_data_files}
1937         COMMAND ${CMAKE_COMMAND} -E make_directory "${DATAFILE_DIR}/radius"
1938         COMMAND ${CMAKE_COMMAND} -E copy_if_different
1939                 ${_radius_src_files}
1940                 "${DATAFILE_DIR}/radius"
1941         VERBATIM
1942         DEPENDS ${_radius_src_files}
1943         WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
1944 )
1945
1946 file(GLOB _profiles_src_files RELATIVE "${CMAKE_SOURCE_DIR}" profiles/*/*)
1947 set (_profiles_data_files)
1948 foreach(_data_file ${_profiles_src_files})
1949         list(APPEND _profiles_data_files "${DATAFILE_DIR}/${_data_file}")
1950 endforeach()
1951
1952 add_custom_command(
1953         OUTPUT ${_profiles_data_files}
1954         COMMAND ${CMAKE_COMMAND} -E copy_directory
1955                 "${CMAKE_SOURCE_DIR}/profiles" "${DATAFILE_DIR}/profiles"
1956 )
1957
1958 list(APPEND copy_data_files_depends
1959         ${_dtds_data_files}
1960         ${_diameter_data_files}
1961         ${_radius_data_files}
1962         ${_profiles_data_files}
1963 )
1964
1965 # Copy files including ${INSTALL_FILES} and ${INSTALL_DIRS} to ${DATAFILE_DIR}
1966 add_custom_target(copy_data_files ALL DEPENDS ${copy_data_files_depends} )
1967 set_target_properties(copy_data_files PROPERTIES FOLDER "Copy Tasks")
1968
1969
1970 # Shared code, build object files once for all users.
1971 add_library(version_info OBJECT version_info.c)
1972 target_include_directories(version_info SYSTEM PRIVATE ${VERSION_INFO_INCLUDE_DIRS})
1973 add_dependencies(version_info version)
1974 # sources common for wireshark, tshark, rawshark and sharkd
1975 add_library(shark_common OBJECT
1976         cfile.c
1977         extcap.c
1978         extcap_parser.c
1979         file_packet_provider.c
1980         frame_tvbuff.c
1981         sync_pipe_write.c
1982 )
1983 add_library(cli_main OBJECT cli_main.c)
1984 add_library(capture_opts OBJECT capture_opts.c)
1985 target_include_directories(capture_opts SYSTEM PRIVATE ${PCAP_INCLUDE_DIRS})
1986 set_target_properties(version_info shark_common cli_main capture_opts
1987         PROPERTIES
1988         COMPILE_FLAGS "${WERROR_COMMON_FLAGS}"
1989 )
1990
1991
1992 if(BUILD_wireshark AND QT_FOUND)
1993         set(WIRESHARK_SRC
1994                 capture_info.c
1995                 file.c
1996                 fileset.c
1997                 ${PLATFORM_UI_SRC}
1998         )
1999         set(wireshark_FILES
2000                 $<TARGET_OBJECTS:capture_opts>
2001                 $<TARGET_OBJECTS:qtui>
2002                 $<TARGET_OBJECTS:shark_common>
2003                 $<TARGET_OBJECTS:version_info>
2004                 ${WIRESHARK_SRC}
2005                 ${PLATFORM_UI_RC_FILES}
2006         )
2007         set_executable_resources(wireshark "Wireshark" UNIQUE_RC)
2008 endif()
2009
2010 if(ENABLE_APPLICATION_BUNDLE)
2011         #
2012         # Add -Wl,-single_module to the LDFLAGS used with shared
2013         # libraries, to fix some error that show up in some cases;
2014         # some Apple documentation recommends it for most shared
2015         # libraries.
2016         #
2017         set( CMAKE_SHARED_LINKER_FLAGS "-Wl,-single_module ${CMAKE_SHARED_LINKER_FLAGS}" )
2018         #
2019         # Add -Wl,-headerpad_max_install_names to the LDFLAGS, as
2020         # code-signing issues is running out of padding space.
2021         #
2022         # Add -Wl,-search_paths_first to make sure that if we search
2023         # directories A and B, in that order, for a given library, a
2024         # non-shared version in directory A, rather than a shared
2025         # version in directory B, is chosen (so we can use
2026         # --with-pcap=/usr/local to force all programs to be linked
2027         # with a static version installed in /usr/local/lib rather than
2028         # the system version in /usr/lib).
2029         #
2030
2031         set(CMAKE_EXE_LINKER_FLAGS
2032         "-Wl,-headerpad_max_install_names -Wl,-search_paths_first ${CMAKE_EXE_LINKER_FLAGS}"
2033         )
2034
2035         # Create our Frameworks directory
2036         file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/run/${CMAKE_CFG_INTDIR}/Wireshark.app/Contents/Frameworks")
2037
2038         # Add files to the app bundle
2039         # Wireshark.app/Contents
2040         file(WRITE ${CMAKE_BINARY_DIR}/packaging/macosx/PkgInfo "APPLWshk\n")
2041         set(BUNDLE_CONTENTS_FILES
2042                 ${CMAKE_BINARY_DIR}/packaging/macosx/PkgInfo
2043         )
2044         set_source_files_properties(${BUNDLE_CONTENTS_FILES} PROPERTIES
2045                 MACOSX_PACKAGE_LOCATION .
2046         )
2047
2048         # Wireshark.app/Contents/Resources
2049         set(BUNDLE_RESOURCE_FILES
2050                 ${CMAKE_SOURCE_DIR}/packaging/macosx/Wireshark.icns
2051                 ${CMAKE_SOURCE_DIR}/packaging/macosx/Wiresharkdoc.icns
2052         )
2053         set_source_files_properties(${BUNDLE_RESOURCE_FILES} PROPERTIES
2054                 MACOSX_PACKAGE_LOCATION Resources
2055         )
2056
2057         # Wireshark.app/Contents/Resources/share/man/man1
2058         set_source_files_properties(${BUNDLE_RESOURCE_SHARE_MAN1_FILES} PROPERTIES
2059                 MACOSX_PACKAGE_LOCATION Resources/share/man/man1
2060                 GENERATED 1
2061         )
2062
2063         # Wireshark.app/Contents/Resources/share/man/man4
2064         set_source_files_properties(${BUNDLE_RESOURCE_SHARE_MAN4_FILES} PROPERTIES
2065                 MACOSX_PACKAGE_LOCATION Resources/share/man/man4
2066                 GENERATED 1
2067         )
2068
2069         # INSTALL_FILES and INSTALL_DIRS are handled by copy_data_files
2070
2071         set(EXTRA_BUNDLE_FILES
2072                 ${BUNDLE_CONTENTS_FILES}
2073                 ${BUNDLE_RESOURCE_FILES}
2074                 ${BUNDLE_RESOURCE_SHARE_MAN1_FILES}
2075                 ${BUNDLE_RESOURCE_SHARE_MAN4_FILES}
2076         )
2077 else()
2078         set(EXTRA_BUNDLE_FILES)
2079 endif()
2080
2081 if(BUILD_wireshark AND QT_FOUND)
2082         set(wireshark_LIBS
2083                 ui
2084                 capchild
2085                 caputils
2086                 wiretap
2087                 wscodecs
2088                 epan
2089                 ${QT_LIBRARIES}
2090                 ${VERSION_INFO_LIBS}
2091                 ${APPLE_APPLICATION_SERVICES_LIBRARY}
2092                 ${APPLE_APPKIT_LIBRARY}
2093                 ${APPLE_CORE_FOUNDATION_LIBRARY}
2094                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
2095                 ${WIN_VERSION_LIBRARY}
2096                 ${WINSPARKLE_LIBRARIES}
2097                 $<$<BOOL:${WIN32}>:UxTheme.lib>
2098         )
2099
2100         add_executable(wireshark WIN32 MACOSX_BUNDLE ${wireshark_FILES} ${EXTRA_BUNDLE_FILES})
2101         set(PROGLIST ${PROGLIST} wireshark)
2102         set_target_properties(wireshark PROPERTIES
2103                 LINK_FLAGS "${WS_LINK_FLAGS}"
2104                 FOLDER "Executables"
2105         )
2106         if(ENABLE_APPLICATION_BUNDLE OR WIN32)
2107                 set_target_properties(wireshark PROPERTIES OUTPUT_NAME Wireshark)
2108         endif()
2109
2110         if(ENABLE_APPLICATION_BUNDLE)
2111                 add_dependencies(wireshark manpages)
2112                 set_target_properties(
2113                         wireshark PROPERTIES
2114                                 MACOSX_BUNDLE_INFO_PLIST ${CMAKE_BINARY_DIR}/packaging/macosx/Info.plist
2115                 )
2116                 if(CMAKE_CFG_INTDIR STREQUAL ".")
2117                         # Add a wrapper script which opens the bundle. This adds
2118                         # convenience but makes debugging more difficult.
2119                         # It is not created if using Xcode
2120                         file(REMOVE ${CMAKE_BINARY_DIR}/run/wireshark)
2121                         file(WRITE ${CMAKE_BINARY_DIR}/run/wireshark "#!/bin/sh\n")
2122                         file(APPEND ${CMAKE_BINARY_DIR}/run/wireshark "# Generated by ${CMAKE_CURRENT_LIST_FILE}\n")
2123                         file(APPEND ${CMAKE_BINARY_DIR}/run/wireshark "exec ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/MacOS/Wireshark \"\$\@\"\n")
2124                         execute_process(COMMAND chmod a+x ${CMAKE_BINARY_DIR}/run/wireshark)
2125                 endif()
2126         endif()
2127
2128         target_link_libraries(wireshark ${wireshark_LIBS})
2129
2130         install(
2131                 TARGETS wireshark
2132                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
2133                 BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}
2134         )
2135
2136         if(QT_WINDEPLOYQT_EXECUTABLE)
2137                 add_custom_target(copy_qt_dlls ALL)
2138                 set_target_properties(copy_qt_dlls PROPERTIES FOLDER "Copy Tasks")
2139                 # Will we ever need to use --debug? Windeployqt seems to
2140                 # be smart enough to copy debug DLLs when needed.
2141                 add_custom_command(TARGET copy_qt_dlls
2142                         POST_BUILD
2143                         COMMAND set "PATH=${QT_BIN_PATH};%PATH%"
2144                         COMMAND "${QT_WINDEPLOYQT_EXECUTABLE}"
2145                                 $<$<CONFIG:Debug>:--debug>
2146                                 $<$<NOT:$<CONFIG:Debug>>:--release>
2147                                 --no-compiler-runtime
2148                                 --verbose 10
2149                                 "$<TARGET_FILE:wireshark>"
2150                 )
2151                 add_dependencies(copy_qt_dlls wireshark)
2152
2153                 install(CODE "execute_process(COMMAND
2154                         \"${QT_WINDEPLOYQT_EXECUTABLE}\"
2155                         --no-compiler-runtime
2156                         \"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/Wireshark.exe\")"
2157                 )
2158
2159         endif(QT_WINDEPLOYQT_EXECUTABLE)
2160 endif()
2161
2162 # Common properties for CLI executables
2163 macro(set_extra_executable_properties _executable _folder)
2164         set_target_properties(${_executable} PROPERTIES
2165                 LINK_FLAGS "${WILDCARD_OBJ} ${WS_LINK_FLAGS}"
2166                 FOLDER ${_folder}
2167         )
2168
2169         set(PROGLIST ${PROGLIST} ${_executable})
2170
2171         if(ENABLE_APPLICATION_BUNDLE)
2172                 if(NOT CMAKE_CFG_INTDIR STREQUAL ".")
2173                         # Xcode
2174                         set_target_properties(${_executable} PROPERTIES
2175                                 RUNTIME_OUTPUT_DIRECTORY run/$<CONFIG>/Wireshark.app/Contents/MacOS
2176                         )
2177                 else ()
2178                         set_target_properties(${_executable} PROPERTIES
2179                                 RUNTIME_OUTPUT_DIRECTORY run/Wireshark.app/Contents/MacOS
2180                         )
2181                         # Add a wrapper script which runs each executable from the
2182                         # correct location. This adds convenience but makes debugging
2183                         # more difficult.
2184                         file(REMOVE ${CMAKE_BINARY_DIR}/run/${_executable})
2185                         file(WRITE ${CMAKE_BINARY_DIR}/run/${_executable} "#!/bin/sh\n")
2186                         file(APPEND ${CMAKE_BINARY_DIR}/run/${_executable} "exec ${CMAKE_BINARY_DIR}/run/Wireshark.app/Contents/MacOS/${_executable} \"\$\@\"\n")
2187                         execute_process(COMMAND chmod a+x ${CMAKE_BINARY_DIR}/run/${_executable})
2188                 endif()
2189         endif()
2190 endmacro()
2191
2192 register_tap_files(tshark-tap-register.c
2193         ${TSHARK_TAP_SRC}
2194 )
2195
2196 if(BUILD_tshark)
2197         set(tshark_LIBS
2198                 ui
2199                 capchild
2200                 caputils
2201                 wiretap
2202                 epan
2203                 ${VERSION_INFO_LIBS}
2204                 ${APPLE_CORE_FOUNDATION_LIBRARY}
2205                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
2206                 ${M_LIBRARIES}
2207         )
2208         set(tshark_FILES
2209                 $<TARGET_OBJECTS:capture_opts>
2210                 $<TARGET_OBJECTS:cli_main>
2211                 $<TARGET_OBJECTS:shark_common>
2212                 $<TARGET_OBJECTS:version_info>
2213                 tshark-tap-register.c
2214                 tshark.c
2215                 ${TSHARK_TAP_SRC}
2216         )
2217
2218         set_executable_resources(tshark "TShark" UNIQUE_RC)
2219         add_executable(tshark ${tshark_FILES})
2220         set_extra_executable_properties(tshark "Executables")
2221         target_link_libraries(tshark ${tshark_LIBS})
2222         install(TARGETS tshark RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2223 endif()
2224
2225 if(BUILD_tfshark)
2226         set(tfshark_LIBS
2227                 ui
2228                 wiretap
2229                 epan
2230                 ${VERSION_INFO_LIBS}
2231                 ${APPLE_CORE_FOUNDATION_LIBRARY}
2232                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
2233         )
2234         set(tfshark_FILES
2235                 $<TARGET_OBJECTS:cli_main>
2236                 $<TARGET_OBJECTS:shark_common>
2237                 $<TARGET_OBJECTS:version_info>
2238                 tfshark.c
2239                 ${TSHARK_TAP_SRC}
2240         )
2241         set_executable_resources(tfshark "TFShark")
2242         add_executable(tfshark ${tfshark_FILES})
2243         set_extra_executable_properties(tfshark "Executables")
2244         target_link_libraries(tfshark ${tfshark_LIBS})
2245         install(TARGETS tfshark RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2246 endif()
2247
2248 if(BUILD_rawshark AND PCAP_FOUND)
2249         set(rawshark_LIBS
2250                 caputils
2251                 ui
2252                 wiretap
2253                 epan
2254                 ${VERSION_INFO_LIBS}
2255                 ${APPLE_CORE_FOUNDATION_LIBRARY}
2256                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
2257         )
2258         set(rawshark_FILES
2259                 $<TARGET_OBJECTS:cli_main>
2260                 $<TARGET_OBJECTS:shark_common>
2261                 $<TARGET_OBJECTS:version_info>
2262                 rawshark.c
2263         )
2264         set_executable_resources(rawshark "Rawshark")
2265         add_executable(rawshark ${rawshark_FILES})
2266         set_extra_executable_properties(rawshark "Executables")
2267         target_link_libraries(rawshark ${rawshark_LIBS})
2268         install(TARGETS rawshark RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2269 endif()
2270
2271 if(BUILD_sharkd)
2272         set(sharkd_LIBS
2273                 ui
2274                 wscodecs
2275                 wiretap
2276                 epan
2277                 ${VERSION_INFO_LIBS}
2278                 ${APPLE_CORE_FOUNDATION_LIBRARY}
2279                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
2280         )
2281         set(sharkd_FILES
2282                 #
2283                 # XXX - currently doesn't work on Windows if it uses
2284                 # $<TARGET_OBJECTS:cli_main> and has real_main().
2285                 #
2286                 $<TARGET_OBJECTS:shark_common>
2287                 $<TARGET_OBJECTS:version_info>
2288                 sharkd.c
2289                 sharkd_daemon.c
2290                 sharkd_session.c
2291         )
2292         set_executable_resources(sharkd "SharkD")
2293         add_executable(sharkd ${sharkd_FILES})
2294         set_extra_executable_properties(sharkd "Executables")
2295         target_link_libraries(sharkd ${sharkd_LIBS})
2296         if(WIN32)
2297                 target_link_libraries(sharkd "ws2_32.lib")
2298         endif(WIN32)
2299
2300         install(TARGETS sharkd RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2301 endif()
2302
2303 if(BUILD_dftest)
2304         set(dftest_LIBS
2305                 ui
2306                 wiretap
2307                 epan
2308                 ${VERSION_INFO_LIBS}
2309         )
2310         set(dftest_FILES
2311                 dftest.c
2312         )
2313         add_executable(dftest ${dftest_FILES})
2314         set_extra_executable_properties(dftest "Tests")
2315         target_link_libraries(dftest ${dftest_LIBS})
2316 endif()
2317
2318 if(BUILD_randpkt)
2319         set(randpkt_LIBS
2320                 randpkt_core
2321                 ui
2322                 wiretap
2323                 wsutil
2324                 ${M_LIBRARIES}
2325                 ${PCAP_LIBRARIES}
2326                 ${CARES_LIBRARIES}
2327                 ${ZLIB_LIBRARIES}
2328         )
2329         set(randpkt_FILES
2330                 $<TARGET_OBJECTS:cli_main>
2331                 $<TARGET_OBJECTS:version_info>
2332                 randpkt.c
2333         )
2334         add_executable(randpkt ${randpkt_FILES})
2335         set_extra_executable_properties(randpkt "Executables")
2336         target_link_libraries(randpkt ${randpkt_LIBS})
2337         install(TARGETS randpkt RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2338 endif()
2339
2340 if(BUILD_fuzzshark OR ENABLE_FUZZER OR OSS_FUZZ)
2341         add_subdirectory(fuzz)
2342 endif()
2343
2344 if(BUILD_text2pcap)
2345         set(text2pcap_LIBS
2346                 writecap
2347                 wsutil
2348                 ${M_LIBRARIES}
2349                 ${ZLIB_LIBRARIES}
2350         )
2351         set(text2pcap_FILES
2352                 $<TARGET_OBJECTS:cli_main>
2353                 $<TARGET_OBJECTS:version_info>
2354                 text2pcap.c
2355         )
2356         add_lex_files(text2pcap_LEX_FILES text2pcap_FILES
2357                 text2pcap-scanner.l
2358         )
2359         set_executable_resources(text2pcap "Text2pcap"
2360                 COPYRIGHT_INFO "2001 Ashok Narayanan <ashokn@cisco.com>")
2361         add_executable(text2pcap ${text2pcap_FILES})
2362         set_extra_executable_properties(text2pcap "Executables")
2363         target_link_libraries(text2pcap ${text2pcap_LIBS})
2364         install(TARGETS text2pcap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2365 endif()
2366
2367 if(BUILD_mergecap)
2368         set(mergecap_LIBS
2369                 ui
2370                 wiretap
2371                 ${ZLIB_LIBRARIES}
2372                 ${CMAKE_DL_LIBS}
2373         )
2374         set(mergecap_FILES
2375                 $<TARGET_OBJECTS:cli_main>
2376                 $<TARGET_OBJECTS:version_info>
2377                 mergecap.c
2378         )
2379         set_executable_resources(mergecap "Mergecap")
2380         add_executable(mergecap ${mergecap_FILES})
2381         set_extra_executable_properties(mergecap "Executables")
2382         target_link_libraries(mergecap ${mergecap_LIBS})
2383         install(TARGETS mergecap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2384 endif()
2385
2386 if(BUILD_reordercap)
2387         set(reordercap_LIBS
2388                 ui
2389                 wiretap
2390                 ${ZLIB_LIBRARIES}
2391                 ${CMAKE_DL_LIBS}
2392         )
2393         set(reordercap_FILES
2394                 $<TARGET_OBJECTS:cli_main>
2395                 $<TARGET_OBJECTS:version_info>
2396                 reordercap.c
2397         )
2398         set_executable_resources(reordercap "Reordercap")
2399         add_executable(reordercap ${reordercap_FILES})
2400         set_extra_executable_properties(reordercap "Executables")
2401         target_link_libraries(reordercap ${reordercap_LIBS})
2402         install(TARGETS reordercap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2403 endif()
2404
2405 if(BUILD_capinfos)
2406         set(capinfos_LIBS
2407                 ui
2408                 wiretap
2409                 wsutil
2410                 ${ZLIB_LIBRARIES}
2411                 ${GCRYPT_LIBRARIES}
2412                 ${CMAKE_DL_LIBS}
2413         )
2414         set(capinfos_FILES
2415                 $<TARGET_OBJECTS:cli_main>
2416                 $<TARGET_OBJECTS:version_info>
2417                 capinfos.c
2418         )
2419         set_executable_resources(capinfos "Capinfos")
2420         add_executable(capinfos ${capinfos_FILES})
2421         set_extra_executable_properties(capinfos "Executables")
2422         target_link_libraries(capinfos ${capinfos_LIBS})
2423         install(TARGETS capinfos RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2424 endif()
2425
2426 if(BUILD_captype)
2427         set(captype_LIBS
2428                 ui
2429                 wiretap
2430                 wsutil
2431                 ${ZLIB_LIBRARIES}
2432                 ${CMAKE_DL_LIBS}
2433         )
2434         set(captype_FILES
2435                 $<TARGET_OBJECTS:cli_main>
2436                 $<TARGET_OBJECTS:version_info>
2437                 captype.c
2438         )
2439         set_executable_resources(captype "Captype")
2440         add_executable(captype ${captype_FILES})
2441         set_extra_executable_properties(captype "Executables")
2442         target_link_libraries(captype ${captype_LIBS})
2443         install(TARGETS captype RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2444 endif()
2445
2446 if(BUILD_editcap)
2447         set(editcap_LIBS
2448                 ui
2449                 wiretap
2450                 ${ZLIB_LIBRARIES}
2451                 ${GCRYPT_LIBRARIES}
2452                 ${CMAKE_DL_LIBS}
2453         )
2454         set(editcap_FILES
2455                 $<TARGET_OBJECTS:cli_main>
2456                 $<TARGET_OBJECTS:version_info>
2457                 editcap.c
2458         )
2459         set_executable_resources(editcap "Editcap")
2460         add_executable(editcap ${editcap_FILES})
2461         set_extra_executable_properties(editcap "Executables")
2462         target_link_libraries(editcap ${editcap_LIBS})
2463         install(TARGETS editcap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2464 endif()
2465
2466 if(BUILD_dumpcap AND PCAP_FOUND)
2467         set(dumpcap_LIBS
2468                 writecap
2469                 wsutil
2470                 caputils
2471                 ui
2472                 ${PCAP_LIBRARIES}
2473                 ${CAP_LIBRARIES}
2474                 ${GLIB2_LIBRARIES}
2475                 ${GTHREAD2_LIBRARIES}
2476                 ${ZLIB_LIBRARIES}
2477                 ${APPLE_CORE_FOUNDATION_LIBRARY}
2478                 ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
2479         )
2480         set(dumpcap_FILES
2481                 $<TARGET_OBJECTS:capture_opts>
2482                 $<TARGET_OBJECTS:cli_main>
2483                 $<TARGET_OBJECTS:version_info>
2484                 dumpcap.c
2485                 ringbuffer.c
2486                 sync_pipe_write.c
2487         )
2488         set_executable_resources(dumpcap "Dumpcap" UNIQUE_RC)
2489         add_executable(dumpcap ${dumpcap_FILES})
2490         set_extra_executable_properties(dumpcap "Executables")
2491         target_link_libraries(dumpcap ${dumpcap_LIBS})
2492         install(TARGETS dumpcap
2493                         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
2494                         PERMISSIONS ${DUMPCAP_SETUID}
2495                                 OWNER_READ OWNER_WRITE OWNER_EXECUTE
2496                                 GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
2497         )
2498         if(ENABLE_DUMPCAP_GROUP)
2499                 install(CODE "execute_process(COMMAND chgrp ${DUMPCAP_INSTALL_GROUP} ${CMAKE_INSTALL_FULL_BINDIR}/dumpcap)")
2500                 install(CODE "execute_process(COMMAND chmod o-x ${CMAKE_INSTALL_FULL_BINDIR}/dumpcap)")
2501         endif()
2502         if(DUMPCAP_INSTALL_OPTION STREQUAL "capabilities")
2503                 install( CODE "execute_process(
2504                         COMMAND
2505                                 ${SETCAP_EXECUTABLE}
2506                                 cap_net_raw,cap_net_admin+ep
2507                                 ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/dumpcap${CMAKE_EXECUTABLE_SUFFIX}
2508                         RESULT_VARIABLE
2509                                 _SETCAP_RESULT
2510                         )
2511                         if( _SETCAP_RESULT )
2512                                 message( WARNING \"setcap failed (${_SETCAP_RESULT}).\")
2513                         endif()"
2514                 )
2515         endif()
2516 endif()
2517
2518 # We have two idl2wrs utilities: this and the CORBA version in tools.
2519 # We probably shouldn't do that.
2520 if(BUILD_dcerpcidl2wrs)
2521         set(idl2wrs_LIBS
2522                 ${GLIB2_LIBRARIES}
2523                 wsutil
2524         )
2525         set(idl2wrs_FILES
2526                 epan/dissectors/dcerpc/idl2wrs.c
2527         )
2528
2529         add_executable(idl2wrs ${idl2wrs_FILES})
2530         set_target_properties(idl2wrs PROPERTIES FOLDER "Executables")
2531         set_extra_executable_properties(idl2wrs "Executables")
2532         target_link_libraries(idl2wrs ${idl2wrs_LIBS})
2533         install(TARGETS idl2wrs RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2534 endif()
2535
2536 if (WIN32)
2537         find_package( MSVC_REDIST )
2538
2539         # Must come after executable targets are defined.
2540         find_package( NSIS )
2541
2542         if(MAKENSIS_EXECUTABLE)
2543                 add_subdirectory( packaging/nsis EXCLUDE_FROM_ALL )
2544                 ADD_NSIS_UNINSTALLER_TARGET()
2545                 ADD_NSIS_PACKAGE_TARGET()
2546         endif()
2547
2548         find_package( WiX )
2549
2550         if(WIX_CANDLE_EXECUTABLE)
2551                 add_subdirectory( packaging/wix EXCLUDE_FROM_ALL )
2552                 ADD_WIX_PACKAGE_TARGET()
2553         endif()
2554
2555         find_package( PortableApps )
2556         if(PORTABLEAPPS_LAUNCHER_GENERATOR_EXECUTABLE AND PORTABLEAPPS_INSTALLER_EXECUTABLE)
2557                 add_subdirectory( packaging/portableapps EXCLUDE_FROM_ALL )
2558                 ADD_PORTABLEAPPS_PACKAGE_TARGET()
2559         endif()
2560 endif()
2561
2562 if (MAXMINDDB_FOUND)
2563         set(mmdbresolve_LIBS
2564                 # Note: libmaxminddb is not GPL-2 compatible.
2565                 ${MAXMINDDB_LIBRARY}
2566         )
2567         set(mmdbresolve_FILES
2568                 mmdbresolve.c
2569         )
2570         add_executable(mmdbresolve ${mmdbresolve_FILES})
2571         set_extra_executable_properties(mmdbresolve "Executables")
2572         target_link_libraries(mmdbresolve ${mmdbresolve_LIBS})
2573         target_include_directories(mmdbresolve PUBLIC ${MAXMINDDB_INCLUDE_DIRS})
2574         target_compile_definitions(mmdbresolve PUBLIC ${MAXMINDDB_DEFINITIONS})
2575         install(TARGETS mmdbresolve RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
2576 endif()
2577
2578 if(ENABLE_APPLICATION_BUNDLE)
2579         add_custom_target(app_bundle)
2580         set_target_properties(app_bundle PROPERTIES FOLDER "Copy Tasks")
2581         add_custom_command(TARGET app_bundle
2582                 POST_BUILD
2583                 COMMAND "${CMAKE_BINARY_DIR}/packaging/macosx/osx-app.sh"
2584                 WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/run"
2585         )
2586         add_dependencies(app_bundle ${PROGLIST})
2587
2588         add_custom_target(dmg_package_prep DEPENDS app_bundle)
2589
2590         ADD_CUSTOM_COMMAND(
2591                 OUTPUT ${CMAKE_BINARY_DIR}/packaging/macosx/PkgInfo
2592                 COMMAND ${CMAKE_COMMAND} -E echo APPLWshk > ${CMAKE_BINARY_DIR}/packaging/macosx/PkgInfo
2593         )
2594
2595         ADD_CUSTOM_TARGET( dmg_package
2596                 COMMAND ${CMAKE_COMMAND} -E copy_directory
2597                                         ${CMAKE_SOURCE_DIR}/packaging/macosx/ChmodBPF
2598                                         ${CMAKE_BINARY_DIR}/run/ChmodBPF
2599                 COMMAND ${CMAKE_COMMAND} -E copy_directory
2600                                         ${CMAKE_SOURCE_DIR}/packaging/macosx/Scripts
2601                                         ${CMAKE_BINARY_DIR}/run/Scripts
2602                 COMMAND ${CMAKE_COMMAND} -E copy_directory
2603                                         ${CMAKE_SOURCE_DIR}/packaging/macosx/utility-launcher
2604                                         ${CMAKE_BINARY_DIR}/run/utility-launcher
2605                 COMMAND ${CMAKE_COMMAND} -E copy_if_different
2606                                         ${CMAKE_SOURCE_DIR}/COPYING
2607                                         ${CMAKE_BINARY_DIR}/run/COPYING.txt
2608                 COMMAND ${CMAKE_COMMAND} -E copy_directory
2609                                         ${CMAKE_SOURCE_DIR}/packaging/macosx/Wireshark_package.pmdoc
2610                                         ${CMAKE_BINARY_DIR}/run/Wireshark_package.pmdoc
2611                 COMMAND ${CMAKE_COMMAND} -E copy_if_different
2612                                         ${CMAKE_BINARY_DIR}/packaging/macosx/Wireshark_package.pmdoc/index.xml
2613                                         ${CMAKE_BINARY_DIR}/run/Wireshark_package.pmdoc/index.xml
2614                 COMMAND ${CMAKE_COMMAND} -E copy_if_different
2615                                         ${CMAKE_SOURCE_DIR}/packaging/macosx/dmg_background.png
2616                                         ${CMAKE_BINARY_DIR}/run/dmg_background.png
2617                 COMMAND bash -x ${CMAKE_BINARY_DIR}/packaging/macosx/osx-dmg.sh
2618                         --source-directory ${CMAKE_SOURCE_DIR}/packaging/macosx
2619                 # Unlike nsis_package_prep + nsis_package, we can add a direct
2620                 # dependency here.
2621                 DEPENDS dmg_package_prep
2622                 # We create Wireshark.app in "run". Do our work there.
2623                 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/run
2624         )
2625
2626 endif()
2627
2628 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
2629         find_program(RPMBUILD_EXECUTABLE rpmbuild)
2630         find_program(DPKG_BUILDPACKAGE_EXECUTABLE dpkg-buildpackage)
2631         find_program(GIT_EXECUTABLE git)
2632         # Should we add appimaged's monitored directories
2633         # as HINTS?
2634         # https://github.com/AppImage/appimaged
2635         find_program(LINUXDEPLOYQT_EXECUTABLE linuxdeployqt)
2636         find_program(APPIMAGETOOL_EXECUTABLE appimagetool)
2637 endif()
2638
2639
2640 string(REPLACE "-" "_" RPM_VERSION "${VERSION}")
2641 configure_file(packaging/rpm/wireshark.spec.in ${CMAKE_BINARY_DIR}/packaging/rpm/SPECS/wireshark.spec)
2642 if(RPMBUILD_EXECUTABLE)
2643         foreach(_rpm_dir BUILD RPMS SOURCES SPECS SRPMS)
2644                 file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/packaging/rpm/${_rpm_dir}")
2645         endforeach()
2646
2647         set(_rpmbuild_with_args)
2648         if(CMAKE_GENERATOR STREQUAL "Ninja")
2649                 list(APPEND _rpmbuild_with_args --with ninja)
2650         endif()
2651         if(CCACHE_EXECUTABLE)
2652                 list(APPEND _rpmbuild_with_args --with ccache)
2653         endif()
2654         if (BUILD_wireshark)
2655                 list(APPEND _rpmbuild_with_args --with qt5)
2656         endif()
2657         if (MAXMINDDB_FOUND)
2658                 list(APPEND _rpmbuild_with_args --with mmdbresolve)
2659         endif()
2660         if (LUA_FOUND)
2661                 list(APPEND _rpmbuild_with_args --with lua)
2662         endif()
2663         if (LZ4_FOUND AND SNAPPY_FOUND)
2664                 list(APPEND _rpmbuild_with_args --with lz4_and_snappy)
2665         endif()
2666         if (CARES_FOUND)
2667                 list(APPEND _rpmbuild_with_args --with c_ares)
2668         endif()
2669         if (SPANDSP_FOUND)
2670                 list(APPEND _rpmbuild_with_args --with spandsp)
2671         endif()
2672         if (BCG729_FOUND)
2673                 list(APPEND _rpmbuild_with_args --with bcg729)
2674         endif()
2675         if (LIBXML2_FOUND)
2676                 list(APPEND _rpmbuild_with_args --with libxml2)
2677         endif()
2678         if (NGHTTP2_FOUND)
2679                 list(APPEND _rpmbuild_with_args --with nghttp2)
2680         endif()
2681         if (SYSTEMD_FOUND)
2682                 list(APPEND _rpmbuild_with_args --with sdjournal)
2683         endif()
2684
2685         execute_process(
2686                 COMMAND ${PERL_EXECUTABLE}
2687                         ${CMAKE_SOURCE_DIR}/tools/make-version.pl
2688                         ${CMAKE_SOURCE_DIR}
2689         )
2690
2691         # XXX Replace with the "dist" target?
2692         set(_export_tarball "${CPACK_PACKAGE_NAME}-${VERSION}.tar.xz")
2693         add_custom_command(
2694                 OUTPUT "${CMAKE_BINARY_DIR}/packaging/rpm/SOURCES/${_export_tarball}"
2695                 COMMAND ${CMAKE_BINARY_DIR}/packaging/source/git-export-release.sh
2696                         -d "${CMAKE_BINARY_DIR}/packaging/rpm/SOURCES"
2697                         "${VERSION}"
2698                 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
2699         )
2700         add_custom_target(rpm-package
2701                 COMMAND ${RPMBUILD_EXECUTABLE}
2702                         --define "_topdir ${CMAKE_BINARY_DIR}/packaging/rpm"
2703                         --define "_prefix ${CMAKE_INSTALL_PREFIX}"
2704                         ${_rpmbuild_with_args}
2705                         -ba SPECS/wireshark.spec
2706                 DEPENDS "${CMAKE_BINARY_DIR}/packaging/rpm/SOURCES/${_export_tarball}"
2707                 WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/packaging/rpm"
2708                 COMMENT "Create a tarball from the current git commit."
2709         )
2710 endif()
2711
2712 if(DPKG_BUILDPACKAGE_EXECUTABLE)
2713         add_custom_target(deb-package
2714                 COMMAND ${DPKG_BUILDPACKAGE_EXECUTABLE} -us -uc
2715                 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
2716         )
2717 endif()
2718
2719 if(LINUXDEPLOYQT_EXECUTABLE AND APPIMAGETOOL_EXECUTALBE)
2720         # The documentation at https://github.com/probonopd/linuxdeployqt
2721         # says that you need to set CMAKE_BUILD_TYPE=Release and
2722         # CMAKE_INSTALL_PREFIX=/usr. I (gcc) also had to set
2723         # CMAKE_INSTALL_LIBDIR=/usr/lib.
2724         if (CMAKE_BUILD_TYPE STREQUAL "Release" AND CMAKE_INSTALL_PREFIX STREQUAL "/usr" AND CMAKE_INSTALL_LIBDIR STREQUAL "/usr/lib" )
2725                 add_custom_target(appimage-prerequisites)
2726                 add_dependencies(appimage-prerequisites ${PROGLIST})
2727         else()
2728                 add_custom_target(appimage-prerequisites
2729                         COMMAND echo "CMAKE_BUILD_TYPE isn't Release or CMAKE_INSTALL_PREFIX isn't /usr or CMAKE_INSTALL_LIBDIR isn't /usr/lib."
2730                         COMMAND false
2731                 )
2732         endif()
2733         set (_ai_appdir "${CMAKE_BINARY_DIR}/packaging/appimage/appdir")
2734         add_custom_target(appimage-appdir
2735                 COMMAND ${CMAKE_COMMAND} -E make_directory "${_ai_appdir}"
2736                 COMMAND env DESTDIR=${_ai_appdir}
2737                         ${CMAKE_COMMAND} --build . --target install
2738                 DEPENDS appimage-prerequisites
2739         )
2740         set(_exe_args)
2741         foreach(_prog ${PROGLIST})
2742                 # XXX Is this the correct path?
2743                 list(APPEND _exe_args "-executable=${_ai_appdir}/usr/bin/${_prog}")
2744         endforeach()
2745         # linuxdeployqt currently clobbers AppRun:
2746         # https://github.com/probonopd/linuxdeployqt/issues/159
2747         # When that's fixed we will no longer need appimagetool. Until
2748         # then, we need to prep and package in two steps:
2749         # https://github.com/probonopd/linuxdeployqt/wiki/Custom-wrapper-script-instead-of-AppRun
2750         add_custom_target(appimage-prep
2751                 COMMAND ${LINUXDEPLOYQT_EXECUTABLE}
2752                         "${_ai_appdir}/usr/share/applications/wireshark.desktop"
2753                         ${_exe_args}
2754                 COMMAND rm -f "${_ai_appdir}/AppRun"
2755                 COMMAND install
2756                         "${CMAKE_SOURCE_DIR}/packaging/appimage/AppRun"
2757                         "${_ai_appdir}/AppRun"
2758                 DEPENDS appimage-appdir
2759         )
2760         add_custom_target(appimage
2761                 COMMAND env VERSION=${PROJECT_VERSION} ${APPIMAGETOOL_EXECUTABLE} appdir
2762                 WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/packaging/appimage"
2763                 DEPENDS appimage-prep
2764         )
2765 endif()
2766
2767 set(CLEAN_C_FILES
2768         ${dumpcap_FILES}
2769         ${wireshark_FILES}
2770         ${tshark_FILES}
2771         ${rawshark_FILES}
2772         ${dftest_FILES}
2773         ${randpkt_FILES}
2774         ${randpktdump_FILES}
2775         ${udpdump_FILES}
2776         ${text2pcap_FILES}
2777         ${mergecap_FILES}
2778         ${capinfos_FILES}
2779         ${captype_FILES}
2780         ${editcap_FILES}
2781         ${idl2wrs_FILES}
2782         ${mmdbresolve_FILES}
2783 )
2784
2785 # Make sure we don't pass /WX to rc.exe. Rc doesn't have a /WX flag,
2786 # but it does have /W (warn about invalid code pages) and /X (ignore
2787 # the INCLUDE environment variable).
2788 # This should apparently be handled for us via CMAKE_RC_FLAG_REGEX
2789 # in CMakeRCInformation.cmake but that doesn't appear to work.
2790 if (WIN32)
2791         list(FILTER CLEAN_C_FILES EXCLUDE REGEX ".*\\.rc")
2792 endif (WIN32)
2793
2794 # XXX This also contains object files ($<TARGET_OBJECTS:...>), is that an issue?
2795 set_source_files_properties(
2796         ${CLEAN_C_FILES}
2797         PROPERTIES
2798         COMPILE_FLAGS "${WERROR_COMMON_FLAGS}"
2799 )
2800
2801 install(
2802         FILES
2803                 ${INSTALL_FILES}
2804         PERMISSIONS
2805                 OWNER_WRITE OWNER_READ
2806                 GROUP_READ
2807                 WORLD_READ
2808         DESTINATION
2809                 ${CMAKE_INSTALL_DATADIR}
2810 )
2811
2812 set(SHARK_PUBLIC_HEADERS
2813         cfile.h
2814         cli_main.h
2815         file.h
2816         globals.h
2817         log.h
2818         ws_attributes.h
2819         ws_compiler_tests.h
2820         ws_diag_control.h
2821         ws_symbol_export.h
2822         version_info.h
2823         ${CMAKE_BINARY_DIR}/ws_version.h
2824 )
2825
2826 install(FILES ${SHARK_PUBLIC_HEADERS}
2827         DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${CPACK_PACKAGE_NAME}
2828 )
2829
2830 # Install icons and other desktop files for Freedesktop.org-compliant desktops.
2831 if((BUILD_wireshark AND QT_FOUND) AND NOT (WIN32 OR APPLE))
2832         install(FILES wireshark-mime-package.xml
2833                 DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/mime/packages"
2834                 RENAME wireshark.xml
2835         )
2836         install(FILES wireshark.appdata.xml
2837                 DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/appdata"
2838         )
2839         if(BUILD_wireshark AND QT_FOUND)
2840                 install(FILES wireshark.desktop
2841                         DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications")
2842         endif()
2843         foreach(size 16 24 32 48 64 128 256)
2844                 install(FILES image/wsicon${size}.png
2845                         DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/${size}x${size}/apps"
2846                         RENAME wireshark.png)
2847                 install(FILES image/WiresharkDoc-${size}.png
2848                         DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/${size}x${size}/mimetypes"
2849                         RENAME application-wireshark-doc.png)
2850         endforeach()
2851         install(FILES image/wsicon.svg
2852                 DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/apps"
2853                 RENAME wireshark.svg)
2854 endif()
2855
2856 install(
2857         FILES
2858                 "${CMAKE_BINARY_DIR}/wireshark.pc"
2859         DESTINATION
2860                 ${CMAKE_INSTALL_LIBDIR}/pkgconfig
2861 )
2862
2863 install(
2864         DIRECTORY
2865                 ${INSTALL_DIRS}
2866         DESTINATION
2867                 ${CMAKE_INSTALL_DATADIR}
2868         FILE_PERMISSIONS
2869                 OWNER_WRITE OWNER_READ
2870                 GROUP_READ
2871                 WORLD_READ
2872         DIRECTORY_PERMISSIONS
2873                 OWNER_EXECUTE OWNER_WRITE OWNER_READ
2874                 GROUP_EXECUTE GROUP_READ
2875                 WORLD_EXECUTE WORLD_READ
2876         PATTERN ".git" EXCLUDE
2877         PATTERN ".svn" EXCLUDE
2878         PATTERN "Makefile.*" EXCLUDE
2879 )
2880
2881 if(WIN32)
2882         # Note: CMake export mechanism misbehaves with a '.' in the
2883         # path (incorrect relative path computation).
2884         set(WIRESHARK_INSTALL_CMAKEDIR "cmake")
2885 else()
2886         set(WIRESHARK_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/${CPACK_PACKAGE_NAME}/cmake")
2887 endif()
2888
2889 install(
2890         FILES
2891                 ${CMAKE_MODULE_PATH}/FindGLIB2.cmake
2892                 ${CMAKE_MODULE_PATH}/FindWSWinLibs.cmake
2893                 ${CMAKE_MODULE_PATH}/UseAsn2Wrs.cmake
2894                 ${CMAKE_MODULE_PATH}/LocatePythonModule.cmake
2895                 ${CMAKE_MODULE_PATH}/UseMakePluginReg.cmake
2896         DESTINATION
2897                 ${WIRESHARK_INSTALL_CMAKEDIR}
2898 )
2899
2900 include(CMakePackageConfigHelpers)
2901
2902 configure_package_config_file(WiresharkConfig.cmake.in
2903         ${CMAKE_BINARY_DIR}/WiresharkConfig.cmake
2904         INSTALL_DESTINATION ${WIRESHARK_INSTALL_CMAKEDIR}
2905         PATH_VARS
2906                 CMAKE_INSTALL_LIBDIR
2907                 CMAKE_INSTALL_INCLUDEDIR
2908                 PLUGIN_INSTALL_VERSION_LIBDIR
2909                 EXTCAP_INSTALL_LIBDIR
2910 )
2911
2912 write_basic_package_version_file(
2913         ${CMAKE_BINARY_DIR}/WiresharkConfigVersion.cmake
2914         COMPATIBILITY AnyNewerVersion
2915 )
2916
2917 install(
2918         FILES
2919                 ${CMAKE_BINARY_DIR}/WiresharkConfig.cmake
2920                 ${CMAKE_BINARY_DIR}/WiresharkConfigVersion.cmake
2921         DESTINATION
2922                 ${WIRESHARK_INSTALL_CMAKEDIR}
2923 )
2924
2925 install(EXPORT WiresharkTargets
2926         DESTINATION ${WIRESHARK_INSTALL_CMAKEDIR}
2927 )
2928
2929 if (DOXYGEN_EXECUTABLE)
2930         # API reference
2931         # We don't have a good way of tracking dependencies, so we simply
2932         # recreate the whole thing from scratch each time.
2933         add_custom_target(wsar_html
2934                 COMMAND ${CMAKE_COMMAND} -E remove_directory wsar_html
2935                 COMMAND ${DOXYGEN_EXECUTABLE} doxygen.cfg
2936         )
2937
2938         add_custom_target(wsar_html_zip
2939                 COMMAND ${CMAKE_COMMAND} -E tar "cfv" "wsar_html.zip" --format=zip wsar_html
2940                 DEPENDS wsar_html
2941         )
2942         set_target_properties(wsar_html wsar_html_zip PROPERTIES
2943                 FOLDER "Docs"
2944                 EXCLUDE_FROM_DEFAULT_BUILD True
2945         )
2946 endif(DOXYGEN_EXECUTABLE)
2947
2948 add_custom_target(test-programs
2949         DEPENDS exntest
2950                 oids_test
2951                 reassemble_test
2952                 tvbtest
2953                 wmem_test
2954         COMMENT "Building unit test programs and wrapper"
2955 )
2956 set_target_properties(test-programs PROPERTIES
2957         FOLDER "Tests"
2958         EXCLUDE_FROM_DEFAULT_BUILD True
2959 )
2960
2961 # Test suites
2962 enable_testing()
2963 # We could try to build this list dynamically, but given that we tend to
2964 # go years between adding suites just run
2965 #     test/test.py --list-groups | sort
2966 # and paste the output here.
2967 set(_test_group_list
2968         suite_capture
2969         suite_clopts
2970         suite_decryption
2971         suite_dfilter.group_bytes_ether
2972         suite_dfilter.group_bytes_ipv6
2973         suite_dfilter.group_bytes_type
2974         suite_dfilter.group_double
2975         suite_dfilter.group_dfunction_string
2976         suite_dfilter.group_integer
2977         suite_dfilter.group_integer_1byte
2978         suite_dfilter.group_ipv4
2979         suite_dfilter.group_membership
2980         suite_dfilter.group_range_method
2981         suite_dfilter.group_scanner
2982         suite_dfilter.group_string_type
2983         suite_dfilter.group_stringz
2984         suite_dfilter.group_time_relative
2985         suite_dfilter.group_time_type
2986         suite_dfilter.group_tvb
2987         suite_dfilter.group_uint64
2988         suite_dissection
2989         suite_dissectors.group_asterix
2990         suite_fileformats
2991         suite_follow
2992         suite_io
2993         suite_mergecap
2994         suite_nameres
2995         suite_outputformats
2996         suite_text2pcap
2997         suite_sharkd
2998         suite_unittests
2999         suite_wslua
3000 )
3001
3002 # We don't currently handle spaces in arguments. On Windows this
3003 # means that you will probably have to pass in an interface index
3004 # instead of a name.
3005 set(TEST_EXTRA_ARGS "" CACHE STRING "Extra arguments to pass to test/test.py")
3006 separate_arguments(TEST_EXTRA_ARGS)
3007
3008 foreach(_group_name ${_test_group_list})
3009         add_test(
3010                 NAME ${_group_name}
3011                 COMMAND ${CMAKE_COMMAND} -E env PYTHONIOENCODING=UTF-8
3012                         ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/test/test.py
3013                         --verbose
3014                         --program-path ${WS_PROGRAM_PATH}
3015                         ${TEST_EXTRA_ARGS}
3016                         ${_group_name}
3017                 )
3018         set_tests_properties(${_group_name} PROPERTIES TIMEOUT 600)
3019 endforeach()
3020
3021 # Make it possible to run pytest without passing the full path as argument.
3022 if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
3023         file(READ "${CMAKE_CURRENT_SOURCE_DIR}/pytest.ini" pytest_ini)
3024         string(REGEX REPLACE "\naddopts = ([^\n]+)"
3025                 "\naddopts = ${CMAKE_CURRENT_SOURCE_DIR}/test \\1"
3026                 pytest_ini "${pytest_ini}")
3027         file(WRITE "${CMAKE_BINARY_DIR}/pytest.ini" "${pytest_ini}")
3028 endif()
3029
3030 if (GIT_EXECUTABLE)
3031         # Update AUTHORS file with entries from git shortlog
3032         add_custom_target(
3033                 gen-authors
3034                 COMMAND ${PERL_EXECUTABLE} tools/generate_authors.pl AUTHORS.src > AUTHORS
3035                 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
3036         )
3037 else (GIT_EXECUTABLE)
3038         add_custom_target( gen-authors COMMAND ${CMAKE_COMMAND} -E echo "Git not found." )
3039 endif (GIT_EXECUTABLE)
3040 set_target_properties(gen-authors PROPERTIES FOLDER "Docs")
3041
3042 if (WIN32)
3043         file (TO_NATIVE_PATH ${CMAKE_SOURCE_DIR}/tools/Get-HardenFlags.ps1 _win_harden_flags)
3044         add_custom_target(hardening-check
3045                 COMMAND ${POWERSHELL_COMMAND} "${_win_harden_flags}" "${_dll_output_dir_win}"
3046                 DEPENDS ${PROGLIST}
3047                 COMMENT "Checking binaries for security features"
3048         )
3049         set_target_properties(hardening-check PROPERTIES FOLDER "Tests")
3050 else ()
3051         find_program(HARDENING_CHECK_EXECUTABLE hardening-check
3052                 DOC "Path to the hardening-check utility."
3053         )
3054         if(HARDENING_CHECK_EXECUTABLE)
3055                 foreach(_prog ${PROGLIST})
3056                         get_target_property(_prog_dir ${_prog} RUNTIME_OUTPUT_DIRECTORY)
3057                         if(NOT _prog_dir)
3058                                 set(_prog_dir "${CMAKE_BINARY_DIR}/run")
3059                         endif()
3060                         set(_prog_paths ${_prog_paths} "${_prog_dir}/${_prog}")
3061                 endforeach()
3062                 add_custom_target(hardening-check
3063                         COMMAND ${HARDENING_CHECK_EXECUTABLE} ${_prog_paths}
3064                         DEPENDS ${PROGLIST}
3065                         COMMENT "Checking binaries for security features"
3066                 )
3067         endif()
3068 endif()
3069
3070 CHECKAPI(
3071         NAME
3072           main
3073         SWITCHES
3074           -build
3075         SOURCES
3076           ${WIRESHARK_SRC}
3077           ${TSHARK_TAP_SRC}
3078 )
3079
3080 find_program(SHELLCHECK_EXECUTABLE shellcheck
3081         DOC "Path to the shellcheck utility."
3082 )
3083 if(SHELLCHECK_EXECUTABLE)
3084         add_custom_target(shellcheck)
3085         set_target_properties(shellcheck PROPERTIES FOLDER "Tests")
3086         # --external-sources requires 0.4.0 or later.
3087         add_custom_command(TARGET shellcheck POST_BUILD
3088                 COMMAND shellcheck --external-sources
3089                         image/stock_icons/svg-to-png.sh
3090                         packaging/appimage/AppRun
3091                         packaging/macosx/osx-app.sh.in
3092                         packaging/macosx/osx-dmg.sh.in
3093                         packaging/source/git-export-release.sh.in
3094                         tools/compress-pngs.sh
3095                         tools/debian-setup.sh
3096                         tools/fuzz-test.sh
3097                         tools/gen-bugnote
3098                         tools/pre-commit
3099                         tools/randpkt-test.sh
3100                         tools/release-update-debian-soversions.sh
3101                         tools/test-captures.sh
3102                         tools/update-tx
3103                         tools/valgrind-wireshark.sh
3104                 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
3105         )
3106 endif()
3107
3108 #
3109 # Editor modelines  -  http://www.wireshark.org/tools/modelines.html
3110 #
3111 # Local variables:
3112 # c-basic-offset: 8
3113 # tab-width: 8
3114 # indent-tabs-mode: t
3115 # End:
3116 #
3117 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
3118 # :indentSize=8:tabSize=8:noTabs=false:
3119 #