-
Notifications
You must be signed in to change notification settings - Fork 325
/
Copy pathInstall-Boost.ps1
145 lines (112 loc) · 3.85 KB
/
Install-Boost.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
<#
.SYNOPSIS
Downloads Boost via NuGet and returns the BOOST_ROOT and BOOST_LIBRARYDIR
locations.
.PARAMETER Version
The Boost version to install.
.PARAMETER Components
The Boost binary components to install. The Boost headers are always installed.
.PARAMETER VcToolsetVer
Which MSVC toolset version to install libraries for, in Visual Studio toolset
version number format. (E.g., 12.0, 14.1).
.PARAMETER OutputDirectory
Where to install Boost. If not set, creates a directory in the TEMP folder.
#>
[CmdletBinding(SupportsShouldProcess=$True)]
param
(
[string]
$Version,
[ValidateSet('12.0', '14.0', '14.1', '14.2')]
[string]
$VcToolsetVer,
[string[]]
$Components = (
'boost_chrono',
'boost_date_time',
'boost_thread',
'boost_system',
'boost_unit_test_framework'),
[string]
$OutputDirectory = $null
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
function ConvertVcToolsetVer-ToBoostPackageFormat([string]$vcToolsetVer)
{
return $vcToolsetVer.Replace('.', '')
}
function Install-NuGetPackage([string]$InstallDir, [string]$PackageId, [string]$PackageVersion)
{
$nugetPrereleaseFlag = @()
if ($packageVersion.Contains('-')) {
$nugetPrereleaseFlag += 'Prerelease'
}
nuget install $packageId `
-OutputDirectory $installDir `
-Version $packageVersion `
-ExcludeVersion `
$nugetPrereleaseFlag
if (-not $?)
{
throw "NuGet install of '$packageId' '$packageVersion' failed. Exit code $LastExitCode"
}
}
if (-not $OutputDirectory)
{
$OutputDirectory = [System.IO.Path]::Combine(
[System.IO.Path]::GetTempPath(),
[System.IO.Path]::GetRandomFileName())
Write-Debug "OutputDirectory not set. Generated temp folder name: '$OutputDirectory'"
}
if (-not (Test-Path -LiteralPath $OutputDirectory -PathType Container))
{
mkdir $OutputDirectory | Out-Null
}
$workDir = [System.IO.Path]::Combine($OutputDirectory, 'w')
$destDir = [System.IO.Path]::Combine($OutputDirectory, 'd')
$lib32Dir = [System.IO.Path]::Combine($destDir, 'lib32')
$lib64Dir = [System.IO.Path]::Combine($destDir, 'lib64')
mkdir $workDir | Out-Null
mkdir $destDir | Out-Null
mkdir $lib32Dir | Out-Null
mkdir $lib64Dir | Out-Null
function Install-BoostHeaders
{
Write-Progress -Activity 'Installing Boost' -Status "Installing 'boost' (headers) version $Version"
if ($PSCmdlet.ShouldProcess("boost version $Version", 'Install NuGet package'))
{
Install-NuGetPackage `
-PackageId 'boost' `
-InstallDir $workDir `
-PackageVersion $Version
Move-Item `
-Path ([System.IO.Path]::Combine($workDir, 'boost', 'lib', 'native', 'include', 'boost')) `
-Destination $destDir
}
}
function Install-BoostComponent([string]$Component)
{
$packageId = "$Component-vc$(ConvertVcToolsetVer-ToBoostPackageFormat $VcToolsetVer)"
Write-Progress -Activity 'Installing Boost' -Status "Installing '$packageId' version $Version"
if ($PSCmdlet.ShouldProcess("$packageId version $Version", 'Install NuGet package'))
{
Install-NuGetPackage `
-PackageId $packageId `
-InstallDir $workDir `
-PackageVersion $Version
Move-Item `
-Path ([System.IO.Path]::Combine($workDir, $packageId, 'lib', 'native', 'address-model-32', 'lib', '*')) `
-Destination $lib32Dir
Move-Item `
-Path ([System.IO.Path]::Combine($workDir, $packageId, 'lib', 'native', 'address-model-64', 'lib', '*')) `
-Destination $lib64Dir
}
}
Install-BoostHeaders | Out-Null
$Components | % `
{
Install-BoostComponent -Component $PSItem | Out-Null
}
Write-Progress -Activity 'Installing Boost' -Completed
return @{'BOOST_ROOT' = $destDir; 'BOOST_LIBRARYDIR'= @{'32' = $lib32Dir; '64' = $lib64Dir}}