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