Clean up a warning.
[metze/wireshark/wip.git] / CMakeLists.txt
index 96b013892abd13f6b727e147e3efc77eb604b4c3..78b662d90fa2153a476db32e6bd5acdc28fe8cde 100644 (file)
@@ -4,19 +4,7 @@
 # By Gerald Combs <gerald@wireshark.org>
 # Copyright 1998 Gerald Combs
 #
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# SPDX-License-Identifier: GPL-2.0-or-later
 #
 
 project(Wireshark C CXX)
@@ -24,8 +12,8 @@ project(Wireshark C CXX)
 # Updated by make-version.pl
 set(GIT_REVISION 0)
 set(PROJECT_MAJOR_VERSION 2)
-set(PROJECT_MINOR_VERSION 5)
-set(PROJECT_PATCH_VERSION 1)
+set(PROJECT_MINOR_VERSION 9)
+set(PROJECT_PATCH_VERSION 0)
 set(PROJECT_BUILD_VERSION ${GIT_REVISION})
 set(PROJECT_VERSION_EXTENSION "")
 set(PROJECT_RELEASE_VERSION "${PROJECT_MAJOR_VERSION}.${PROJECT_MINOR_VERSION}")
@@ -335,8 +323,10 @@ if( CMAKE_C_COMPILER_ID MATCHES "MSVC")
                # /Zo                               Enhanced debugging of optimised code for VS2013 Update 3 and beyond,
                #                                   Assume all VS2013 builds are at least Update 3.
                #                                   See http://msdn.microsoft.com/en-us/library/dn785163.aspx
-               set(LOCAL_CFLAGS ${LOCAL_CFLAGS} /Zo)
+               list(APPEND LOCAL_CFLAGS /Zo)
        elseif(MSVC14)
+               # To do: Add /external:... See https://blogs.msdn.microsoft.com/vcblog/2017/12/13/broken-warnings-theory/
+               #
                # /Zo                               Enhanced debugging of optimised code
                # /utf-8                            Set Source and Executable character sets to UTF-8
                #                                   VS2015(MSVC14): On by default when /Zi or /Z7 used.
@@ -346,26 +336,28 @@ if( CMAKE_C_COMPILER_ID MATCHES "MSVC")
                #                                   https://gitlab.kitware.com/cmake/cmake/commit/f973d49ab9d4c59b93f6dac812a94bb130200836
                # /Qspectre                         Speculative execution attack mitigation
                #                                   See https://blogs.msdn.microsoft.com/vcblog/2018/01/15/spectre-mitigations-in-msvc/
-               set(LOCAL_CFLAGS ${LOCAL_CFLAGS} /Zo /utf-8 /guard:cf /Qspectre)
+               list(APPEND LOCAL_CFLAGS /Zo /utf-8 /guard:cf /Qspectre)
                set(WS_LINK_FLAGS "${WS_LINK_FLAGS} /guard:cf")
        endif()
 
        if(ENABLE_CODE_ANALYSIS)
-               set(LOCAL_CFLAGS ${LOCAL_CFLAGS} /analyze:WX-)
+               list(APPEND LOCAL_CFLAGS /analyze:WX-)
        endif()
 
        # Additional compiler warnings to be treated as "Level 3"
-       #  when compiling Wireshark sources. (Selected from "level 4" warnings).
+       # when compiling Wireshark sources. (Selected from "level 4" warnings).
        ## 4295: array is too small to include a terminating null character
        ## 4189: local variable is initialized but not referenced
        # Disable warnings about about use of flexible array members:
        ## 4200: nonstandard extension used : zero-sized array in struct/union
-       set(WARNINGS_CFLAGS /w34295 /w34189 /wd4200)
+       list(APPEND LOCAL_CFLAGS /w34295 /w34189 /wd4200)
 
-       set(WIRESHARK_COMMON_FLAGS
-               ${LOCAL_CFLAGS}
-               ${WARNINGS_CFLAGS}
-       )
+       # We've matched these to specific compiler versions using the
+       # checks above. There's no need to pass them to check_c_compiler_flag
+       # or check_cxx_compiler_flag, which can be slow.
+       string(REPLACE ";" " " _flags "${LOCAL_CFLAGS}")
+       set(CMAKE_C_FLAGS "${_flags} ${CMAKE_C_FLAGS}")
+       set(CMAKE_CXX_FLAGS "${_flags} ${CMAKE_CXX_FLAGS}")
 
 else() # ! MSVC
        if(CMAKE_OSX_DEPLOYMENT_TARGET)
@@ -393,41 +385,79 @@ else() # ! MSVC
                endif()
        endif()
 
