-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
131 lines (106 loc) · 4.35 KB
/
Copy pathbuild.ps1
File metadata and controls
131 lines (106 loc) · 4.35 KB
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
<#
.SYNOPSIS
Configure and build Descry (descry.exe) with CMake + Ninja using the
MSYS2 MinGW-w64 toolchain.
.DESCRIPTION
Wraps the documented build:
cmake -G Ninja -B build
ninja -C build
The MSYS2 mingw64 bin directory is auto-detected and prepended to PATH so
cmake finds gcc/ninja/pkg-config and the matching SDL2 / FreeType /
HarfBuzz / libpng / libjpeg, even from a vanilla PowerShell session. The
POST_BUILD step in CMakeLists.txt bundles the runtime DLLs next to the exe,
leaving build\ self-contained for build_installer.ps1 to package.
.PARAMETER Config
CMAKE_BUILD_TYPE. Default: Release.
.PARAMETER Clean
Delete the build directory before configuring (forces a fresh reconfigure).
.PARAMETER Run
Launch build\descry.exe after a successful build.
.PARAMETER Installer
After building, also build the installer by invoking build_installer.ps1.
.PARAMETER MingwBin
Path to the MSYS2 mingw64 bin directory. Auto-detected when omitted.
.EXAMPLE
.\build.ps1
Release build into .\build.
.EXAMPLE
.\build.ps1 -Clean -Config Debug -Run
Fresh Debug build, then launch the app.
.EXAMPLE
.\build.ps1 -Installer
Build the app, then produce dist\Descry-Setup-<version>.exe.
#>
[CmdletBinding()]
param(
[ValidateSet("Release", "Debug", "RelWithDebInfo", "MinSizeRel")]
[string]$Config = "Release",
[switch]$Clean,
[switch]$Run,
[switch]$Installer,
[string]$MingwBin
)
$ErrorActionPreference = "Stop"
$root = $PSScriptRoot
$buildDir = Join-Path $root "build"
# --- locate the MSYS2 MinGW-w64 toolchain --------------------------------
if (-not $MingwBin) {
# Prefer a gcc already on PATH; otherwise probe the usual install spots.
$gcc = Get-Command gcc -ErrorAction SilentlyContinue
if ($gcc) {
$MingwBin = Split-Path $gcc.Source
} else {
$MingwBin = @(
"D:\Apps\msys64\mingw64\bin",
"C:\msys64\mingw64\bin",
"C:\tools\msys64\mingw64\bin"
) | Where-Object { Test-Path $_ } | Select-Object -First 1
}
}
if (-not $MingwBin -or -not (Test-Path $MingwBin)) {
throw "MSYS2 MinGW-w64 toolchain not found. Pass -MingwBin <path to mingw64\bin>."
}
# Put the toolchain first on PATH so cmake/pkg-config resolve to mingw64.
$env:PATH = "$MingwBin;$env:PATH"
foreach ($tool in @("cmake", "ninja", "gcc", "pkg-config")) {
if (-not (Get-Command $tool -ErrorAction SilentlyContinue)) {
throw "Required tool '$tool' not found under $MingwBin."
}
}
Write-Host "Toolchain : $MingwBin" -ForegroundColor Cyan
Write-Host "Config : $Config" -ForegroundColor Cyan
Write-Host "Build dir : $buildDir" -ForegroundColor Cyan
# --- clean ---------------------------------------------------------------
if ($Clean -and (Test-Path $buildDir)) {
Write-Host "Cleaning $buildDir ..." -ForegroundColor Yellow
Remove-Item -Recurse -Force $buildDir
}
# --- configure -----------------------------------------------------------
# Re-run configure only when there is no cache (fresh or cleaned tree). Ninja
# is single-config, so changing -Config on an existing tree needs -Clean.
$cache = Join-Path $buildDir "CMakeCache.txt"
if (-not (Test-Path $cache)) {
Write-Host "Configuring (cmake -G Ninja) ..." -ForegroundColor Green
& cmake -G Ninja -B $buildDir -S $root "-DCMAKE_BUILD_TYPE=$Config"
if ($LASTEXITCODE -ne 0) { throw "cmake configure failed ($LASTEXITCODE)" }
} else {
Write-Host "Reusing CMake cache (pass -Clean to reconfigure)." -ForegroundColor DarkGray
}
# --- build ---------------------------------------------------------------
Write-Host "Building (ninja) ..." -ForegroundColor Green
& cmake --build $buildDir
if ($LASTEXITCODE -ne 0) { throw "build failed ($LASTEXITCODE)" }
$exe = Join-Path $buildDir "descry.exe"
if (-not (Test-Path $exe)) { throw "build reported success but $exe is missing." }
Write-Host "Built: $exe" -ForegroundColor Green
# --- optional: installer -------------------------------------------------
if ($Installer) {
Write-Host "Building installer ..." -ForegroundColor Green
& (Join-Path $root "build_installer.ps1")
if ($LASTEXITCODE -ne 0) { throw "installer build failed ($LASTEXITCODE)" }
}
# --- optional: run -------------------------------------------------------
if ($Run) {
Write-Host "Launching descry.exe ..." -ForegroundColor Green
& $exe
}