forked from jamulussoftware/jamulus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy_windows.ps1
213 lines (181 loc) · 6.71 KB
/
deploy_windows.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
param(
# Replace default path with system Qt installation folder if necessary
[string] $QtInstallPath = "C:\Qt\5.12.3"
)
# Global constants
$RootPath = "$PWD"
$BuildPath = "$RootPath\build"
$DeployPath = "$RootPath\deploy"
$WindowsPath ="$RootPath\windows"
$AppName = "Jamulus"
# Stop at all errors
$ErrorActionPreference = "Stop"
# Execute native command with errorlevel handling
Function Execute-Native-Command {
Param(
[string] $Command,
[string[]] $Arguments
)
& "$Command" @Arguments
if ($LastExitCode -Ne 0)
{
Throw "Native command $Command returned with exit code $LastExitCode"
}
}
# Cleanup existing build folders
Function Clean-Build-Environment
{
if (Test-Path -Path $BuildPath) { Remove-Item -Path $BuildPath -Recurse -Force }
if (Test-Path -Path $DeployPath) { Remove-Item -Path $DeployPath -Recurse -Force }
New-Item -Path $BuildPath -ItemType Directory
New-Item -Path $DeployPath -ItemType Directory
}
# Download and uncompress dependency in ZIP format
Function Install-Dependency
{
param(
[Parameter(Mandatory=$true)]
[string] $Uri,
[Parameter(Mandatory=$true)]
[string] $Name,
[Parameter(Mandatory=$true)]
[string] $Destination
)
if (Test-Path -Path "$WindowsPath\$Destination") { return }
$TempFileName = [System.IO.Path]::GetTempFileName() + ".zip"
$TempDir = [System.IO.Path]::GetTempPath()
Invoke-WebRequest -Uri $Uri -OutFile $TempFileName
echo $TempFileName
Expand-Archive -Path $TempFileName -DestinationPath $TempDir -Force
echo $WindowsPath\$Destination
Move-Item -Path "$TempDir\$Name" -Destination "$WindowsPath\$Destination" -Force
Remove-Item -Path $TempFileName -Force
}
# Install VSSetup (Visual Studio detection), ASIO SDK and NSIS Installer
Function Install-Dependencies
{
Install-PackageProvider -Name "Nuget" -Scope CurrentUser -Force
Install-Module -Name "VSSetup" -Scope CurrentUser -Force
Install-Dependency -Uri "http://www.steinberg.net/sdk_downloads/ASIOSDK2.3.2.zip" `
-Name "ASIOSDK2.3.2" -Destination "ASIOSDK2"
Install-Dependency -Uri "https://jztkft.dl.sourceforge.net/project/nsis/NSIS%203/3.06.1/nsis-3.06.1.zip" `
-Name "nsis-3.06.1" -Destination "NSIS"
}
# Setup environment variables and build tool paths
Function Setup-Build-Environment
{
param(
[Parameter(Mandatory=$true)]
[string] $QtInstallPath,
[Parameter(Mandatory=$true)]
[string] $BuildArch
)
# Look for Visual Studio/Build Tools 2017 or later (version 15.0 or above)
$VsInstallPath = Get-VSSetupInstance | `
Select-VSSetupInstance -Product "*" -Version "15.0" -Latest | `
Select-Object -ExpandProperty "InstallationPath"
if ($VsInstallPath -Eq "") { $VsInstallPath = "<N/A>" }
if ($BuildArch -Eq "x86_64")
{
$VcVarsBin = "$VsInstallPath\VC\Auxiliary\build\vcvars64.bat"
$QtMsvcSpecPath = "$QtInstallPath\msvc2017_64\bin"
}
else
{
$VcVarsBin = "$VsInstallPath\VC\Auxiliary\build\vcvars32.bat"
$QtMsvcSpecPath = "$QtInstallPath\msvc2017\bin"
}
# Setup Qt executables paths for later calls
Set-Item Env:QtQmakePath "$QtMsvcSpecPath\qmake.exe"
Set-Item Env:QtWinDeployPath "$QtMsvcSpecPath\windeployqt.exe"
""
"**********************************************************************"
"Using Visual Studio/Build Tools environment settings located at"
$VcVarsBin
"**********************************************************************"
""
"**********************************************************************"
"Using Qt binaries for Visual C++ located at"
$QtMsvcSpecPath
"**********************************************************************"
""
if (-Not (Test-Path -Path $VcVarsBin))
{
Throw "Microsoft Visual Studio ($BuildArch variant) is not installed. " + `
"Please install Visual Studio 2017 or above it before running this script."
}
if (-Not (Test-Path -Path $Env:QtQmakePath))
{
Throw "The Qt binaries for Microsoft Visual C++ 2017 (msvc2017) could not be located. " + `
"Please install Qt with support for MSVC 2017 before running this script," + `
"then call this script with the Qt install location, for example C:\Qt\5.12.3"
}
# Import environment variables set by vcvarsXX.bat into current scope
$EnvDump = [System.IO.Path]::GetTempFileName()
Execute-Native-Command -Command "cmd" `
-Arguments ("/c", "`"$VcVarsBin`" && set > `"$EnvDump`"")
foreach ($_ in Get-Content -Path $EnvDump)
{
if ($_ -Match "^([^=]+)=(.*)$")
{
Set-Item "Env:$($Matches[1])" $Matches[2]
}
}
Remove-Item -Path $EnvDump -Force
}
# Build Jamulus x86_64 and x86
Function Build-App
{
param(
[Parameter(Mandatory=$true)]
[string] $BuildConfig,
[Parameter(Mandatory=$true)]
[string] $BuildArch
)
Execute-Native-Command -Command "$Env:QtQmakePath" `
-Arguments ("$RootPath\$AppName.pro", "CONFIG+=$BuildConfig $BuildArch", `
"-o", "$BuildPath\Makefile")
Set-Location -Path $BuildPath
Execute-Native-Command -Command "nmake" -Arguments ("$BuildConfig")
Execute-Native-Command -Command "$Env:QtWinDeployPath" `
-Arguments ("--$BuildConfig", "--compiler-runtime", "--dir=$DeployPath\$BuildArch",
"$BuildPath\$BuildConfig\$AppName.exe")
Move-Item -Path "$BuildPath\$BuildConfig\$AppName.exe" -Destination "$DeployPath\$BuildArch" -Force
Execute-Native-Command -Command "nmake" -Arguments ("clean")
Set-Location -Path $RootPath
}
# Build and deploy Jamulus 64bit and 32bit variants
function Build-App-Variants
{
param(
[Parameter(Mandatory=$true)]
[string] $QtInstallPath
)
foreach ($_ in ("x86_64", "x86"))
{
$OriginalEnv = Get-ChildItem Env:
Setup-Build-Environment -QtInstallPath $QtInstallPath -BuildArch $_
Build-App -BuildConfig "release" -BuildArch $_
$OriginalEnv | % { Set-Item "Env:$($_.Name)" $_.Value }
}
}
# Build Windows installer
Function Build-Installer
{
foreach ($_ in Get-Content -Path "$RootPath\$AppName.pro")
{
if ($_ -Match "^VERSION *= *(.*)$")
{
$AppVersion = $Matches[1]
break
}
}
Execute-Native-Command -Command "$WindowsPath\NSIS\makensis" `
-Arguments ("/v4", "/DAPP_NAME=$AppName", "/DAPP_VERSION=$AppVersion", `
"/DROOT_PATH=$RootPath", "/DWINDOWS_PATH=$WindowsPath", "/DDEPLOY_PATH=$DeployPath", `
"$WindowsPath\installer.nsi")
}
Clean-Build-Environment
Install-Dependencies
Build-App-Variants -QtInstallPath $QtInstallPath
Build-Installer