af72339c61f293764b399ba32f7c5066c8266f25
[metze/wireshark/wip.git] / packaging / nsis / 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 # 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.
11 #
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.
16 #
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.
20 #
21
22 # We should use CPack to generate the NSIS package. Even better,
23 # we should use CPack to create a .msi using WIX.
24
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
30 )
31 set(NSIS_GENERATED_FILES ${NSIS_GENERATED_FILES} PARENT_SCOPE)
32
33 set(NSIS_FILES
34         wireshark.nsi
35         uninstall.nsi
36         common.nsh
37         GetWindowsVersion.nsh
38         servicelib.nsh
39         AdditionalTasksPage.ini
40         WinPcapPage.ini
41         USBPcapPage.ini
42         ${NSIS_GENERATED_FILES}
43         PARENT_SCOPE
44 )
45
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)
56 else()
57         message(FATAL_ERROR "Your mysterious moon-man architecture \"${WIRESHARK_TARGET_PLATFORM}\" frightens and confuses us.")
58 endif()
59
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}")
64
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}")
68
69 set(USBPCAP_DISPLAY_VERSION "1.2.0.3")
70
71 set(PRODUCT_VERSION ${PROJECT_MAJOR_VERSION}.${PROJECT_MINOR_VERSION}.${PROJECT_PATCH_VERSION}.${PROJECT_BUILD_VERSION})
72
73 # To do:
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})
79
80 #add_custom_target(build_nsis_package
81 #       DEPENDS
82 #               wireshark-$(WIRESHARK_TARGET_PLATFORM)-$(VERSION).exe
83 #)
84
85 if(BUILD_wireshark AND QT_FOUND)
86         set (QT_DIR "\${STAGING_DIR}")
87 endif()
88
89 if(BUILD_wireshark_gtk AND GTK_FOUND)
90         set (GTK_DIR "\${STAGING_DIR}")
91 endif()
92
93 # Look for the Visual C++ Redistributable packages in the following locations:
94 # - _PROJECT_LIB_DIR
95 # - _PROJECT_LIB_DIR/vcredist_MSVCxx
96 # - %VCINSTALLDIR%
97 # - %VCINSTALLDIR%/redist/1033 (<= Visual Studio 2015)
98 # - %VCINSTALLDIR%/Redist/MSVC/* (>= Visual Studio 2017)
99 # MSVC_VERSION
100 # 1200 = VS  6.0
101 # 1300 = VS  7.0
102 # 1310 = VS  7.1
103 # 1400 = VS  8.0
104 # 1500 = VS  9.0
105 # 1600 = VS 10.0
106 # 1700 = VS 11.0
107 # 1800 = VS 12.0
108 # 1900 = VS 14.0
109 # 1910 = VS 15.0
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")
120 endif()
121
122 find_program(VCREDIST_EXE "${_vcredist_name}"
123         PATHS "${_PROJECT_LIB_DIR}" ENV "VCINSTALLDIR"
124         PATH_SUFFIXES ${_ws_vcredist_subdir} ${_ms_vcredist_subdir}
125         NO_DEFAULT_PATH
126 )
127 if(VCREDIST_EXE)
128         file(TO_NATIVE_PATH "${VCREDIST_EXE}" VCREDIST_EXE)
129         message(STATUS "Using ${VCREDIST_EXE} for the installer")
130 endif()
131
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}")
141
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}
149         )
150         set(_all_manifest_contents "${_all_manifest_contents}File \"\${STAGING_DIR}\\${_dll}\"\n")
151 endforeach()
152 foreach(_script "init.lua" "console.lua" "dtd_gen.lua")
153         set(_all_manifest_contents "${_all_manifest_contents}File \"\${STAGING_DIR}\\${_script}\"\n")
154 endforeach()
155 file(WRITE "${_all_manifest}" "${_all_manifest_contents}")
156
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")
163         endforeach()
164         set(_gtk_dll_manifest_contents "${_gtk_dll_manifest_contents}# Subdirectories\n")
165         if(GTK2_ETC_DIR)
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")
168         endif()
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")
172         endif()
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")
175         # XXX Schemas (GTK3)
176 endif()
177 file(WRITE "${_gtk_dll_manifest}" "${_gtk_dll_manifest_contents}")
178
179 file(TO_NATIVE_PATH "${DATAFILE_DIR}" _staging_dir)
180 file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}" _nsis_include_dir)
181
182 # Variables we can't set via config.nsh.
183 set(NSIS_DEFINES
184         -DSTAGING_DIR=${_staging_dir}
185         -DNSIS_INCLUDE_DIR=${_nsis_include_dir}
186         PARENT_SCOPE
187 )
188
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 )
195
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}
200                         uninstall.nsi
201                 COMMAND ${DATAFILE_DIR}/uninstall_installer.exe
202                 COMMAND ${CMAKE_COMMAND} -E remove ${DATAFILE_DIR}/uninstall_installer.exe
203                 WORKING_DIRECTORY ${_nsis_source_dir}
204         )
205 endmacro( ADD_NSIS_UNINSTALLER_TARGET )
206
207 macro( ADD_NSIS_PACKAGE_TARGET )
208         #set (_nsis_package ${CMAKE_BINARY_DIR}/packaging/nsis/Wireshark-$(WIRESHARK_TARGET_PLATFORM)-$(VERSION).exe)
209
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
216         )
217
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
222                 DEPENDS
223                         ${NSIS_FILES}
224                         copy_data_files
225                         user_guides
226                         ${CMAKE_BINARY_DIR}/docbook/user-guide.chm
227                         ${DATAFILE_DIR}/uninstall.exe
228         )
229         set_target_properties(nsis_package_prep PROPERTIES FOLDER "Packaging")
230
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}
235                         wireshark.nsi
236                 WORKING_DIRECTORY ${_nsis_source_dir}
237         )
238         set_target_properties(nsis_package PROPERTIES FOLDER "Packaging")
239 endmacro( ADD_NSIS_PACKAGE_TARGET )
240
241 set(CLEAN_FILES
242         all-manifest.nsh
243         config.nsh
244         gtk-dll-manifest.nsh
245         #NEWS.txt
246         qt-dll-manifest.nsh
247         #user-guide.chm
248         ${DATAFILE_DIR}/uninstall.exe
249         wireshark-$(WIRESHARK_TARGET_PLATFORM)-$(VERSION).exe
250 )