-       if(CMAKE_VERSION VERSION_LESS "3.1")
-               # Many modern compilers use c99 by default, but for older ones
-               # (like GCC 4.4.7), -std=gnu99 is required to avoid errors about
-               # use constructs like "for (int i = 0; i < n; i++) ;"
+       #
+       # Do whatever is necessary to enable as much C99 support as
+       # possible in the C compiler.  Newer versions of compilers
+       # might default to supporting C99, but older versions may
+       # require a special flag.
+       #
+       # We do not want strict C99 support, as we may also want to
+       # use compiler extensions.
+       #
+       # Prior to CMake 3.1, setting CMAKE_C_STANDARD will not have
+       # any effect, so, unless and until we require CMake 3.1 or
+       # later, we have to do it ourselves on pre-3.1 CMake, so we
+       # just do it ourselves on all versions of CMake.
+       #
+       # Note: with CMake 3.1 through 3.5, the only compilers for
+       # which CMake handles CMAKE_C_STANDARD are GCC and Clang.
+       # 3.6 adds support only for Intel C; 3.9 adds support for
+       # PGI C, Sun C, and IBM XL C, and 3.10 adds support for
+       # Cray C and IAR C, but no version of CMake has support for
+       # HP C.  Therefore, even if we use CMAKE_C_STANDARD with
+       # compilers for which CMake supports it, we may still have
+       # to do it ourselves on other compilers.
+       #
+       # See the CMake documentation for the CMAKE_<LANG>_COMPILER_ID
+       # variables for a list of compiler IDs.
+       #
+       # We don't worry about MSVC; it doesn't have such a flag -
+       # either it doesn't support the C99 features we need at all,
+       # or it supports them regardless of the compiler flag.
+       #
+       # XXX - we add the flag for a given compiler to CMAKE_C_FLAGS,
+       # so we test whether it works and add it if we do.  We don't
+       # test whether it's necessary in order to get the C99 features
+       # that we use; if we ever have a user who tries to compile with
+       # a compiler that can't be made to support those features, we
+       # can add a test to make sure we actually *have* C99 support.
+       #
+       if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR
+          CMAKE_C_COMPILER_ID MATCHES "Clang")
                #
-               # Older versions of IBM XL C may require -qlanglvl=extc99.
-               # With V7.0, the "xlc" command defaults to C89; with 10.1,
-               # it defaults to C99 (both with IBM syntax extensions).
+               # We use -std=gnu99 rather than -std=c99 because, for
+               # some older compilers such as GCC 4.4.7, -std=gnu99
+               # is required to avoid errors about C99 constructs
+               # such as "for (int i = 0; i < n; i++) ;".
                #
-               # HP's manual for HP C/HP-UX B.11.11.04 (the tenth
-               # edition of the manual), for PA-RISC, "documents
-               # new HP C features that support C99 industry standards".
-               # The manual for Version A.06.25 for Itanium mentions an
-               # -AC99 flag to support C99, but says it's the default;
-               # some older versions might require -AC99.
+               set(CMAKE_C_FLAGS "-std=gnu99 ${CMAKE_C_FLAGS}")
+       elseif(CMAKE_C_COMPILER_ID MATCHES "XL")
                #
-               # As of Sun Studio 8, the compiler appears to default
-               # to supporting some C99 language features, but not
-               # C99 library differences from C89; -xc99 will give
-               # you both.  The earlier Sun Forte Developer 6 update 2
-               # might or might not support thosee C99 language features
-               # by default, and doesn't speak of library differences;
-               # if it doesn't support the language features by default,
-               # -xc99 will support them.
+               # We want support for extensions picked up for
+               # GNU C compatibility, so we use -qlanglvl=extc99.
                #
-               if(CMAKE_C_COMPILER_ID MATCHES "GNU")
-                       set(CMAKE_C_FLAGS "-std=gnu99 ${CMAKE_C_FLAGS}")
-               endif()
-       else()
+               set(CMAKE_C_FLAGS "-qlanglvl=extc99 ${CMAKE_C_FLAGS}")
+       elseif(CMAKE_C_COMPILER_ID MATCHES "HP")
                #
-               # Current versions of CMake do not support options to
-               # request C99 for XL C, HP C, or Oracle C.  (They may
-               # not be necessary for current versions.)
+               # We also need to add -Wp,-H200000 to handle some large
+               # #defines we have; that flag is not necessary for the
+               # C++ compiler unless the "legacy" C++ preprocessor is
+               # being used (+legacy_cpp).  We don't want the legacy
+               # preprocessor if it's not the default, so we just add
+               # -Wp,-H200000 to the C flags.  (If there are older
+               # versions of aC++ that only support the legacy
+               # preprocessor, and require that we boost the table
+               # size, we'd have to check whether -Wp,-H200000 is
+               # supported by the C++ compiler and add it only if it is.)
                #
-               set(CMAKE_C_STANDARD 99)
+               set(CMAKE_C_FLAGS "-AC99 -Wp,-H200000 $WS_CFLAGS ${CMAKE_C_FLAGS}")
+       elseif(CMAKE_C_COMPILER_ID MATCHES "Sun")
+               #
+               # We also crank up the warning level.
+               #
+               set(CMAKE_C_FLAGS "-xc99 -v ${CMAKE_C_FLAGS}")
+       elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
+               set(CMAKE_C_FLAGS "-c99 ${CMAKE_C_FLAGS}")
        endif()
 
        if(CMAKE_C_COMPILER_ID MATCHES "Clang")
@@ -845,11 +875,11 @@ endif()
 # - set HAVE_XXX
 
 # The minimum package list
-set(PACKAGELIST Git GLIB2 GMODULE2 GTHREAD2 GCRYPT LEX YACC Perl SH PythonInterp)
+set(PACKAGELIST Git GLIB2 GMODULE2 GTHREAD2 GCRYPT LEX YACC Perl PythonInterp)
 set(LEX_OPTIONS REQUIRED)
 set(GLIB2_OPTIONS REQUIRED)
 set(GLIB2_FIND_OPTIONS REQUIRED)
