-
Notifications
You must be signed in to change notification settings - Fork 59
/
build.ps1
150 lines (123 loc) · 3.46 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
138
139
140
141
142
143
144
145
146
147
148
149
150
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","arm64")]
[string] $arch = "x64",
[ValidateSet("17","16","15","14")]
[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 -vsver $vsver -arch $arch -config $config -static $static
.\build.ps1 -proj core -init:$init -install:$install -vsver $vsver -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) {
17 {
$gen += "17 2022"
}
16 {
$gen += "16 2019"
}
15 {
$gen += "15 2017"
}
14 {
$gen += "14 2015"
}
12 {
$gen += "12 2013"
}
default {
throw "Visual Studio version $vsver not supported!"
}
}
$cmake_arch=""
if($arch -eq "x64"){
$cmake_arch += "x64"
}
elseif($arch -eq "x86"){
$cmake_arch += "Win32"
}
elseif($arch -eq "arm64"){
$cmake_arch += "ARM64"
}
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" -A $cmake_arch -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" -A $cmake_arch -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 }
}
}
}