More licenses converted to SPDX.
[metze/wireshark/wip.git] / packaging / nsis / windeployqt-to-nsis.ps1
1 # windeployqt-to-nsh
2 #
3 # Windeployqt-to-nsh - Convert the output of windeployqt to an equivalent set of
4 # NSIS "File" function calls.
5 #
6 # Copyright 2014 Gerald Combs <gerald@wireshark.org>
7 #
8 # Wireshark - Network traffic analyzer
9 # By Gerald Combs <gerald@wireshark.org>
10 # Copyright 1998 Gerald Combs
11 #
12 # SPDX-License-Identifier: GPL-2.0-or-later
13
14 #requires -version 2
15
16 <#
17 .SYNOPSIS
18 Creates NSIS "File" function calls required for Qt packaging.
19
20 .DESCRIPTION
21 This script creates an NSIS-compatible file based on the following Qt
22 versions:
23
24   - 5.3 and later: A list of DLLs and directories based on the output of the
25     "windeployqt" utility. Windeployqt lists the DLLs required to run a Qt
26     application. (The initial version that shipped with Qt 5.2 is unusable.)
27
28   - 5.2 and earlier: A hard-coded list of Qt DLLs and directories appropriate
29     for earlier Qt versions.
30
31   - None: A dummy file.
32
33 If building with Qt, QMake must be in your PATH.
34
35 .PARAMETER Executable
36 The path to a Qt application. It will be examined for dependent DLLs.
37
38 .PARAMETER FilePath
39 Output filename.
40
41 .INPUTS
42 -Executable Path to the Qt application.
43 -FilePath Output NSIS file.
44
45 .OUTPUTS
46 List of NSIS commands required to package supporting DLLs.
47
48 .EXAMPLE
49 C:\PS> .\windeployqt-to-nsis.ps1 windeployqt.exe ..\..\staging\wireshark.exe qt-dll-manifest.nsh
50 #>
51
52 Param(
53     [Parameter(Mandatory=$true, Position=0)]
54     [String] $Executable,
55
56     [Parameter(Position=1)]
57     [String] $FilePath = "qt-dll-manifest.nsh"
58 )
59
60
61 try {
62     $qtVersion = [version](qmake -query QT_VERSION)
63     $nsisCommands = @("# Qt version " + $qtVersion ; "#")
64
65     if ($qtVersion -ge "5.3") {
66         # Qt 5.3 or later. Windeployqt is present and works
67
68         $wdqtList = windeployqt `
69             --release `
70             --no-compiler-runtime `
71             --list relative `
72             $Executable
73
74         $dllPath = Split-Path -Parent $Executable
75
76         $dllList = @()
77         $dirList = @()
78
79         foreach ($entry in $wdqtList) {
80             $dir = Split-Path -Parent $entry
81             if ($dir) {
82                 $dirList += "File /r `"$dllPath\$dir`""
83             } else {
84                 $dllList += "File `"$dllPath\$entry`""
85             }
86         }
87
88         $dirList = $dirList | Sort-Object | Get-Unique
89
90         $nsisCommands += $dllList + $dirList
91
92     } elseif ($qtVersion -ge "5.0") {
93         # Qt 5.0 - 5.2. Windeployqt is buggy or not present
94
95         $nsisCommands += @"
96 File "..\..\wireshark-qt-release\Qt5Core.dll"
97 File "..\..\wireshark-qt-release\Qt5Gui.dll"
98 File "..\..\wireshark-qt-release\Qt5Widgets.dll"
99 File "..\..\wireshark-qt-release\Qt5PrintSupport.dll"
100 File /r "..\..\wireshark-qt-release\platforms"
101 "@
102
103     } else {
104         # Assume Qt 4
105
106         $nsisCommands += @"
107 File "..\..\wireshark-qt-release\QtCore4.dll"
108 File "..\..\wireshark-qt-release\QtGui4.dll"
109 "@
110
111     }
112 }
113
114 catch {
115
116     $nsisCommands = @"
117 # Qt not configured
118 #
119 "@
120
121 }
122
123 Set-Content $FilePath @"
124 #
125 # Automatically generated by $($MyInvocation.MyCommand.Name)
126 #
127 "@
128
129 Add-Content $FilePath $nsisCommands