DCOM: always NUL-terminate dissect_dcom_BSTR results
[metze/wireshark/wip.git] / CMakeLists.txt
index ec29925396288ae9a782b40fec58a38c63030f49..076735341e40c1d823b26d2a4adec5228070adb3 100644 (file)
@@ -174,6 +174,12 @@ if(NOT CMAKE_INSTALL_RPATH AND NOT (WIN32 OR APPLE))
        endif()
 endif()
 
+if(WIN32)
+    # Linking with wsetargv.obj enables "wildcard expansion" of
+    # command-line arguments.
+    set(WILDCARD_OBJ wsetargv.obj)
+endif(WIN32)
+
 # Banner shown at top right of Qt welcome screen.
 if(DEFINED ENV{WIRESHARK_VERSION_FLAVOR})
        set(VERSION_FLAVOR "$ENV{WIRESHARK_VERSION_FLAVOR}")
@@ -193,6 +199,7 @@ message(STATUS "V: ${PROJECT_VERSION}, MaV: ${PROJECT_MAJOR_VERSION}, MiV: ${PRO
 include(UseLemon)
 include(UseMakePluginReg)
 include(UseMakeTaps)
+include(UseExecutableResources)
 include(UseAsn2Wrs)
 
 # The following snippet has been taken from
@@ -491,29 +498,9 @@ else() # ! MSVC
                -Wno-long-long
                -Wheader-guard
                -Wcomma
+               -Wshorten-64-to-32
        )
 
-       #
-       # For -Wshorten-64-to-32, Apple's llvm-gcc doesn't seem to support
-       # specifying -Werror and then specifying that -Wshorten-64-to-32
-       # warnings should *not* be treated as errors - not with pragmas
-       # and not even with -Werror ... -Wshorten-64-to-32 ...
-       # -Wno-error=shorten-64-to-32.
-       #
-       # So we only add -Wshorten-64-to-32 if either 1) we're not building
-       # on/for Apple or 2) we're using Clang.
-       #
-       # We also suppress -Wunused-function; that's enabled by -Wall,
-       # but it's another warning that can be difficult to suppress
-       # in generated code.
-       #
-       if ((NOT APPLE) OR CMAKE_C_COMPILER_ID MATCHES "Clang")
-               list(APPEND WIRESHARK_COMMON_FLAGS
-                       -Wshorten-64-to-32
-                       -Wno-unused-function
-               )
-       endif()
-
        #
        # Code that may be worth looking into (coding practices)
        #
@@ -752,9 +739,22 @@ if(NOT DISABLE_WERROR AND NOT ENABLE_EXTRA_COMPILER_WARNINGS)
        if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
                set(WERROR_COMMON_FLAGS "/WX")
        else()
-               check_c_compiler_flag(-Werror WERROR)
-               if (WERROR)
-                       set(WERROR_COMMON_FLAGS "-Werror")
+               #
+               # If a warning has been enabled by -Wall or -W,
+               # and have specified -Werror, there appears to be
+               # no way, in Apple's llvm-gcc, to prevent that
+               # particular warning from giving an error - not
+               # with a pragma, not with -Wno-{warning}, and not
+               # with -Wno-error={warning}.
+               #
+               # Therefore, with that compiler, we just disable
+               # -Werror.
+               #
+               if ((NOT APPLE) OR CMAKE_C_COMPILER_ID MATCHES "Clang")
+                       check_c_compiler_flag(-Werror WERROR)
+                       if (WERROR)
+                               set(WERROR_COMMON_FLAGS "-Werror")
+                       endif()
                endif()
        endif()
 endif()
@@ -851,6 +851,10 @@ if(ENABLE_AIRPCAP)
        set(PACKAGELIST ${PACKAGELIST} AIRPCAP)
 endif()
 
+if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+       set(PACKAGELIST ${PACKAGELIST} Systemd)
+endif()
+
 # Build the Qt GUI?
 if(BUILD_wireshark)
        # Untested, may not work if CMAKE_PREFIX_PATH gets overwritten
@@ -1050,9 +1054,6 @@ foreach(PACKAGE ${PACKAGELIST})
        endif()
 endforeach()
 
