-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.ps1
216 lines (181 loc) · 5.59 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
function Check-cmake {
$cmake = Get-Command cmake -ErrorAction SilentlyContinue
if ($cmake -eq $null) {
Write-Host "CMake not found. Please install CMake and make sure it is in the PATH."
exit 1
}
}
function Init-Environment {
& .\scripts\init_env_cfg.cmd
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
Read-Env-Cfg
$global:BUILD_DIR="$IPPONBOARD_ROOT_DIR\_build\build-Ipponboard"
$global:CONFIG="release"
$global:BIN_DIR="$IPPONBOARD_ROOT_DIR\_bin\Ipponboard-$CONFIG"
$global:TEST_BIN_DIR="$IPPONBOARD_ROOT_DIR\_bin\Test-$CONFIG"
}
# Read settings from env_cfg.cmd file. The settings are in the format "set VAR=VALUE"
function Read-Env-Cfg {
$env_cfg = Get-Content .\env_cfg.bat
foreach ($line in $env_cfg) {
if ($line -match '^set "(.*)=(.*)"\s*$') {
Set-Variable -Name $matches[1] -Value $matches[2] -Scope Global
Write-Host "Setting $($matches[1]) to $($matches[2])"
}
}
}
function Show-Menu {
Clear-Host
$menu = @"
Current config ($CONFIG):
QTDIR : $QTDIR
BOOST_DIR : $BOOST_DIR
ROOT_DIR : $IPPONBOARD_ROOT_DIR
BUILD_DIR : $BUILD_DIR
BIN_DIR : $BIN_DIR
INNO_DIR : $INNO_DIR
Select build mode:
(1) clean ALL
(2) create makefiles
(3) tests only
(4) build all
(5) run Ipponboard
(6) build doc
(7) translate resources
(8) build setup
(9) clean build with setup (release)
(s) switch debug/release
(q) quit
"@
Write-Host $menu
}
# write a function that takes another function from this scruipt as a parameter and calls it and measures the time it took
function Execute-And-Measure {
param (
[scriptblock]$function
)
$start = Get-Date
& $function
$end = Get-Date
$elapsed = $end - $start
$formattedTime = '{0:hh\:mm\:ss\.fff}' -f $elapsed
Write-Host "Elapsed time: $formattedTime"
Pause
}
function MainLoop {
Init-Environment
do {
Show-Menu
$choice = [System.Console]::ReadKey($true).KeyChar
switch ($choice) {
'1' { Execute-And-Measure ${function:Clean-All} }
'2' { Execute-And-Measure ${function:Create-Makefiles} }
'3' { Execute-And-Measure ${function:Build-and-run-tests} }
'4' { Execute-And-Measure ${function:Build-ALL} }
'5' { Execute-And-Measure ${function:Run} }
'6' { Execute-And-Measure ${function:Build-Doc} }
'7' { Execute-And-Measure ${function:Translate-Resources} }
'8' { Execute-And-Measure ${function:Build-Setup} }
'9' { Execute-And-Measure ${function:CleanBuildWithSetup} }
's' { Switch-Config }
'q' { break }
default { Write-Host "Invalid choice" }
}
} while ($choice -ne 'q')
}
function Clean-All {
# remove _bin and _build directories
$dirs = "$IPPONBOARD_ROOT_DIR\_bin", "$IPPONBOARD_ROOT_DIR\_build", "$IPPONBOARD_ROOT_DIR\_output"
foreach ($item in $dirs) {
Write-Host "Removing $item"
if (Test-Path $item) {
Remove-Item -Path $item -Recurse -Force -ErrorAction SilentlyContinue
}
}
Write-Host "Removing versioninfo.h"
Remove-Item -Path "$IPPONBOARD_ROOT_DIR\base\versioninfo.h" -ErrorAction SilentlyContinue
}
function Create-Makefiles {
& .\scripts\create-versioninfo.cmd "$IPPONBOARD_ROOT_DIR\base"
if ($LASTEXITCODE -ne 0) { return $false }
cmake -S "$IPPONBOARD_ROOT_DIR" -B "$BUILD_DIR" -G "Visual Studio 17 2022" -A Win32 --fresh
if ($LASTEXITCODE -ne 0) { return $false }
}
function Run-Tests {
$exe = "$TEST_BIN_DIR\IpponboardTest.exe"
if (-not (Test-Path $exe)) {
Write-Host "Test app not found: $exe"
return $false
}
Set-Location $TEST_BIN_DIR
& "$exe"
$success = ($LASTEXITCODE -eq 0)
Set-Location -Path $PSScriptRoot
return $success
}
function Build-and-run-tests {
cmake --build "$BUILD_DIR" --config $CONFIG --target IpponboardTest
if ($LASTEXITCODE -ne 0) { return $false }
$success = Run-Tests
return $success
}
function Build-ALL {
cmake --build "$BUILD_DIR" --config $CONFIG
if ($LASTEXITCODE -ne 0) { return $false }
$success = Run-Tests
if (-not $success) { return $false }
$success = Build-Doc
return $success
}
function Run {
$app = "$BIN_DIR\Ipponboard.exe"
if (-not (Test-Path $app)) {
Write-Host "Application not found: $app"
return $false
}
Set-Location $BIN_DIR
& "$app"
$success = ($LASTEXITCODE -eq 0)
Set-Location -Path $PSScriptRoot
return $success
}
function CleanBuildWithSetup {
Clean-All
if ($CONFIG -ne "release") { Switch-Config }
$success = Create-Makefiles
if (-not $success) { return $false }
$success = Build-ALL
if (-not $success) { return $false }
#Translate-Resources
$success = Build-Setup
return $success
}
function Build-Doc {
& .\scripts\build-doc.cmd
return ($LASTEXITCODE -eq 0)
}
function Build-Setup {
& .\scripts\build-setup.cmd
return ($LASTEXITCODE -eq 0)
}
function Switch-Config {
if ($global:CONFIG -eq "release") {
$global:CONFIG = "debug"
} else {
$global:CONFIG = "release"
}
$global:BIN_DIR="$IPPONBOARD_ROOT_DIR\_bin\Ipponboard-$CONFIG"
$global:TEST_BIN_DIR="$IPPONBOARD_ROOT_DIR\_bin\Test-$CONFIG"
}
function Translate-Resources {
& .\scripts\translate.cmd
return ($LASTEXITCODE -eq 0)
}
# Main
try {
Check-cmake
MainLoop
} catch {
Write-Host "An error occurred: $_"
exit 1
}