-set(GLIB2_MIN_VERSION 2.22.0)
+set(GLIB2_MIN_VERSION 2.32.0)
 set(GTHREAD2_OPTIONS REQUIRED)
 set(GCRYPT_OPTIONS "1.4.2" REQUIRED)
 set(PythonInterp_FIND_VERSION 2)
@@ -864,6 +894,8 @@ endif()
 set(PACKAGELIST ${PACKAGELIST} LIBSSH)
 set(LIBSSH_OPTIONS "0.6")
 
+set(PACKAGELIST ${PACKAGELIST} JSONGLIB)
+
 if(ENABLE_PCAP)
        set(PACKAGELIST ${PACKAGELIST} PCAP)
 endif()
@@ -872,54 +904,35 @@ if(ENABLE_AIRPCAP)
        set(PACKAGELIST ${PACKAGELIST} AIRPCAP)
 endif()
 
-# Build the GTK-GUI?
-if(BUILD_wireshark_gtk)
-       if(ENABLE_GTK3)
-               set(PACKAGELIST ${PACKAGELIST} GTK3)
-       else()
-               set(PACKAGELIST ${PACKAGELIST} GTK2)
-               set(GTK2_OPTIONS COMPONENTS gtk)
-               set(GTK2_FIND_VERSION 2.12)
-               set(GTK2_DEBUG false)
-       endif()
-endif()
-
 # Build the Qt GUI?
 if(BUILD_wireshark)
-       if(ENABLE_QT5)
-               # Untested, may not work if CMAKE_PREFIX_PATH gets overwritten
-               # somewhere. The if WIN32 in this place is annoying as well.
-               if( WIN32 )
-                       set( QT5_BASE_PATH "$ENV{QT5_BASE_DIR}" )
-                       set( CMAKE_PREFIX_PATH "${QT5_BASE_PATH}" )
-               endif()
-               set(PACKAGELIST ${PACKAGELIST}
-                       Qt5Core
-                       Qt5LinguistTools
-                       Qt5Multimedia
-                       Qt5PrintSupport
-                       Qt5Svg
-                       Qt5Widgets
-               )
-               set(Qt5Core_OPTIONS REQUIRED)
-               set(Qt5LinguistTools_OPTIONS REQUIRED)
-               set(Qt5Multimedia_OPTIONS REQUIRED)
-               set(Qt5PrintSupport_OPTIONS REQUIRED)
-               set(Qt5Svg_OPTIONS REQUIRED)
-               set(Qt5Widgets_OPTIONS REQUIRED)
-               if (APPLE)
-                       set(PACKAGELIST ${PACKAGELIST} Qt5MacExtras)
-                       set(Qt5MacExtras_OPTIONS REQUIRED)
-               endif()
-               if( WIN32 )
-                       set(PACKAGELIST ${PACKAGELIST} Qt5WinExtras)
-                       set(Qt5WinExtras_OPTIONS REQUIRED)
-               endif()
-               set(QT_VERSION 5)
-       else()
-               set(PACKAGELIST ${PACKAGELIST} Qt4)
-               set(Qt4_OPTIONS 4.8 REQUIRED QtCore QtGui)
-               set(QT_VERSION 4)
+       # Untested, may not work if CMAKE_PREFIX_PATH gets overwritten
+       # somewhere. The if WIN32 in this place is annoying as well.
+       if( WIN32 )
+               set( QT5_BASE_PATH "$ENV{QT5_BASE_DIR}" )
+               set( CMAKE_PREFIX_PATH "${QT5_BASE_PATH}" )
+       endif()
+       set(PACKAGELIST ${PACKAGELIST}
+               Qt5Core
+               Qt5LinguistTools
+               Qt5Multimedia
+               Qt5PrintSupport
+               Qt5Svg
+               Qt5Widgets
+       )
+       set(Qt5Core_OPTIONS REQUIRED)
+       set(Qt5LinguistTools_OPTIONS REQUIRED)
+       set(Qt5Multimedia_OPTIONS REQUIRED)
+       set(Qt5PrintSupport_OPTIONS REQUIRED)
+       set(Qt5Svg_OPTIONS REQUIRED)
+       set(Qt5Widgets_OPTIONS REQUIRED)
+       if (APPLE)
+               set(PACKAGELIST ${PACKAGELIST} Qt5MacExtras)
+               set(Qt5MacExtras_OPTIONS REQUIRED)
+       endif()
+       if( WIN32 )
+               set(PACKAGELIST ${PACKAGELIST} Qt5WinExtras)
+               set(Qt5WinExtras_OPTIONS REQUIRED)
        endif()
 endif()
 
@@ -945,12 +958,6 @@ if(ENABLE_KERBEROS)
        set(PACKAGELIST ${PACKAGELIST} KERBEROS)
 endif()
 
-# Portable audio (GTK+ only)
-if(ENABLE_PORTAUDIO AND BUILD_wireshark_gtk)
-       set(PACKAGELIST ${PACKAGELIST} PORTAUDIO)
-endif()
-
-
 # C Asynchronous resolver
 if(ENABLE_CARES)
        set(PACKAGELIST ${PACKAGELIST} CARES)
@@ -971,7 +978,11 @@ if(ENABLE_ZLIB)
                set(ZLIB_DLL "zlib1.dll")
                set_target_properties(zlib PROPERTIES FOLDER "Libs/zlib")
                # Annoyingly zlib also builds some other stuff we aren't interested in
