-
Notifications
You must be signed in to change notification settings - Fork 20
/
build.ps1
401 lines (368 loc) · 14.5 KB
/
build.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
#!/usr/bin/env pwsh
param (
[switch]$DisableInteractive = $false,
[switch]$DoNotUpdateTOOL = $false,
[switch]$DoNotDeleteBuildFolder = $false,
[switch]$ForceStaticLib = $false,
[switch]$ForceTriangle32bit = $false,
[switch]$DisableLaTeX = $false,
[Int32]$ForceGCCVersion = 0,
[Int32]$BuildArch = 64,
[Int32]$NumberOfBuildWorkers = 8,
[string]$AdditionalBuildSetup = "" # "-DCMAKE_CUDA_ARCHITECTURES=30"
)
$build_ps1_version = "2.0.0"
$ErrorActionPreference = "SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
Start-Transcript -Path $PSScriptRoot/build.log
Function MyThrow ($Message) {
if ($DisableInteractive) {
Write-Host $Message -ForegroundColor Red
throw
}
else {
# Check if running in PowerShell ISE
if ($psISE) {
# "ReadKey" not supported in PowerShell ISE.
# Show MessageBox UI
$Shell = New-Object -ComObject "WScript.Shell"
$Shell.Popup($Message, 0, "OK", 0)
throw
}
$Ignore =
16, # Shift (left or right)
17, # Ctrl (left or right)
18, # Alt (left or right)
20, # Caps lock
91, # Windows key (left)
92, # Windows key (right)
93, # Menu key
144, # Num lock
145, # Scroll lock
166, # Back
167, # Forward
168, # Refresh
169, # Stop
170, # Search
171, # Favorites
172, # Start/Home
173, # Mute
174, # Volume Down
175, # Volume Up
176, # Next Track
177, # Previous Track
178, # Stop Media
179, # Play
180, # Mail
181, # Select Media
182, # Application 1
183 # Application 2
Write-Host $Message -ForegroundColor Red
Write-Host -NoNewline "Press any key to continue..."
while (($null -eq $KeyInfo.VirtualKeyCode) -or ($Ignore -contains $KeyInfo.VirtualKeyCode)) {
$KeyInfo = $Host.UI.RawUI.ReadKey("NoEcho, IncludeKeyDown")
}
Write-Host ""
throw
}
}
Write-Host "Build script version ${build_ps1_version}"
Write-Host "Setting parallelism to $env:NUMBER_OF_PROCESSORS"
$env:CMAKE_BUILD_PARALLEL_LEVEL = $env:NUMBER_OF_PROCESSORS
Write-Host -NoNewLine "PowerShell version:"
$PSVersionTable.PSVersion
if ($PSVersionTable.PSVersion.Major -eq 5) {
$IsWindowsPowerShell = $true
}
if ($PSVersionTable.PSVersion.Major -lt 5) {
MyThrow("Your PowerShell version is too old, please update it.")
}
if ($ForceStaticLib) {
Write-Host "Forced CMake to produce a static library"
$AdditionalBuildSetup = $AdditionalBuildSetup + " -DBUILD_SHARED_LIBS=OFF "
}
Push-Location $PSScriptRoot
$GIT_EXE = Get-Command "git" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Definition
if (-Not $GIT_EXE) {
MyThrow("Could not find git, please install it")
}
else {
Write-Host "Using git from ${GIT_EXE}"
}
if (Test-Path "$PSScriptRoot/.git") {
Write-Host "This tool has been cloned with git and supports self-updating mechanism"
if ($DoNotUpdateTOOL) {
Write-Host "This tool will not self-update sources" -ForegroundColor Yellow
}
else {
Write-Host "This tool will self-update sources, please pass -DoNotUpdateTOOL to the script to disable"
$proc = Start-Process -NoNewWindow -PassThru -FilePath $GIT_EXE -ArgumentList "pull"
$handle = $proc.Handle
$proc.WaitForExit()
$exitCode = $proc.ExitCode
if (-Not ($exitCode -eq 0)) {
MyThrow("Updating this tool sources failed! Exited with error code $exitCode.")
}
}
}
$CMAKE_EXE = Get-Command "cmake" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Definition
if (-Not $CMAKE_EXE) {
MyThrow("Could not find CMake, please install it")
}
else {
Write-Host "Using CMake from ${CMAKE_EXE}"
$proc = Start-Process -NoNewWindow -PassThru -FilePath ${CMAKE_EXE} -ArgumentList "--version"
$handle = $proc.Handle
$proc.WaitForExit()
$exitCode = $proc.ExitCode
if (-Not ($exitCode -eq 0)) {
MyThrow("CMake version check failed! Exited with error code $exitCode.")
}
}
function getProgramFiles32bit() {
$out = ${env:PROGRAMFILES(X86)}
if ($null -eq $out) {
$out = ${env:PROGRAMFILES}
}
if ($null -eq $out) {
MyThrow("Could not find [Program Files 32-bit]")
}
return $out
}
function getLatestVisualStudioWithDesktopWorkloadPath() {
$programFiles = getProgramFiles32bit
$vswhereExe = "$programFiles\Microsoft Visual Studio\Installer\vswhere.exe"
if (Test-Path $vswhereExe) {
$output = & $vswhereExe -products * -latest -requires Microsoft.VisualStudio.Workload.NativeDesktop -format xml
[xml]$asXml = $output
foreach ($instance in $asXml.instances.instance) {
$installationPath = $instance.InstallationPath -replace "\\$" # Remove potential trailing backslash
}
if (!$installationPath) {
Write-Host "Warning: no full Visual Studio setup has been found, extending search to include also partial installations" -ForegroundColor Yellow
$output = & $vswhereExe -products * -latest -format xml
[xml]$asXml = $output
foreach ($instance in $asXml.instances.instance) {
$installationPath = $instance.InstallationPath -replace "\\$" # Remove potential trailing backslash
}
}
if (!$installationPath) {
Write-Host "Warning: no full Visual Studio setup has been found, extending search to include also pre-release installations" -ForegroundColor Yellow
$output = & $vswhereExe -prerelease -products * -latest -format xml
[xml]$asXml = $output
foreach ($instance in $asXml.instances.instance) {
$installationPath = $instance.InstallationPath -replace "\\$" # Remove potential trailing backslash
}
}
if (!$installationPath) {
MyThrow("Could not locate any installation of Visual Studio")
}
}
else {
MyThrow("Could not locate vswhere at $vswhereExe")
}
return $installationPath
}
function getLatestVisualStudioWithDesktopWorkloadVersion() {
$programFiles = getProgramFiles32bit
$vswhereExe = "$programFiles\Microsoft Visual Studio\Installer\vswhere.exe"
if (Test-Path $vswhereExe) {
$output = & $vswhereExe -products * -latest -requires Microsoft.VisualStudio.Workload.NativeDesktop -format xml
[xml]$asXml = $output
foreach ($instance in $asXml.instances.instance) {
$installationVersion = $instance.InstallationVersion
}
if (!$installationVersion) {
Write-Host "Warning: no full Visual Studio setup has been found, extending search to include also partial installations" -ForegroundColor Yellow
$output = & $vswhereExe -products * -latest -format xml
[xml]$asXml = $output
foreach ($instance in $asXml.instances.instance) {
$installationVersion = $instance.installationVersion
}
}
if (!$installationVersion) {
Write-Host "Warning: no full Visual Studio setup has been found, extending search to include also pre-release installations" -ForegroundColor Yellow
$output = & $vswhereExe -prerelease -products * -latest -format xml
[xml]$asXml = $output
foreach ($instance in $asXml.instances.instance) {
$installationVersion = $instance.installationVersion
}
}
if (!$installationVersion) {
MyThrow("Could not locate any installation of Visual Studio")
}
}
else {
MyThrow("Could not locate vswhere at $vswhereExe")
}
return $installationVersion
}
if (-Not $DoNotSetupVS) {
$CL_EXE = Get-Command "cl" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Definition
if ((-Not $CL_EXE) -or ($CL_EXE -match "HostX86\\x86") -or ($CL_EXE -match "HostX64\\x86")) {
$vsfound = getLatestVisualStudioWithDesktopWorkloadPath
Write-Host "Found VS in ${vsfound}"
Push-Location "${vsfound}\Common7\Tools"
cmd.exe /c "VsDevCmd.bat -arch=x64 & set" |
ForEach-Object {
if ($_ -match "=") {
$v = $_.split("="); Set-Item -force -path "ENV:\$($v[0])" -value "$($v[1])"
}
}
Pop-Location
Write-Host "Visual Studio Command Prompt variables set"
}
$tokens = getLatestVisualStudioWithDesktopWorkloadVersion
$tokens = $tokens.split('.')
if ($DoNotUseNinja) {
$dllfolder = "Release"
$selectConfig = " --config Release "
if ($tokens[0] -eq "14") {
$generator = "Visual Studio 14 2015"
$AdditionalBuildSetup = $AdditionalBuildSetup + " -T `"host=x64`" -A `"x64`""
}
elseif ($tokens[0] -eq "15") {
$generator = "Visual Studio 15 2017"
$AdditionalBuildSetup = $AdditionalBuildSetup + " -T `"host=x64`" -A `"x64`""
}
elseif ($tokens[0] -eq "16") {
$generator = "Visual Studio 16 2019"
$AdditionalBuildSetup = $AdditionalBuildSetup + " -T `"host=x64`" -A `"x64`""
}
elseif ($tokens[0] -eq "17") {
$generator = "Visual Studio 17 2022"
$AdditionalBuildSetup = $AdditionalBuildSetup + " -T `"host=x64`" -A `"x64`""
}
else {
MyThrow("Unknown Visual Studio version, unsupported configuration")
}
}
if (-Not $UseVCPKG) {
$dllfolder = ""
}
}
Write-Host "Setting up environment to use CMake generator: $generator"
if (-Not $DoNotDeleteBuildFolder) {
Write-Host "Removing build folders" -ForegroundColor Yellow
Remove-Item -Force -Recurse -ErrorAction SilentlyContinue .\build_win_release64
Remove-Item -Force -Recurse -ErrorAction SilentlyContinue .\build_win_release32_triangle
Remove-Item -Force -Recurse -ErrorAction SilentlyContinue .\build_win_release32
}
if (($null -eq (Get-Command "latex" -ErrorAction SilentlyContinue)) -or $DisableLaTeX) {
Write-Host "LaTeX has not been found!" -ForegroundColor Yellow
}
else {
Write-Host "LaTeX has been found! Building manuals" -ForegroundColor Yellow
$latexFOUND = "-DBUILD_MANUAL=ON"
}
if ($BuildArch -eq "64") {
if ($ForceTriangle32bit) {
Write-Host "Triangle will be built as a 32 bit executable!" -ForegroundColor Yellow
New-Item -Path .\build_win_release64_notriangle -ItemType directory -Force | Out-Null
Set-Location build_win_release64_notriangle
$cmake_args = "-A x64 $latexFOUND ${install_prefix} -DSKIP_triangle:BOOL=ON .."
Write-Host "Configuring CMake project" -ForegroundColor Green
Write-Host "CMake args: $cmake_args"
$proc = Start-Process -NoNewWindow -PassThru -FilePath $CMAKE_EXE -ArgumentList $cmake_args
$handle = $proc.Handle
$proc.WaitForExit()
$exitCode = $proc.ExitCode
if (-Not ($exitCode -eq 0)) {
MyThrow("Config failed! Exited with error code $exitCode.")
}
Write-Host "Building CMake project" -ForegroundColor Green
$cmake_args = "--build . ${selectConfig} --parallel ${NumberOfBuildWorkers} --target install"
Write-Host "CMake args: $cmake_args"
$proc = Start-Process -NoNewWindow -PassThru -FilePath $CMAKE_EXE -ArgumentList $cmake_args
$handle = $proc.Handle
$proc.WaitForExit()
$exitCode = $proc.ExitCode
if (-Not ($exitCode -eq 0)) {
MyThrow("Build failed! Exited with error code $exitCode.")
}
Set-Location ..
New-Item -Path .\build_win_release32_triangle -ItemType directory -Force | Out-Null
Set-Location build_win_release32_triangle
$cmake_args = "-A Win32 $latexFOUND ${install_prefix} -DSKIP_belasolv:BOOL=ON -DSKIP_csolv:BOOL=ON -DSKIP_liblua:BOOL=ON -DSKIP_ResizableLib:BOOL=ON -DSKIP_femm:BOOL=ON -DSKIP_femmplot:BOOL=ON -DSKIP_fkn:BOOL=ON -DSKIP_hsolv:BOOL=ON -DSKIP_scifemm:BOOL=ON .."
Write-Host "Configuring CMake project" -ForegroundColor Green
Write-Host "CMake args: $cmake_args"
$proc = Start-Process -NoNewWindow -PassThru -FilePath $CMAKE_EXE -ArgumentList $cmake_args
$handle = $proc.Handle
$proc.WaitForExit()
$exitCode = $proc.ExitCode
if (-Not ($exitCode -eq 0)) {
MyThrow("Config failed! Exited with error code $exitCode.")
}
Write-Host "Building CMake project" -ForegroundColor Green
$cmake_args = "--build . ${selectConfig} --parallel ${NumberOfBuildWorkers} --target install"
Write-Host "CMake args: $cmake_args"
$proc = Start-Process -NoNewWindow -PassThru -FilePath $CMAKE_EXE -ArgumentList $cmake_args
$handle = $proc.Handle
$proc.WaitForExit()
$exitCode = $proc.ExitCode
if (-Not ($exitCode -eq 0)) {
MyThrow("Build failed! Exited with error code $exitCode.")
}
}
else {
New-Item -Path .\build_win_release64 -ItemType directory -Force | Out-Null
Set-Location build_win_release64
$cmake_args = "-A x64 $latexFOUND ${install_prefix} .."
Write-Host "Configuring CMake project" -ForegroundColor Green
Write-Host "CMake args: $cmake_args"
$proc = Start-Process -NoNewWindow -PassThru -FilePath $CMAKE_EXE -ArgumentList $cmake_args
$handle = $proc.Handle
$proc.WaitForExit()
$exitCode = $proc.ExitCode
if (-Not ($exitCode -eq 0)) {
MyThrow("Config failed! Exited with error code $exitCode.")
}
Write-Host "Building CMake project" -ForegroundColor Green
$cmake_args = "--build . ${selectConfig} --parallel ${NumberOfBuildWorkers} --target install"
Write-Host "CMake args: $cmake_args"
$proc = Start-Process -NoNewWindow -PassThru -FilePath $CMAKE_EXE -ArgumentList $cmake_args
$handle = $proc.Handle
$proc.WaitForExit()
$exitCode = $proc.ExitCode
if (-Not ($exitCode -eq 0)) {
MyThrow("Build failed! Exited with error code $exitCode.")
}
}
}
if ($BuildArch -eq "32") {
New-Item -Path .\build_win_release32 -ItemType directory -Force | Out-Null
Set-Location build_win_release32
$cmake_args = "-A Win32 $latexFOUND ${install_prefix} .."
Write-Host "Configuring CMake project" -ForegroundColor Green
Write-Host "CMake args: $cmake_args"
$proc = Start-Process -NoNewWindow -PassThru -FilePath $CMAKE_EXE -ArgumentList $cmake_args
$handle = $proc.Handle
$proc.WaitForExit()
$exitCode = $proc.ExitCode
if (-Not ($exitCode -eq 0)) {
MyThrow("Config failed! Exited with error code $exitCode.")
}
Write-Host "Building CMake project" -ForegroundColor Green
$cmake_args = "--build . ${selectConfig} --parallel ${NumberOfBuildWorkers} --target install"
Write-Host "CMake args: $cmake_args"
$proc = Start-Process -NoNewWindow -PassThru -FilePath $CMAKE_EXE -ArgumentList $cmake_args
$handle = $proc.Handle
$proc.WaitForExit()
$exitCode = $proc.ExitCode
if (-Not ($exitCode -eq 0)) {
MyThrow("Build failed! Exited with error code $exitCode.")
}
}
Set-Location ..
if (-Not $DoNotDeleteBuildFolder) {
Write-Host "Removing build folders" -ForegroundColor Yellow
Remove-Item -Force -Recurse -ErrorAction SilentlyContinue .\build_win_release64
Remove-Item -Force -Recurse -ErrorAction SilentlyContinue .\build_win_release32_triangle
Remove-Item -Force -Recurse -ErrorAction SilentlyContinue .\build_win_release32
}
Write-Host "Build complete!" -ForegroundColor Green
Pop-Location
$ErrorActionPreference = "SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"