-
Notifications
You must be signed in to change notification settings - Fork 40
/
build-extern.ps1
109 lines (93 loc) · 2.66 KB
/
build-extern.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
$ErrorActionPreference = "Stop"
# Find CMake.
$cmake = 'cmake.exe'
try
{
Get-Command $cmake | Out-Null
}
catch
{
$key = 'HKLM:\SOFTWARE\Kitware\CMake'
try
{
$cmake_installdir = Get-ItemProperty -Path $key -Name InstallDir
$global:cmake = Join-Path -Path $cmake_installdir.InstallDir `
-ChildPath 'bin\cmake.exe'
}
catch
{
throw 'Failed to find cmake.'
}
}
# Find the Microsoft Visual Studio install path.
pushd $PSScriptRoot
New-Item -ItemType Directory -Force -Path '.extern/tool/vswhere' | Out-Null
Set-Location -Path '.extern/tool/vswhere'
$vswhere = 'vswhere.exe'
if (-Not (Test-Path $vswhere))
{
$uri = 'https://github.com/microsoft/vswhere/releases/download/2.7.1'
Invoke-WebRequest -Uri "$uri/$vswhere" -OutFile $vswhere
}
$msvc = & ./$vswhere -legacy -latest -format json | ConvertFrom-Json
popd
if ($msvc)
{
$path = $msvc.installationPath
$version = [Version]$msvc.installationVersion
if (($version.Major -eq 17) -or ($version.Major -eq 16) `
-or ($version.Major -eq 15))
{
$global:msvc = Join-Path -Path $msvc.installationPath `
-ChildPath 'VC\Auxiliary\Build'
}
elseif ($version.Major -eq 14)
{
$global:msvc = Join-Path -Path $msvc.installationPath `
-ChildPath 'bin\amd64'
}
elseif ($version.Major -eq 12)
{
$global:msvc = Join-Path -Path $msvc.installationPath `
-ChildPath 'VC\bin\amd64'
}
else
{
throw 'Microsoft Visual Studio 2013 or above required.'
}
}
else
{
throw 'Failed to find Microsoft Visual Studio.'
}
# Put MSVC compiler in the search path.
pushd $msvc
cmd /c 'vcvars64.bat&set' |
foreach {
if ($_ -match '=') {
$v = $_.split('='); set-item -force -path "ENV:\$($v[0])" `
-value "$($v[1])"
}
}
popd
# Download Ninja.
pushd $PSScriptRoot
Set-Location -Path '.extern/tool'
if (-Not (Test-Path 'ninja-win/ninja.exe'))
{
$uri = 'https://github.com/ninja-build/ninja/releases/download/v1.9.0/ninja-win.zip'
Invoke-WebRequest -Uri $uri -OutFile ninja-win.zip
Expand-Archive ninja-win.zip
Remove-item 'ninja-win.zip'
}
$ninja = Resolve-Path -Path 'ninja-win'
$env:path = "$ninja;" + $env:path
popd
# Create the build directory.
pushd $PSScriptRoot
New-Item -ItemType Directory -Force -Path '.extern/build' | Out-Null
Set-Location -Path '.extern/build'
# Run Cmake and perform the build.
& "$cmake" "-G" "`"Ninja`"" "-DCMAKE_INSTALL_PREFIX=../install" "../../cmake/extern"
& "$cmake" "--build" "."
popd