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