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