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