-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ps1
97 lines (89 loc) · 2.85 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
Param(
[string]$Configuration = "Debug",
[switch]$Clean,
[switch]$Force
)
$ErrorActionPreference = "Stop"
$WorkingDirectory="$PSScriptRoot\Build"
$ENV:Path = $ENV:Path + ";$($Env:ProgramFiles)\CMake\bin"
function Find-Tool
{
param(
[Parameter(Mandatory=$true)]
[string]$Command
)
Get-Command $Command | Select-Object -ExpandProperty Definition
}
function Install-Prerequisites
{
$ChocoExe = (& Find-Tool "choco.exe")
if (-not $ChocoExe)
{
Write-Host -ForegroundColor Green "In order to be sure have the right tools this script installs Chocolatey."
$YN = Read-Host -Prompt "Are you okay with this? (y/n):"
if ($YN -ieq "y" -or $YN -ieq "yes")
{
Write-Host -ForegroundColor Yellow "Installing Chocolatey..."
Start-Process "$($Env:SystemRoot)\System32\WindowsPowerShell\v1.0\powershell.exe" `
-ArgumentList @("-NoProfile", "-ExecutionPolicy", "Bypass", "-Command",
"iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))", "-NoExit")
-Verb RunAs -Wait
$ChocoExe = "$($Env:ProgramData)\chocolatey\bin\choco.exe"
}
else
{
Write-Host -ForegroundColor Yellow "Goodbye!"
exit 1
}
}
$CMakeExe = (& Find-Tool "cmake.exe")
if (-not $CMakeExe)
{
Write-Host -ForegroundColor Yellow "Installing CMake..."
Start-Process $ChocoExe -ArgumentList @("install", "cmake", "-y", "--force") -Verb RunAs -Wait
Write-Host -ForegroundColor Yellow "Close this window and open a new PowerShell window to be sure your path is up to date."
exit 0
}
}
function Start-Clean
{
Write-Host -ForegroundColor Yellow "Cleaning working directory..."
Remove-Item -Recurse -Force "$WorkingDirectory" -EA SilentlyContinue
}
function Start-Configure
{
if (-not (Test-Path "$WorkingDirectory\CMakeCache.txt"))
{
Write-Host -ForegroundColor Yellow "Configuring CMake..."
Remove-Item -Recurse -Force "$WorkingDirectory" -EA SilentlyContinue
New-Item -Path "$WorkingDirectory" -ItemType Directory -Force
Set-Location "$WorkingDirectory"
# TODO: Detect and support latest Visual Studio that is installed here
# Right now we are just hard-coded to VS 2017
cmake.exe ../src -G "Visual Studio 15 2017 Win64"
}
}
function Start-Build
{
Set-Location "$WorkingDirectory"
# TODO: Run build automatically
# For now, just open Visual Studio 2017
Write-Host -ForegroundColor Yellow "Opening Magenta.sln file..."
& explorer.exe "$WorkingDirectory\Magenta.sln"
}
# Main Script
try
{
Install-Prerequisites
Push-Location
if ($Clean -or $Force)
{
Start-Clean
}
Start-Configure
Start-Build
}
finally
{
Pop-Location
}