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