-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
102 lines (91 loc) · 3.42 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
#!/usr/bin/env pwsh
# $args[0] = Release/Debug
# $args[1] = other cmake defines
[CmdletBinding()]
Param
(
[parameter(mandatory=$true, position=0)][string]$build_type,
[parameter(mandatory=$false, position=1, ValueFromRemainingArguments=$true)]$other_cmake_flags
)
$number_of_build_workers=(Get-CimInstance Win32_ComputerSystem).NumberOfLogicalProcessors
function getProgramFiles32bit() {
$out = ${env:PROGRAMFILES(X86)}
if ($null -eq $out) {
$out = ${env:PROGRAMFILES}
}
if ($null -eq $out) {
Write-Host "Could not find [Program Files 32-bit]" -ForegroundColor Yellow
}
return $out
}
function getLatestVisualStudioWithDesktopWorkloadPath() {
$programFiles = getProgramFiles32bit
$vswhereExe = "$programFiles\Microsoft Visual Studio\Installer\vswhere.exe"
if (-Not (Test-Path $vswhereExe)) {
$vswhereExe = "C:\ProgramData\chocolatey\bin\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 (-Not ($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 (-Not ($installationPath)) {
Write-Host "Critical: could not locate any installation of Visual Studio" -ForegroundColor Red
}
}
else {
Write-Host "Could not locate vswhere at $vswhereExe" -ForegroundColor Yellow
}
return $installationPath
}
if ($null -eq (Get-Command "cl.exe" -ErrorAction SilentlyContinue)) {
$vsfound = getLatestVisualStudioWithDesktopWorkloadPath
if ($vsfound) {
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" -ForegroundColor Yellow
}
}
Push-Location $PSScriptRoot
If ( $build_type -eq "Debug" -or $build_type -eq "debug" )
{
# DEBUG
#Remove-Item .\build_win_debug -Force -Recurse -ErrorAction SilentlyContinue
New-Item -Path .\build_win_debug -ItemType directory -Force
Set-Location build_win_debug
cmake -G "Visual Studio 16 2019" -T "host=x64" -A "x64" "-DCMAKE_BUILD_TYPE=Debug" ${other_cmake_flags} ..
cmake --build . --config Debug --target install
Set-Location ..
}
ElseIf ( $build_type -eq "Release" -or $build_type -eq "release" )
{
# RELEASE
#Remove-Item .\build_win_release -Force -Recurse -ErrorAction SilentlyContinue
New-Item -Path .\build_win_release -ItemType directory -Force
Set-Location build_win_release
cmake -G "Visual Studio 16 2019" -T "host=x64" -A "x64" "-DCMAKE_BUILD_TYPE=Release" ${other_cmake_flags} ..
cmake --build . --config Release --target install
Set-Location ..
}
Else
{
Write-Host "Unknown build type - Allowed only [Debug, Release]" -ForeGroundColor Red
exit 1
}
Pop-Location