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