-# Provide Windows system lib names
-include( UseWinLibs )
-
 # dist target that prepares source dir
 # XXX Duplicated in the RPM section below.
 add_custom_target(dist
@@ -1060,7 +1061,6 @@ add_custom_target(dist
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
 )
 
-
 if(HAVE_LIBAIRPCAP)
        set(HAVE_AIRPCAP 1)
 endif()
@@ -1191,6 +1191,16 @@ if(ENABLE_CHECKHF_CONFLICT)
        set(ENABLE_CHECK_FILTER 1)
 endif()
 
+#
+# Platform-specific additional libraries.
+#
+if(WIN32)
+       set(WIN_PSAPI_LIBRARY    psapi.lib)
+       set(WIN_WSOCK32_LIBRARY  wsock32.lib)
+       set(WIN_COMCTL32_LIBRARY comctl32.lib )
+       set(WIN_VERSION_LIBRARY  version.lib)
+endif()
+
 if(APPLE)
        #
        # We assume that APPLE means macOS so that we have the macOS
@@ -1387,36 +1397,23 @@ 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
-       doxygen.cfg.in
-       image/libwireshark.rc.in
-       image/text2pcap.rc.in
-       image/capinfos.rc.in
-       image/wireshark.rc.in
-       image/mergecap.rc.in
-       image/tshark.rc.in
-       image/dumpcap.rc.in
-       image/reordercap.rc.in
-       image/rawshark.rc.in
-       image/file_dlg_win32.rc
-       image/tfshark.rc.in
-       image/editcap.rc.in
-       image/captype.rc.in
-       image/libwscodecs.rc.in
-       image/libwsutil.rc.in
-       image/wiretap.rc.in
-       image/wireshark.exe.manifest.in
-       packaging/macosx/Info.plist.in
-       packaging/macosx/osx-app.sh.in
-       packaging/macosx/osx-dmg.sh.in
-       packaging/macosx/Wireshark_package.pmdoc/index.xml.in
-       wireshark.pc.in
+set(CFG_OUT_FILES
+       doxygen.cfg
+       image/libwireshark.rc
+       image/wireshark.rc
+       image/dumpcap.rc
+       image/libwscodecs.rc
+       image/libwsutil.rc
+       image/wiretap.rc
+       image/wireshark.exe.manifest
+       packaging/macosx/Info.plist
+       packaging/macosx/osx-app.sh
+       packaging/macosx/osx-dmg.sh
+       packaging/macosx/Wireshark_package.pmdoc/index.xml
+       wireshark.pc
 )
-foreach( _in_file ${IN_FILES} )
-       get_filename_component( _path ${_in_file} PATH )
-       string( REGEX REPLACE "(.*)\\.in" "\\1" _outfile ${_in_file}  )
-       configure_file( ${CMAKE_SOURCE_DIR}/${_in_file} ${CMAKE_BINARY_DIR}/${_outfile} @ONLY )
+foreach( _cfg_file ${CFG_OUT_FILES} )
+       configure_file( ${CMAKE_SOURCE_DIR}/${_cfg_file}.in ${CMAKE_BINARY_DIR}/${_cfg_file} @ONLY )
 endforeach()
 
 include(FeatureSummary)
@@ -2016,9 +2013,9 @@ if(BUILD_wireshark AND QT_FOUND)
        )
        set(wireshark_FILES
                ${WIRESHARK_SRC}
-               ${CMAKE_BINARY_DIR}/image/wireshark.rc
                ${PLATFORM_UI_RC_FILES}
        )
+       set_executable_resources(wireshark "Wireshark" UNIQUE_RC)
 endif()
 
 if(ENABLE_APPLICATION_BUNDLE)
@@ -2181,7 +2178,7 @@ endif()
 # Common properties for CLI executables
 macro(set_extra_executable_properties _executable _folder)
        set_target_properties(${_executable} PROPERTIES
-               LINK_FLAGS "${WS_LINK_FLAGS}"
+               LINK_FLAGS "${WILDCARD_OBJ} ${WS_LINK_FLAGS}"
                FOLDER ${_folder}
        )
 
@@ -2228,9 +2225,9 @@ if(BUILD_tshark)
                tshark.c
                ${TSHARK_TAP_SRC}
                ${SHARK_COMMON_SRC}
-               ${CMAKE_BINARY_DIR}/image/tshark.rc
        )
 
+       set_executable_resources(tshark "TShark" UNIQUE_RC)
        add_executable(tshark ${tshark_FILES})
        add_dependencies(tshark version)
        set_extra_executable_properties(tshark "Executables")
@@ -2250,8 +2247,8 @@ if(BUILD_tfshark)
                tfshark.c
                ${TSHARK_TAP_SRC}
                ${SHARK_COMMON_SRC}
-               ${CMAKE_BINARY_DIR}/image/tfshark.rc
        )
+       set_executable_resources(tfshark "TFShark")
        add_executable(tfshark ${tfshark_FILES})
        add_dependencies(tfshark version)
        set_extra_executable_properties(tfshark "Executables")
@@ -2271,8 +2268,8 @@ if(BUILD_rawshark AND PCAP_FOUND)
        set(rawshark_FILES
                ${SHARK_COMMON_SRC}
                rawshark.c
-               ${CMAKE_BINARY_DIR}/image/rawshark.rc
        )
+       set_executable_resources(rawshark "Rawshark")
        add_executable(rawshark ${rawshark_FILES})
        add_dependencies(rawshark version)
        set_extra_executable_properties(rawshark "Executables")
