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