forked from editorconfig/editorconfig-core-c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
137 lines (110 loc) · 3.13 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
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
param(
[ValidateSet("pcre2","core", "all")]
[string] $proj = "all",
[switch] $init,
[switch] $install,
[ValidateSet("ON","OFF")]
[string] $static = "ON",
[ValidateSet("Debug","Release")]
[string] $config = "Release",
[ValidateSet("x86","x64")]
[string] $arch = "x64",
[ValidateSet("15","14","12")]
[int] $vsver = 15
)
$ErrorActionPreference="stop"
function exec
{
param
(
[ScriptBlock] $ScriptBlock,
[int[]] $AllowedExitCodes = @(0)
)
$backupErrorActionPreference = $script:ErrorActionPreference
$script:ErrorActionPreference = "Continue"
try
{
& $ScriptBlock
if ($AllowedExitCodes -notcontains $LASTEXITCODE)
{
throw "Execution failed with exit code $LASTEXITCODE"
}
}
finally
{
$script:ErrorActionPreference = $backupErrorActionPreference
}
}
if ($proj -eq "all"){
.\build.ps1 -proj pcre2 -init:$init -install:$install -arch $arch -config $config -static $static
.\build.ps1 -proj core -init:$init -install:$install -arch $arch -config $config -static $static
return
}
$PREFIX="../build"
$dest = "bin"
if ((Test-Path $dest) -ne $true){
throw "Missing build path! Used init?"
}
$dest += "\$arch"
if($static -eq "ON"){
$dest += "-static"
}
$dest += "\$proj"
if ($init) {
"Generating $proj build files" | Write-Host -ForegroundColor DarkGreen
$gen = "Visual Studio "
switch ($vsver) {
15 {
$gen += "15 2017"
}
14 {
$gen += "14 2015"
}
12 {
$gen += "12 2013"
}
default {
throw "Visual Studio version $vsver not supported!"
}
}
if($arch -eq "x64"){
$gen += " Win64"
}
mkdir $dest -ErrorAction SilentlyContinue | Out-Null
Push-Location $dest
try {
switch ($proj) {
pcre2 {
$BUILD_SHARED_LIBS = "ON"
if ($static -eq "ON"){ $BUILD_SHARED_LIBS = "OFF"}
exec { cmake -G "$gen" -DCMAKE_INSTALL_PREFIX="$PREFIX" -DPCRE2_STATIC_RUNTIME="$static" `
-DBUILD_SHARED_LIBS="$BUILD_SHARED_LIBS" -DPCRE2_BUILD_PCRE2GREP="OFF" -DPCRE2_BUILD_TESTS="OFF" `
"../../pcre2" }
}
core {
$MSVC_MD = "ON"
if ($static -eq "ON"){ $MSVC_MD = "OFF"}
exec { cmake -G "$gen" -DCMAKE_INSTALL_PREFIX="$PREFIX" -DMSVC_MD="$MSVC_MD" -DPCRE2_STATIC="$static" `
"../../../." }
}
}
} finally {
Pop-Location
}
}
if ((Test-Path $dest) -ne $true){
throw "Missing build path! Used init?"
}
"Compiling $proj" | Write-Host -ForegroundColor DarkGreen
exec { cmake --build $dest `-- /p:Configuration=$config }
if ($install) {
"Installing $proj" | Write-Host -ForegroundColor DarkGreen
switch ($proj) {
pcre2 {
exec { cmake --build $dest --target install `-- /p:Configuration=$config }
}
core {
exec { cmake --build $dest --target install `-- /p:Configuration=$config }
}
}
}