@@ -2295,6 +2292,7 @@ if(BUILD_sharkd)
                sharkd_session.c
                ${SHARK_COMMON_SRC}
        )
+       set_executable_resources(sharkd "SharkD")
        add_executable(sharkd ${sharkd_FILES})
        add_dependencies(sharkd version)
        set_extra_executable_properties(sharkd "Executables")
@@ -2369,8 +2367,9 @@ if(BUILD_text2pcap)
        add_lex_files(text2pcap_LEX_FILES text2pcap_FILES
                text2pcap-scanner.l
        )
-       add_executable(text2pcap ${text2pcap_FILES}
-               ${CMAKE_BINARY_DIR}/image/text2pcap.rc)
+       set_executable_resources(text2pcap "Text2pcap"
+               COPYRIGHT_INFO "2001 Ashok Narayanan <ashokn@cisco.com>")
+       add_executable(text2pcap ${text2pcap_FILES})
        add_dependencies(text2pcap version)
        set_extra_executable_properties(text2pcap "Executables")
        target_link_libraries(text2pcap ${text2pcap_LIBS})
@@ -2387,8 +2386,8 @@ if(BUILD_mergecap)
        set(mergecap_FILES
                mergecap.c
                version_info.c
-               ${CMAKE_BINARY_DIR}/image/mergecap.rc
        )
+       set_executable_resources(mergecap "Mergecap")
        add_executable(mergecap ${mergecap_FILES})
        add_dependencies(mergecap version)
        set_extra_executable_properties(mergecap "Executables")
@@ -2406,8 +2405,8 @@ if(BUILD_reordercap)
        set(reordercap_FILES
                reordercap.c
                version_info.c
-               ${CMAKE_BINARY_DIR}/image/reordercap.rc
        )
+       set_executable_resources(reordercap "Reordercap")
        add_executable(reordercap ${reordercap_FILES})
        add_dependencies(reordercap version)
        set_extra_executable_properties(reordercap "Executables")
@@ -2427,8 +2426,8 @@ if(BUILD_capinfos)
        set(capinfos_FILES
                capinfos.c
                version_info.c
-               ${CMAKE_BINARY_DIR}/image/capinfos.rc
        )
+       set_executable_resources(capinfos "Capinfos")
        add_executable(capinfos ${capinfos_FILES})
        add_dependencies(capinfos version)
        set_extra_executable_properties(capinfos "Executables")
@@ -2447,8 +2446,8 @@ if(BUILD_captype)
        set(captype_FILES
                captype.c
                version_info.c
-               ${CMAKE_BINARY_DIR}/image/captype.rc
        )
+       set_executable_resources(captype "Captype")
        add_executable(captype ${captype_FILES})
        add_dependencies(captype version)
        set_extra_executable_properties(captype "Executables")
@@ -2467,8 +2466,8 @@ if(BUILD_editcap)
        set(editcap_FILES
                editcap.c
                version_info.c
-               ${CMAKE_BINARY_DIR}/image/editcap.rc
        )
+       set_executable_resources(editcap "Editcap")
        add_executable(editcap ${editcap_FILES})
        add_dependencies(editcap version)
        set_extra_executable_properties(editcap "Executables")
@@ -2499,8 +2498,8 @@ if(BUILD_dumpcap AND PCAP_FOUND)
                ringbuffer.c
                sync_pipe_write.c
                version_info.c
-               ${CMAKE_BINARY_DIR}/image/dumpcap.rc
        )
+       set_executable_resources(dumpcap "Dumpcap" UNIQUE_RC)
        add_executable(dumpcap ${dumpcap_FILES})
        add_dependencies(dumpcap version)
        set_extra_executable_properties(dumpcap "Executables")
@@ -2667,10 +2666,13 @@ if(RPMBUILD_EXECUTABLE)
        if(CMAKE_GENERATOR STREQUAL "Ninja")
                list(APPEND _rpmbuild_with_args --with ninja)
        endif()
+       if(CCACHE_EXECUTABLE)
+               list(APPEND _rpmbuild_with_args --with ccache)
+       endif()
        if (BUILD_wireshark)
                list(APPEND _rpmbuild_with_args --with qt5)
        endif()
-       if (BUILD_mmdbresolve)
+       if (MAXMINDDB_FOUND)
                list(APPEND _rpmbuild_with_args --with mmdbresolve)
        endif()
        if (LUA_FOUND)
@@ -2694,6 +2696,9 @@ if(RPMBUILD_EXECUTABLE)
        if (NGHTTP2_FOUND)
                list(APPEND _rpmbuild_with_args --with nghttp2)
        endif()
+       if (SYSTEMD_FOUND)
+               list(APPEND _rpmbuild_with_args --with sdjournal)
+       endif()
 
        execute_process(
                COMMAND ${PERL_EXECUTABLE}