-               set_target_properties(zlibstatic PROPERTIES FOLDER "Libs/zlib")
+               set_target_properties(zlibstatic PROPERTIES
+                       FOLDER "Libs/zlib"
+                       EXCLUDE_FROM_ALL True
+                       EXCLUDE_FROM_DEFAULT_BUILD True
+               )
        endif()
        set(PACKAGELIST ${PACKAGELIST} ZLIB)
 endif()
@@ -1070,11 +1081,18 @@ foreach(PACKAGE ${PACKAGELIST})
                        message(STATUS "${PACKAGE} includes: ${${PACKAGE_VAR}_INCLUDE_DIRS}")
                endif()
                if (${PACKAGE_VAR}_LIBRARIES)
-                       list(APPEND WS_ALL_LIBS ${${PACKAGE_VAR}_LIBRARIES})
                        message(STATUS "${PACKAGE} libs: ${${PACKAGE_VAR}_LIBRARIES}")
                endif()
                if (${PACKAGE_VAR}_DEFINITIONS)
                        message(STATUS "${PACKAGE} definitions: ${${PACKAGE_VAR}_DEFINITIONS}")
+                       string(REPLACE ";" " " _definitions "${${PACKAGE_VAR}_DEFINITIONS}")
+                       set(CMAKE_C_FLAGS "${_definitions} ${CMAKE_C_FLAGS}")
+                       set(CMAKE_CXX_FLAGS "${_definitions} ${CMAKE_CXX_FLAGS}")
+               endif()
+               if (${PACKAGE_VAR}_LINK_FLAGS)
+                       string(REPLACE ";" " " _link_flags "${${PACKAGE_VAR}_LINK_FLAGS}")
+                       set(WS_LINK_FLAGS "${_link_flags} ${WS_LINK_FLAGS}")
+                       message(STATUS "${PACKAGE} other link flags: ${_link_flags}")
                endif()
                if (${PACKAGE_VAR}_EXECUTABLE)
                        message(STATUS "${PACKAGE} executable: ${${PACKAGE_VAR}_EXECUTABLE}")
@@ -1097,13 +1115,10 @@ endforeach()
 include( UseWinLibs )
 
 # dist target that prepares source dir
+# XXX Duplicated in the RPM section below.
 add_custom_target(dist
-    COMMAND "${CMAKE_COMMAND}"
-        -DPROJECT_SOURCE_DIR="${PROJECT_SOURCE_DIR}"
-        -DGIT_EXECUTABLE="${GIT_EXECUTABLE}"
-        -DWS_SOURCE_DIR="${WS_SOURCE_DIR}"
-        -P "${CMAKE_SOURCE_DIR}/cmake/modules/Dist.cmake"
-    COMMAND "${CMAKE_MAKE_PROGRAM}" package_source
+       COMMAND ./tools/git-export-release.sh -d "${CMAKE_BINARY_DIR}"
+       WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
 )
 
 
@@ -1123,6 +1138,9 @@ endif()
 if(LIBSSH_FOUND)
        set(HAVE_LIBSSH 1)
 endif()
+if(JSONGLIB_FOUND)
+       set(HAVE_JSONGLIB 1)
+endif()
 if(NGHTTP2_FOUND)
        set(HAVE_NGHTTP2 1)
 endif()
@@ -1160,12 +1178,6 @@ if (HAVE_LIBWINSPARKLE)
        set(HAVE_SOFTWARE_UPDATE 1)
 endif()
 
-# No matter which version of GTK is present
-if(GTK2_FOUND OR GTK3_FOUND)
-       message(WARNING "The GTK+ UI is deprecated and will be removed in a future release.")
-       set(GTK_FOUND ON)
-endif()
-
 if(HAVE_LIBZLIB)
        set(HAVE_ZLIB 1)
        # Always include the "true" zlib includes first. This works around a
@@ -1229,11 +1241,6 @@ elseif(QT4_FOUND)
                # That's the name autofoo uses
                set(QT_MULTIMEDIA_LIB 1)
        endif()
-       if(NOT DEFINED MOC_OPTIONS)
-               if(QT_VERSION_MAJOR EQUAL 4 AND QT_VERSION_MINOR GREATER 7)
-                       set(MOC_OPTIONS -nn)
-               endif()
-       endif()
        if(WIN32 OR APPLE)
                message(FATAL_ERROR "Windows and macOS builds should use Qt5.")
        endif()
@@ -1250,16 +1257,13 @@ if(APPLE)
        #
        set(HAVE_MACOS_FRAMEWORKS 1)
        FIND_LIBRARY (APPLE_APPLICATION_SERVICES_LIBRARY ApplicationServices)
+       FIND_LIBRARY (APPLE_APPKIT_LIBRARY AppKit)
        FIND_LIBRARY (APPLE_CORE_FOUNDATION_LIBRARY CoreFoundation)
        FIND_LIBRARY (APPLE_SYSTEM_CONFIGURATION_LIBRARY SystemConfiguration)
 endif()
 
 include(ConfigureChecks.cmake)
 
-#Big or little endian ?
-include(TestBigEndian)
-test_big_endian(WORDS_BIGENDIAN)
-
 # Global properties
 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
 
