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