3 # Wireshark - Network traffic analyzer
4 # By Gerald Combs <gerald@wireshark.org>
5 # Copyright 1998 Gerald Combs
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License
9 # as published by the Free Software Foundation; either version 2
10 # of the License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 # We should use CPack to generate the NSIS package. Even better,
23 # we should use CPack to create a .msi using WIX.
25 set(NSIS_GENERATED_FILES
26 ${CMAKE_CURRENT_BINARY_DIR}/all-manifest.nsh
27 ${CMAKE_CURRENT_BINARY_DIR}/config.nsh
28 ${CMAKE_CURRENT_BINARY_DIR}/gtk-dll-manifest.nsh
29 ${CMAKE_CURRENT_BINARY_DIR}/qt-dll-manifest.nsh
31 set(NSIS_GENERATED_FILES ${NSIS_GENERATED_FILES} PARENT_SCOPE)
39 AdditionalTasksPage.ini
42 ${NSIS_GENERATED_FILES}
46 # Variables required for config.nsh
47 set(PROGRAM_NAME ${CMAKE_PROJECT_NAME})
48 file(TO_NATIVE_PATH "${CMAKE_SOURCE_DIR}" TOP_SRC_DIR)
49 # STAGING_DIR depends on the build configuration so we pass it
50 # on the command line below.
51 file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/docbook" USER_GUIDE_DIR)
52 if ("${WIRESHARK_TARGET_PLATFORM}" STREQUAL "win32")
53 set(TARGET_MACHINE x86)
54 elseif ("${WIRESHARK_TARGET_PLATFORM}" STREQUAL "win64")
55 set(TARGET_MACHINE x64)
57 message(FATAL_ERROR "Your mysterious moon-man architecture \"${WIRESHARK_TARGET_PLATFORM}\" frightens and confuses us.")
60 # Path to the WinPcap installer.
61 # XXX Come up with a better variable, e.g. cache WIRESHARK_LIB_DIR in FindWSWinLibs.
62 file(TO_NATIVE_PATH "${GLIB2_DLL_DIR}/../.." _wireshark_lib_dir)
63 set(WIRESHARK_LIB_DIR "${_wireshark_lib_dir}")
65 # Must match ${WIRESHARK_LIB_DIR}/WinPcap_X_Y_Z.exe
66 set(WINPCAP_PACKAGE_VERSION ${WINPCAP_VERSION})
67 string(REPLACE "_" "." PCAP_DISPLAY_VERSION "${WINPCAP_PACKAGE_VERSION}")
69 set(USBPCAP_DISPLAY_VERSION "1.2.0.3")
71 set(PRODUCT_VERSION ${PROJECT_MAJOR_VERSION}.${PROJECT_MINOR_VERSION}.${PROJECT_PATCH_VERSION}.${PROJECT_BUILD_VERSION})
74 # - Sync the various version names between CMake and NSIS.
75 # - Set CMakeLists.txt version strings in make-version.pl
76 # - Add a VERSION_EXTRA cmake option
77 set (VERSION "${PROJECT_VERSION}")
78 set (PRODUCT_VERSION=${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO}.${VERSION_BUILD})
80 #add_custom_target(build_nsis_package
82 # wireshark-$(WIRESHARK_TARGET_PLATFORM)-$(VERSION).exe
85 if(BUILD_wireshark AND QT_FOUND)
86 set (QT_DIR "\${STAGING_DIR}")
89 if(BUILD_wireshark_gtk AND GTK_FOUND)
90 set (GTK_DIR "\${STAGING_DIR}")
93 # Look for the Visual C++ Redistributable packages in the following locations:
95 # - _PROJECT_LIB_DIR/vcredist_MSVCxx
97 # - %VCINSTALLDIR%/redist/1033 (<= Visual Studio 2015)
98 # - %VCINSTALLDIR%/Redist/MSVC/* (>= Visual Studio 2017)
110 set(_vcredist_name "vcredist_${TARGET_MACHINE}.exe")
111 if(MSVC_VERSION GREATER_EQUAL 1910)
112 set(_ws_vcredist_subdir "vcredist_MSVC2017")
113 set(_ms_vcredist_subdir "Redist/MSVC/14.10.25008")
114 elseif(MSVC_VERSION GREATER_EQUAL 1900)
115 set(_ws_vcredist_subdir "vcredist_MSVC2015")
116 set(_ms_vcredist_subdir "redist/1033")
117 elseif(MSVC_VERSION GREATER_EQUAL 1800)
118 set(_ws_vcredist_subdir "vcredist_MSVC2013")
119 set(_ms_vcredist_subdir "redist/1033")
122 find_program(VCREDIST_EXE "${_vcredist_name}"
123 PATHS "${_PROJECT_LIB_DIR}" ENV "VCINSTALLDIR"
124 PATH_SUFFIXES ${_ws_vcredist_subdir} ${_ms_vcredist_subdir}
128 file(TO_NATIVE_PATH "${VCREDIST_EXE}" VCREDIST_EXE)
129 message(STATUS "Using ${VCREDIST_EXE} for the installer")
132 # Ideally we would generate this at compile time using a separate cmake
133 # module, e.g. cmake/modules/configure_nsis_file.cmake. However we would
134 # have to figure out a clean way to pass in the variables above.
135 file(READ "${CMAKE_CURRENT_SOURCE_DIR}/config.nsh.in" _config_nsh_contents)
136 string(REPLACE "!define" "#cmakedefine" _config_nsh_contents "${_config_nsh_contents}")
137 string(CONFIGURE "${_config_nsh_contents}" _config_nsh_contents)
138 string(REPLACE "#define" "!define" _config_nsh_contents "${_config_nsh_contents}")
139 string(REPLACE "#undef" "!undef" _config_nsh_contents "${_config_nsh_contents}")
140 file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/config.nsh" "${_config_nsh_contents}")
142 # all-manifest.nsh. Can be created at configure time.
143 set(_all_manifest "${CMAKE_CURRENT_BINARY_DIR}/all-manifest.nsh")
144 set(_all_manifest_contents "# Files required for all sections. Generated by CMake.\n")
145 foreach(_dll ${GLIB2_DLLS} ${CARES_DLL} ${GCRYPT_DLLS} ${GEOIP_DLL}
146 ${GNUTLS_DLLS} ${KERBEROS_DLLS} ${LIBSSH_DLL} ${LUA_DLL}
147 ${LZ4_DLL} ${NGHTTP2_DLL} ${SBC_DLL} ${SMI_DLL} ${SNAPPY_DLL}
148 ${SPANDSP_DLL} ${BCG729_DLL} ${LIBXML2_DLL} ${WINSPARKLE_DLL} ${ZLIB_DLL}
150 set(_all_manifest_contents "${_all_manifest_contents}File \"\${STAGING_DIR}\\${_dll}\"\n")
152 foreach(_script "init.lua" "console.lua" "dtd_gen.lua")
153 set(_all_manifest_contents "${_all_manifest_contents}File \"\${STAGING_DIR}\\${_script}\"\n")
155 file(WRITE "${_all_manifest}" "${_all_manifest_contents}")
157 # gtk-dll-manifest.nsh. Can be created at configure time.
158 set(_gtk_dll_manifest "${CMAKE_CURRENT_BINARY_DIR}/gtk-dll-manifest.nsh")
159 set(_gtk_dll_manifest_contents "# Files required for the GTK+ section. Generated by CMake.\n")
160 if(BUILD_wireshark_gtk AND GTK_FOUND)
161 foreach(_dll ${GTK2_DLLS} ${GTK3_DLLS})
162 set(_gtk_dll_manifest_contents "${_gtk_dll_manifest_contents}File \"\${STAGING_DIR}\\${_dll}\"\n")
164 set(_gtk_dll_manifest_contents "${_gtk_dll_manifest_contents}# Subdirectories\n")
166 set(_gtk_dll_manifest_contents "${_gtk_dll_manifest_contents}SetOutPath \$INSTDIR\\etc\\gtk-2.0\n")
167 set(_gtk_dll_manifest_contents "${_gtk_dll_manifest_contents}File \"\${STAGING_DIR}\\etc\\gtk-2.0\\*.*\"\n")
169 if(GTK2_ENGINES_DLL_DIR)
170 set(_gtk_dll_manifest_contents "${_gtk_dll_manifest_contents}SetOutPath \$INSTDIR\\lib\\gtk-2.0\\2.10.0\\engines\n")
171 set(_gtk_dll_manifest_contents "${_gtk_dll_manifest_contents}File \"\${STAGING_DIR}\\lib\\gtk-2.0\\2.10.0\\engines\\*.*\"\n")
173 set(_gtk_dll_manifest_contents "${_gtk_dll_manifest_contents}SetOutPath \$INSTDIR\\lib\\gtk-2.0\\modules\n")
174 set(_gtk_dll_manifest_contents "${_gtk_dll_manifest_contents}File \"\${STAGING_DIR}\\lib\\gtk-2.0\\modules\\*.*\"\n")
177 file(WRITE "${_gtk_dll_manifest}" "${_gtk_dll_manifest_contents}")
179 file(TO_NATIVE_PATH "${DATAFILE_DIR}" _staging_dir)
180 file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}" _nsis_include_dir)
182 # Variables we can't set via config.nsh.
184 -DSTAGING_DIR=${_staging_dir}
185 -DNSIS_INCLUDE_DIR=${_nsis_include_dir}
189 # We want to sign all of the executables that we ship in the official
190 # installers. This means that uninstall.exe must be built separately AND
191 # that building the installer itself won't overwrite uninstall.exe
192 macro( ADD_NSIS_UNINSTALLER_TARGET )
193 set (_nsis_source_dir ${CMAKE_SOURCE_DIR}/packaging/nsis )
194 set (_nsis_binary_dir ${CMAKE_BINARY_DIR}/packaging/nsis )
196 add_custom_command(OUTPUT ${DATAFILE_DIR}/uninstall.exe
197 DEPENDS ${_nsis_source_dir}/uninstall.nsi
198 ${_nsis_source_dir}/common.nsh
199 COMMAND ${MAKENSIS_EXECUTABLE} ${NSIS_DEFINES}
201 COMMAND ${DATAFILE_DIR}/uninstall_installer.exe
202 COMMAND ${CMAKE_COMMAND} -E remove ${DATAFILE_DIR}/uninstall_installer.exe
203 WORKING_DIRECTORY ${_nsis_source_dir}
205 endmacro( ADD_NSIS_UNINSTALLER_TARGET )
207 macro( ADD_NSIS_PACKAGE_TARGET )
208 #set (_nsis_package ${CMAKE_BINARY_DIR}/packaging/nsis/Wireshark-$(WIRESHARK_TARGET_PLATFORM)-$(VERSION).exe)
210 # qt-dll-manifest.nsh. Created using Wireshark.exe.
211 add_custom_command(OUTPUT ${_nsis_binary_dir}/qt-dll-manifest.nsh
212 COMMAND set "PATH=${QT_BIN_PATH};%PATH%"
213 COMMAND ${POWERSHELL_COMMAND} "${_nsis_source_dir}/windeployqt-to-nsis.ps1"
214 -Executable $<TARGET_FILE:wireshark>
215 -FilePath ${_nsis_binary_dir}/qt-dll-manifest.nsh
218 # Build NSIS package dependencies. We build the package in two stages
219 # so that nsis_package below doesn't trigger any dependencies that
220 # might clobber any signed executables.
221 add_custom_target(nsis_package_prep
226 ${CMAKE_BINARY_DIR}/docbook/user-guide.chm
227 ${DATAFILE_DIR}/uninstall.exe
229 set_target_properties(nsis_package_prep PROPERTIES FOLDER "Packaging")
231 # Dump the installer into ${CMAKE_CURRENT_SOURCE_DIR}/packaging/nsis
232 # Note that executables and DLLs *must* be built separately
233 add_custom_target(nsis_package
234 COMMAND ${MAKENSIS_EXECUTABLE} ${NSIS_DEFINES}
236 WORKING_DIRECTORY ${_nsis_source_dir}
238 set_target_properties(nsis_package PROPERTIES FOLDER "Packaging")
239 endmacro( ADD_NSIS_PACKAGE_TARGET )
248 ${DATAFILE_DIR}/uninstall.exe
249 wireshark-$(WIRESHARK_TARGET_PLATFORM)-$(VERSION).exe