-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.ps1
More file actions
123 lines (110 loc) · 4.05 KB
/
Copy pathbuild.ps1
File metadata and controls
123 lines (110 loc) · 4.05 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
# =============================================================
# C++ DebugMate Test - Build Script (Windows)
# =============================================================
# Usage:
# .\build.ps1 # Build with auto-detected compiler
# .\build.ps1 -Compiler msvc # Use MSVC
# .\build.ps1 -Compiler gcc # Use GCC (MSYS2 UCRT64)
# .\build.ps1 -Compiler clang # Use Clang (MSYS2 Clang64)
# .\build.ps1 -Clean # Clean build directory
# =============================================================
param(
[ValidateSet("auto", "msvc", "gcc", "clang")]
[string]$Compiler = "auto",
[switch]$Clean
)
$ErrorActionPreference = "Stop"
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$BuildDir = "$ScriptDir\build"
$BuildType = "Debug"
# MSYS2 paths (modify if installed elsewhere)
$MSYS2_UCRT64 = "C:\msys64\ucrt64\bin"
$MSYS2_CLANG64 = "C:\msys64\clang64\bin"
# Clean
if ($Clean) {
Write-Host "Cleaning build directory..." -ForegroundColor Yellow
if (Test-Path $BuildDir) {
Remove-Item -Recurse -Force $BuildDir
}
Write-Host "Done!" -ForegroundColor Green
exit 0
}
# Auto-detect compiler
if ($Compiler -eq "auto") {
if (Get-Command cl.exe -ErrorAction SilentlyContinue) {
$Compiler = "msvc"
} elseif (Test-Path "$MSYS2_CLANG64\clang++.exe") {
$Compiler = "clang"
} elseif (Test-Path "$MSYS2_UCRT64\g++.exe") {
$Compiler = "gcc"
} else {
Write-Host "Error: No compiler found!" -ForegroundColor Red
Write-Host "Install one of: MSVC, MSYS2 GCC, or MSYS2 Clang" -ForegroundColor Yellow
exit 1
}
}
# Configure based on compiler
$Generator = "Ninja"
$CMakeArgs = @()
switch ($Compiler) {
"msvc" {
Write-Host "Using MSVC" -ForegroundColor Cyan
$Generator = "Visual Studio 17 2022"
$CMakeArgs = @("-A", "x64")
}
"gcc" {
Write-Host "Using GCC (MSYS2 UCRT64)" -ForegroundColor Cyan
if (-not (Test-Path "$MSYS2_UCRT64\g++.exe")) {
Write-Host "Error: GCC not found at $MSYS2_UCRT64" -ForegroundColor Red
Write-Host "Install: pacman -S mingw-w64-ucrt-x86_64-gcc" -ForegroundColor Yellow
exit 1
}
$env:PATH = "$MSYS2_UCRT64;$env:PATH"
$CMakeArgs = @("-G", "Ninja",
"-DCMAKE_C_COMPILER=$MSYS2_UCRT64/gcc.exe",
"-DCMAKE_CXX_COMPILER=$MSYS2_UCRT64/g++.exe")
}
"clang" {
Write-Host "Using Clang (MSYS2 Clang64)" -ForegroundColor Cyan
if (-not (Test-Path "$MSYS2_CLANG64\clang++.exe")) {
Write-Host "Error: Clang not found at $MSYS2_CLANG64" -ForegroundColor Red
Write-Host "Install: pacman -S mingw-w64-clang-x86_64-toolchain" -ForegroundColor Yellow
exit 1
}
$env:PATH = "$MSYS2_CLANG64;$env:PATH"
$CMakeArgs = @("-G", "Ninja",
"-DCMAKE_C_COMPILER=$MSYS2_CLANG64/clang.exe",
"-DCMAKE_CXX_COMPILER=$MSYS2_CLANG64/clang++.exe")
}
}
# Create build directory
if (-not (Test-Path $BuildDir)) {
New-Item -ItemType Directory -Path $BuildDir | Out-Null
}
Push-Location $BuildDir
try {
# Configure
Write-Host "[1/2] Configuring..." -ForegroundColor Cyan
if ($Compiler -eq "msvc") {
& cmake $CMakeArgs ..
} else {
& cmake @CMakeArgs "-DCMAKE_BUILD_TYPE=$BuildType" ..
}
if ($LASTEXITCODE -ne 0) { throw "CMake configuration failed" }
# Build
Write-Host "[2/2] Building..." -ForegroundColor Cyan
& cmake --build . --config $BuildType --parallel
if ($LASTEXITCODE -ne 0) { throw "Build failed" }
Write-Host ""
Write-Host "Build successful!" -ForegroundColor Green
Write-Host " Output: $BuildDir\test_debugmate.exe" -ForegroundColor Green
Write-Host ""
Write-Host "Next steps:" -ForegroundColor Yellow
Write-Host " 1. Open test_cpp folder in VS Code"
Write-Host " 2. Set breakpoints in main.cpp"
Write-Host " 3. Start debugging (F5)"
Write-Host " 4. Use C++ DebugMate to visualize!"
}
finally {
Pop-Location
}