forked from AmokHuginnsson/replxx
-
Notifications
You must be signed in to change notification settings - Fork 1
/
make.ps1
80 lines (71 loc) · 1.97 KB
/
make.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
param (
[Parameter(Mandatory=$True)] [string]$target,
[Parameter(Mandatory=$False)] [string]$prefix = "",
[Parameter(Mandatory=$False)] [string]$generator = "",
[Parameter(Mandatory=$False)] [switch]$with_shared = $false,
[Parameter(Mandatory=$False)] [switch]$with_examples = $false
)
function make_absolute( [string]$path ) {
if ( -Not( [System.IO.Path]::IsPathRooted( $path ) ) ) {
$path = [IO.Path]::GetFullPath( [IO.Path]::Combine( ( ($pwd).Path ), ( $path ) ) )
}
return $path.Replace( "\", "/" )
}
function purge {
Write-Host -NoNewline "Purging... "
Remove-Item "build" -Recurse -ErrorAction Ignore
Write-Host "done."
}
function build( [string]$config, [boolean]$install, [boolean]$build_shared ) {
New-Item -ItemType Directory -Force -Path "build/$config" > $null
if ( $prefix -eq "" ) {
throw "The ``prefix`` paremeter was not specified."
}
$prefix = make_absolute( $prefix )
Push-Location "build/$config"
$shared="-DBUILD_SHARED_LIBS=$(if ( $build_shared ) { "ON" } else { "OFF" } )"
$examples="-DREPLXX_BUILD_EXAMPLES=$( if ( $with_examples ) { "ON" } else { "OFF" } )"
if ( $generator -ne "" ) {
$genOpt = "-G"
}
cmake $shared $examples $genOpt $generator "-DCMAKE_INSTALL_PREFIX=$prefix" ../../
cmake --build . --config $config
if ( $install ) {
cmake --build . --target install --config $config
}
Pop-Location
}
function debug( [boolean]$install = $false ) {
build "debug" $install $false
if ( $with_shared ) {
build "debug" $install $true
}
}
function release( [boolean]$install = $false ) {
build "release" $install $false
if ( $with_shared ) {
build "release" $install $true
}
}
function install-debug {
debug $true
}
function install-release {
release $true
}
if (
( $target -ne "debug" ) -and
( $target -ne "release" ) -and
( $target -ne "install-debug" ) -and
( $target -ne "install-release" ) -and
( $target -ne "purge" )
) {
Write-Error "Unknown target: ``$target``"
exit 1
}
try {
&$target
} catch {
Pop-Location
Write-Error "$_"
}