@@ -1281,6 +1285,8 @@ set_target_properties(checkAPI
                EXCLUDE_FROM_DEFAULT_BUILD True
 )
 
+include( UseCheckAPI )
+
 add_subdirectory( capchild )
 add_subdirectory( caputils )
 add_subdirectory( codecs )
@@ -1317,10 +1323,6 @@ if(NOT WIN32)
        add_custom_target(dumpabi DEPENDS dumpabi-libwireshark dumpabi-libwiretap dumpabi-libwsutil)
 endif()
 
-if(BUILD_wireshark_gtk AND GTK_FOUND)
-       add_subdirectory( ui/gtk )
-endif()
-
 if(BUILD_wireshark AND QT_FOUND)
        add_subdirectory( ui/qt )
 endif()
@@ -1445,13 +1447,15 @@ set( libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}" )
 set( includedir  "\${prefix}/include" )
 set( plugindir "\${libdir}/wireshark/${PLUGIN_VERSION_DIR}" )
 
+# Doxygen variables
+file(GLOB TOP_LEVEL_SOURCE_LIST *.c *.cpp *.h)
+string (REPLACE ";" " " DOXYGEN_TOP_LEVEL_SOURCES "${TOP_LEVEL_SOURCE_LIST}")
+set(DOXYGEN_INPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
+set(DOXYGEN_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
+
 set(ICON_PATH "${CMAKE_SOURCE_DIR}/image/")
 set( IN_FILES
-       capchild/doxygen.cfg.in
-       caputils/doxygen.cfg.in
        doxygen.cfg.in
-       doxygen_global.cfg
-       epan/doxygen.cfg.in
        image/libwireshark.rc.in
        image/text2pcap.rc.in
        image/capinfos.rc.in
@@ -1473,12 +1477,7 @@ set( IN_FILES
        packaging/macosx/osx-app.sh.in
        packaging/macosx/osx-dmg.sh.in
        packaging/macosx/Wireshark_package.pmdoc/index.xml.in
-       randpkt_core/doxygen.cfg.in
-       ui/doxygen.cfg.in
-       ui/gtk/doxygen.cfg.in
-       ui/qt/doxygen.cfg.in
        wireshark.pc.in
-       writecap/doxygen.cfg.in
 )
 foreach( _in_file ${IN_FILES} )
        get_filename_component( _path ${_in_file} PATH )
@@ -1536,7 +1535,6 @@ feature_summary(WHAT ALL)
 
 link_directories(
        ${CMAKE_BINARY_DIR}/ui
-       ${CMAKE_BINARY_DIR}/ui/gtk
        ${CMAKE_BINARY_DIR}/ui/qt
        ${CMAKE_BINARY_DIR}/capchild
        ${CMAKE_BINARY_DIR}/caputils
@@ -1552,11 +1550,14 @@ if(WIN32)
        set(PLATFORM_UI_SRC
                ui/win32/console_win32.c
                ui/win32/file_dlg_win32.c
-               ui/win32/print_win32.c
        )
        set(PLATFORM_UI_RC_FILES
                image/file_dlg_win32.rc
        )
+elseif(APPLE)
+       set(PLATFORM_UI_SRC
+               ui/macosx/cocoa_bridge.mm
+       )
 endif()
 
 # sources common for wireshark, tshark, rawshark and sharkd
@@ -1724,12 +1725,15 @@ if(WIN32)
        if (CARES_FOUND)
                list (APPEND OPTIONAL_DLLS "${CARES_DLL_DIR}/${CARES_DLL}")
        endif(CARES_FOUND)
-       if (GEOIP_FOUND)
-               list (APPEND OPTIONAL_DLLS "${GEOIP_DLL_DIR}/${GEOIP_DLL}")
-       endif(GEOIP_FOUND)
+       if (MAXMINDDB_FOUND)
+               list (APPEND OPTIONAL_DLLS "${MAXMINDDB_DLL_DIR}/${MAXMINDDB_DLL}")
+       endif(MAXMINDDB_FOUND)
        if (LIBSSH_FOUND)
                list (APPEND OPTIONAL_DLLS "${LIBSSH_DLL_DIR}/${LIBSSH_DLL}")
        endif(LIBSSH_FOUND)
+       if (JSONGLIB_FOUND)
+               list (APPEND OPTIONAL_DLLS "${JSONGLIB_DLL_DIR}/${JSONGLIB_DLL}")
+       endif(JSONGLIB_FOUND)
        foreach( _dll ${GCRYPT_DLLS} )
                list (APPEND OPTIONAL_DLLS "${GCRYPT_DLL_DIR}/${_dll}")
        endforeach(_dll)
@@ -2094,7 +2098,7 @@ list(APPEND copy_data_files_depends
 add_custom_target(copy_data_files ALL DEPENDS ${copy_data_files_depends} )
 set_target_properties(copy_data_files PROPERTIES FOLDER "Copy Tasks")
 
-if( (BUILD_wireshark AND QT_FOUND) OR (BUILD_wireshark_gtk AND GTK_FOUND) )
+if(BUILD_wireshark AND QT_FOUND)
        set(WIRESHARK_SRC
                capture_info.c
                capture_opts.c
@@ -2189,6 +2193,7 @@ if(BUILD_wireshark AND QT_FOUND)
                wscodecs
                ${LIBEPAN_LIBS}
                ${APPLE_APPLICATION_SERVICES_LIBRARY}
+               ${APPLE_APPKIT_LIBRARY}
                ${APPLE_CORE_FOUNDATION_LIBRARY}
                ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
                ${NL_LIBRARIES}
@@ -2196,9 +2201,6 @@ if(BUILD_wireshark AND QT_FOUND)
        )
 
        add_executable(wireshark WIN32 MACOSX_BUNDLE wireshark-qt.cpp ${wireshark_FILES} ${EXTRA_BUNDLE_FILES})
-       if(QT_VERSION EQUAL 4)
-               target_compile_definitions(wireshark PRIVATE Q_NULLPTR=NULL)
-       endif()
        add_dependencies(wireshark version)
        set(PROGLIST ${PROGLIST} wireshark)
        if(CMAKE_VERSION VERSION_LESS "2.8.12"
@@ -2340,106 +2342,6 @@ macro(set_extcap_executable_properties _executable)
        endif()
 endmacro()
 
-if(BUILD_wireshark_gtk AND GTK_FOUND)
-       set(wireshark_gtk_LIBS
-               gtkui
-               ui
-               capchild
-               caputils
-               ${GTK2_LIBRARIES}
-               ${GTK3_LIBRARIES}
-               ${GTHREAD2_LIBRARIES}
-               wscodecs
-               ${PORTAUDIO_LIBRARIES}
-               ${LIBEPAN_LIBS}
-               ${APPLE_APPLICATION_SERVICES_LIBRARY}
-               ${APPLE_CORE_SERVICES_LIBRARY}
-               ${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
-               ${NL_LIBRARIES}
-               ${WIN_COMCTL32_LIBRARY}
-       )
-       # wireshark and wireshark-gtk share wireshark_FILES
-
-       add_executable(wireshark-gtk WIN32 ${wireshark_FILES})
-       add_dependencies(wireshark-gtk version)
-       set(PROGLIST ${PROGLIST} wireshark-gtk)
-       set_target_properties(wireshark-gtk PROPERTIES
-               LINK_FLAGS "${WS_LINK_FLAGS}"
-               FOLDER "Executables"
-       )
-       target_link_libraries(wireshark-gtk ${wireshark_gtk_LIBS})
-       install(TARGETS wireshark-gtk RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
-
-       if(WIN32)
-               add_custom_target(copy_gtk_dlls)
-               set_target_properties(copy_gtk_dlls PROPERTIES FOLDER "Copy Tasks")
-               add_custom_command(TARGET copy_gtk_dlls PRE_BUILD
-                       COMMAND ${CMAKE_COMMAND} -E make_directory "${_dll_output_dir}"
-               )
-
-               if(GTK2_FOUND)
-                       set(_gtk_dll_dir "${GTK2_DLL_DIR}")
-                       set(_gtk_etc_dir "${GTK2_ETC_DIR}")
-                       set(_gtk_dlls "${GTK2_DLLS}")
-                       set(_gtk_etc_dir "${GTK2_ETC_DIR}")
-               else()
-                       set(_gtk_dll_dir "${GTK3_DLL_DIR}")
-                       set(_gtk_dlls "${GTK3_DLLS}")
-                       set(_gtk_etc_dir "${GTK3_ETC_DIR}")
-               endif()
-
-               foreach(_dll ${_gtk_dlls})
-                       add_custom_command(TARGET copy_gtk_dlls PRE_BUILD
-                               COMMAND ${CMAKE_COMMAND} -E copy_if_different
-                                       "${_gtk_dll_dir}/${_dll}" "${_dll_output_dir}"
-                       )
-               endforeach(_dll)
-
-               # /etc
-               add_custom_command(TARGET copy_gtk_dlls PRE_BUILD
-                       COMMAND ${CMAKE_COMMAND} -E make_directory "${_dll_output_dir}/etc"
-               )
-               add_custom_command(TARGET copy_gtk_dlls PRE_BUILD
-                       COMMAND ${CMAKE_COMMAND} -E copy_directory
-                               "${_gtk_etc_dir}" "${_dll_output_dir}/etc"
-               )
-
-               # XXX - Omitting ${GTK2_LIB_DIR}\loaders copying from Makefile.nmake
-               if(GTK2_FOUND)
-                       # Engines
-                       set (_engines_output_dir "${_dll_output_dir}/lib/gtk-2.0/2.10.0/engines")
-                       add_custom_command(TARGET copy_gtk_dlls PRE_BUILD
-                               COMMAND ${CMAKE_COMMAND} -E make_directory "${_engines_output_dir}"
-                       )
-                       foreach(_dll ${GTK2_ENGINES_DLLS})
-                               add_custom_command(TARGET copy_gtk_dlls PRE_BUILD
-                                       COMMAND ${CMAKE_COMMAND} -E copy_if_different
-                                               "${GTK2_ENGINES_DLL_DIR}/${_dll}" "${_engines_output_dir}"
-                               )
-                       endforeach(_dll)
-
-                       # Themes
-                       add_custom_command(TARGET copy_gtk_dlls PRE_BUILD
-                               COMMAND ${CMAKE_COMMAND} -E copy_if_different
-                                       "${GTK2_THEMES_DIR}/gtkrc" "${_dll_output_dir}/etc/gtk-2.0"
-                       )
-
-                       # Modules
-                       add_custom_command(TARGET copy_gtk_dlls PRE_BUILD
-                               COMMAND ${CMAKE_COMMAND} -E copy_directory
-                                       "${GTK2_LIB_DIR}" "${_dll_output_dir}/lib/gtk-2.0"
-                       )
-               else()
-                       add_custom_command(TARGET copy_gtk_dlls PRE_BUILD
-                               COMMAND ${CMAKE_COMMAND} -E copy_directory
-                                       "${CMAKE_SOURCE_DIR}/ui/win32/settings.ini" "${_dll_output_dir}/etc"
-                       )
-               endif()
-
-               add_dependencies(wireshark-gtk copy_gtk_dlls copy_cli_dlls)
-       endif(WIN32)
-endif()
-
 register_tap_files(tshark-tap-register.c
        ${TSHARK_TAP_SRC}
 )
@@ -2461,6 +2363,7 @@ if(BUILD_tshark)
                ${SHARK_COMMON_SRC}
                ${CMAKE_BINARY_DIR}/image/tshark.rc
        )
+
        add_executable(tshark ${tshark_FILES})
        add_dependencies(tshark version)
        set_extra_executable_properties(tshark "Executables")
@@ -2934,6 +2837,7 @@ if (MAXMINDDB_FOUND)
        add_executable(mmdbresolve ${mmdbresolve_FILES})
        set_extra_executable_properties(mmdbresolve "Executables")
        target_link_libraries(mmdbresolve ${mmdbresolve_LIBS})
+       target_include_directories(mmdbresolve PUBLIC ${MAXMINDDB_INCLUDE_DIR})
        install(TARGETS mmdbresolve RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
 endif()
 
@@ -2990,6 +2894,91 @@ if(ENABLE_APPLICATION_BUNDLE)
 
 endif()
 
+if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+       find_program(RPMBUILD_EXECUTABLE rpmbuild)
+       find_program(GIT_EXECUTABLE git)
+endif()
+
+if(RPMBUILD_EXECUTABLE)
+       foreach(_rpm_dir BUILD RPMS SOURCES SPECS SRPMS)
+               file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/packaging/rpm/${_rpm_dir}")
+       endforeach()
+
+       set(_rpmbuild_with_args)
+       if(CMAKE_GENERATOR STREQUAL "Ninja")
+               list(APPEND _rpmbuild_with_args --with ninja)
+       endif()
+       if (BUILD_wireshark)
+               list(APPEND _rpmbuild_with_args --with qt5)
+       endif()
+       if (BUILD_mmdbresolve)
+               list(APPEND _rpmbuild_with_args --with mmdbresolve)
+       endif()
+       if (LUA_FOUND)
+               list(APPEND _rpmbuild_with_args --with lua)
+       endif()
+       if (LZ4_FOUND AND SNAPPY_FOUND)
+               list(APPEND _rpmbuild_with_args --with lz4_and_snappy)
+       endif()
+       if (CARES_FOUND)
+               list(APPEND _rpmbuild_with_args --with c_ares)
+       endif()
+       if (SPANDSP_FOUND)
+               list(APPEND _rpmbuild_with_args --with spandsp)
+       endif()
+       if (BCG729_FOUND)
+               list(APPEND _rpmbuild_with_args --with bcg729)
+       endif()
+       if (LIBXML2_FOUND)
+               list(APPEND _rpmbuild_with_args --with libxml2)
+       endif()
+       if (NGHTTP2_FOUND)
+               list(APPEND _rpmbuild_with_args --with nghttp2)
+       endif()
+
+       if(GIT_EXECUTABLE)
+               execute_process(
+                       COMMAND ${GIT_EXECUTABLE} describe --abbrev=8 --match v[1-9]*
+                       OUTPUT_VARIABLE _git_description
+                       OUTPUT_STRIP_TRAILING_WHITESPACE
+                       WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+               )
+       else()
+               set(_git_description "")
+       endif()
+       if (NOT _git_description)
+               # We're building the rpm outside the source. Guess the version from the dirname.
+               get_filename_component(CMAKE_SOURCE_DIR_NAME ${CMAKE_SOURCE_DIR} NAME)
+               # XXX this assumes the directory to start with "wireshark-"
+               string(SUBSTRING "${CMAKE_SOURCE_DIR_NAME}" 10 -1 _git_description)
+       endif()
+       string(SUBSTRING "${_git_description}" 1 -1 RPM_TARBALL_VERSION)
+       string(REPLACE "-" "_" RPM_VERSION "${RPM_TARBALL_VERSION}")
+       configure_file(packaging/rpm/wireshark.spec.in ${CMAKE_BINARY_DIR}/packaging/rpm/SPECS/wireshark.spec)
+
+       # XXX Replace with the "dist" target?
+       set(_export_tarball "${CPACK_PACKAGE_NAME}-${RPM_TARBALL_VERSION}.tar.xz")
+       add_custom_command(
+               OUTPUT "${CMAKE_BINARY_DIR}/packaging/rpm/SOURCES/${_export_tarball}"
+               COMMAND ./tools/git-export-release.sh
+                       -d "${CMAKE_BINARY_DIR}/packaging/rpm/SOURCES"
+                       "${_git_description}"
+               # XXX Add an option to git-export-release.sh to write to a
+               # specific directory so that we can get rid of `ln` below.
+               WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+       )
+       add_custom_target(rpm-package
+               COMMAND ${RPMBUILD_EXECUTABLE}
+                       --define "_topdir ${CMAKE_BINARY_DIR}/packaging/rpm"
+                       --define "_prefix ${CMAKE_INSTALL_PREFIX}"
+                       ${_rpmbuild_with_args}
+                       --clean -ba SPECS/wireshark.spec
+               DEPENDS "${CMAKE_BINARY_DIR}/packaging/rpm/SOURCES/${_export_tarball}"
+               WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/packaging/rpm"
+               COMMENT "Create a tarball from the current git commit."
+       )
+endif()
+
 set(CLEAN_C_FILES
        ${wireshark_FILES}
        ${tshark_FILES}
@@ -3046,6 +3035,7 @@ set(SHARK_PUBLIC_HEADERS
        ws_compiler_tests.h
        ws_diag_control.h
        ws_symbol_export.h
+       version_info.h
 )
 
 if(NOT WIN32)
@@ -3058,7 +3048,7 @@ if(NOT WIN32)
 endif()
 
 # Install icons and other desktop files for Freedesktop.org-compliant desktops.
-if(((BUILD_wireshark AND QT_FOUND) OR BUILD_wireshark_gtk) AND NOT (WIN32 OR APPLE))
+if((BUILD_wireshark AND QT_FOUND) AND NOT (WIN32 OR APPLE))
        install(FILES wireshark-mime-package.xml
                DESTINATION "${CMAKE_INSTALL_DATADIR}/mime/packages"
                RENAME wireshark.xml
@@ -3070,10 +3060,6 @@ if(((BUILD_wireshark AND QT_FOUND) OR BUILD_wireshark_gtk) AND NOT (WIN32 OR APP
                install(FILES wireshark.desktop
                        DESTINATION "${CMAKE_INSTALL_DATADIR}/applications")
        endif()
-       if(BUILD_wireshark_gtk)
-               install(FILES wireshark-gtk.desktop
-                       DESTINATION "${CMAKE_INSTALL_DATADIR}/applications")
-       endif()
        foreach(size 16 24 32 48 64 128 256)
                install(FILES image/wsicon${size}.png
                        DESTINATION "${CMAKE_INSTALL_DATADIR}/icons/hicolor/${size}x${size}/apps"
@@ -3129,6 +3115,25 @@ install(
                ${CMAKE_INSTALL_MODULES_DIR}
 )
 
+if (DOXYGEN_EXECUTABLE)
+       # API reference
+       # We don't have a good way of tracking dependencies, so we simply
+       # recreate the whole thing from scratch each time.
+       add_custom_target(wsar_html
+               COMMAND ${CMAKE_COMMAND} -E remove_directory wsar_html
+               COMMAND ${DOXYGEN_EXECUTABLE} doxygen.cfg
+       )
+
+       add_custom_target(wsar_html_zip
+               COMMAND ${CMAKE_COMMAND} -E tar "cfv" "wsar_html.zip" --format=zip wsar_html
+               DEPENDS wsar_html
+       )
+       set_target_properties(wsar_html wsar_html_zip PROPERTIES
+               FOLDER "Docs"
+               EXCLUDE_FROM_DEFAULT_BUILD True
+       )
+endif(DOXYGEN_EXECUTABLE)
+
 # Test suite wrapper
 if(ENABLE_APPLICATION_BUNDLE)
        set(TEST_SH_BIN_DIR ${CMAKE_BINARY_DIR}/run)
@@ -3144,7 +3149,24 @@ add_custom_target(test-sh
                -P ${CMAKE_SOURCE_DIR}/cmake/modules/GenerateTestSh.cmake
        DEPENDS ${CMAKE_SOURCE_DIR}/cmake/modules/GenerateTestSh.cmake
 )
-set_target_properties(test-sh PROPERTIES FOLDER "Tests")
+set_target_properties(test-sh PROPERTIES
+       FOLDER "Tests"
+       EXCLUDE_FROM_DEFAULT_BUILD True
+)
+
+add_custom_target(test-programs
+       DEPENDS test-sh
+               exntest
+               oids_test
+               reassemble_test
+               tvbtest
+               wmem_test
+       COMMENT "Building unit test programs and wrapper"
+)
+set_target_properties(test-programs PROPERTIES
+       FOLDER "Tests"
+       EXCLUDE_FROM_DEFAULT_BUILD True
+)
 
 if (GIT_EXECUTABLE)
        # Update AUTHORS file with entries from git shortlog
@@ -3158,17 +3180,6 @@ else (GIT_EXECUTABLE)
 endif (GIT_EXECUTABLE)
 set_target_properties(gen-authors PROPERTIES FOLDER "Docs")
 
-add_custom_target(test-programs
-       DEPENDS test-sh
-               exntest
-               oids_test
-               reassemble_test
-               tvbtest
-               wmem_test
-       COMMENT "Building unit test programs and wrapper"
-)
-set_target_properties(test-programs PROPERTIES FOLDER "Tests")
-
 if (WIN32)
        file (TO_NATIVE_PATH ${CMAKE_SOURCE_DIR}/tools/Get-HardenFlags.ps1 _win_harden_flags)
        add_custom_target(hardening-check
@@ -3197,7 +3208,6 @@ else ()
        endif()
 endif()
 
-include( UseCheckAPI )
 CHECKAPI(
        NAME
          main