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