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