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