-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
114 lines (98 loc) · 3.25 KB
/
build.ps1
File metadata and controls
114 lines (98 loc) · 3.25 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
#!/usr/bin/env pwsh
# EDN.C - PowerShell Build Script
# Cross-platform build script (works on Windows, macOS, Linux)
param(
[string]$BuildType = "Release",
[switch]$Clean,
[switch]$Test,
[switch]$Verbose
)
$ErrorActionPreference = "Stop"
Write-Host "EDN.C Build Script" -ForegroundColor Cyan
Write-Host "==================" -ForegroundColor Cyan
Write-Host ""
# Check CMake
if (-not (Get-Command cmake -ErrorAction SilentlyContinue)) {
Write-Host "ERROR: CMake not found" -ForegroundColor Red
Write-Host "Please install CMake from https://cmake.org/download/" -ForegroundColor Yellow
exit 1
}
$ProjectRoot = $PSScriptRoot
$BuildDir = Join-Path $ProjectRoot "build"
# Clean if requested
if ($Clean -and (Test-Path $BuildDir)) {
Write-Host "Cleaning build directory..." -ForegroundColor Yellow
Remove-Item -Recurse -Force $BuildDir
}
# Create build directory
if (-not (Test-Path $BuildDir)) {
Write-Host "Creating build directory..." -ForegroundColor Green
New-Item -ItemType Directory -Path $BuildDir | Out-Null
}
Push-Location $BuildDir
try {
# Configure
Write-Host ""
Write-Host "Configuring project..." -ForegroundColor Green
$ConfigArgs = @("..", "-DCMAKE_BUILD_TYPE=$BuildType")
if ($Verbose) {
$ConfigArgs += "-DCMAKE_VERBOSE_MAKEFILE=ON"
}
& cmake @ConfigArgs
if ($LASTEXITCODE -ne 0) {
throw "CMake configuration failed"
}
# Build
Write-Host ""
Write-Host "Building library and tests..." -ForegroundColor Green
$BuildArgs = @("--build", ".", "--config", $BuildType)
if ($Verbose) {
$BuildArgs += "--verbose"
}
& cmake @BuildArgs
if ($LASTEXITCODE -ne 0) {
throw "Build failed"
}
Write-Host ""
Write-Host "========================================" -ForegroundColor Green
Write-Host "Build successful!" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Green
Write-Host ""
# Run tests if requested
if ($Test) {
Write-Host "Running tests..." -ForegroundColor Cyan
Write-Host ""
& ctest -C $BuildType --output-on-failure
if ($LASTEXITCODE -ne 0) {
throw "Tests failed"
}
Write-Host ""
Write-Host "All tests passed!" -ForegroundColor Green
}
else {
Write-Host "Library: build/$BuildType/edn.lib (or build/libedn.a)" -ForegroundColor Cyan
Write-Host "Tests: build/$BuildType/*.exe (or build/test_*.exe)" -ForegroundColor Cyan
Write-Host ""
Write-Host "To run tests:" -ForegroundColor Yellow
Write-Host " cd build"
Write-Host " ctest -C $BuildType"
Write-Host ""
Write-Host "Or with PowerShell:" -ForegroundColor Yellow
Write-Host " .\build.ps1 -Test"
Write-Host ""
}
}
catch {
Write-Host ""
Write-Host "ERROR: $_" -ForegroundColor Red
Write-Host ""
Write-Host "Troubleshooting:" -ForegroundColor Yellow
Write-Host " - Make sure you have a C compiler installed (Visual Studio, GCC, or Clang)"
Write-Host " - If using MSVC, run from 'Developer PowerShell for VS'"
Write-Host " - If using MinGW, ensure gcc is in your PATH"
Write-Host ""
exit 1
}
finally {
Pop-Location
}