1 param (
2 [Parameter(Mandatory=$True)] [string]$target,
3 [Parameter(Mandatory=$False)] [string]$prefix = "",
4 [Parameter(Mandatory=$False)] [string]$generator = "",
5 [Parameter(Mandatory=$False)] [switch]$with_shared = $false,
6 [Parameter(Mandatory=$False)] [switch]$with_examples = $false
7 )
8
make_absolute([string] $path)9 function make_absolute( [string]$path ) {
10 if ( -Not( [System.IO.Path]::IsPathRooted( $path ) ) ) {
11 $path = [IO.Path]::GetFullPath( [IO.Path]::Combine( ( ($pwd).Path ), ( $path ) ) )
12 }
13 return $path.Replace( "\", "/" )
14 }
15
purge()16 function purge {
17 Write-Host -NoNewline "Purging... "
18 Remove-Item "build" -Recurse -ErrorAction Ignore
19 Write-Host "done."
20 }
21
build( [string]$config, [boolean]$install, [boolean]$build_shared )22 function build( [string]$config, [boolean]$install, [boolean]$build_shared ) {
23 New-Item -ItemType Directory -Force -Path "build/$config" > $null
24 if ( $prefix -eq "" ) {
25 throw "The ``prefix`` paremeter was not specified."
26 }
27 $prefix = make_absolute( $prefix )
28 Push-Location "build/$config"
29 $shared="-DBUILD_SHARED_LIBS=$(if ( $build_shared ) { "ON" } else { "OFF" } )"
30 $examples="-DREPLXX_BUILD_EXAMPLES=$( if ( $with_examples ) { "ON" } else { "OFF" } )"
31 if ( $generator -ne "" ) {
32 $genOpt = "-G"
33 }
34 cmake $shared $examples $genOpt $generator "-DCMAKE_INSTALL_PREFIX=$prefix" ../../
35 cmake --build . --config $config
36 if ( $install ) {
37 cmake --build . --target install --config $config
38 }
39 Pop-Location
40 }
41
debug( [boolean]$install = $false )42 function debug( [boolean]$install = $false ) {
43 build "debug" $install $false
44 if ( $with_shared ) {
45 build "debug" $install $true
46 }
47 }
48
release( [boolean]$install = $false )49 function release( [boolean]$install = $false ) {
50 build "release" $install $false
51 if ( $with_shared ) {
52 build "release" $install $true
53 }
54 }
55
install-debug()56 function install-debug {
57 debug $true
58 }
59
install-release()60 function install-release {
61 release $true
62 }
63
64 if (
65 ( $target -ne "debug" ) -and
66 ( $target -ne "release" ) -and
67 ( $target -ne "install-debug" ) -and
68 ( $target -ne "install-release" ) -and
69 ( $target -ne "purge" )
70 ) {
71 Write-Error "Unknown target: ``$target``"
72 exit 1
73 }
74
75 try {
76 &$target
77 } catch {
78 Pop-Location
79 Write-Error "$_"
80 }
81