1# Build Hall_Senser on Windows (CMake + Ninja, GD32EB ARM GCC).2# Usage:3# .\scripts\build.ps14# .\scripts\build.ps1 -Preset release5# .\scripts\build.ps1 -Flash67[CmdletBinding()]8param(9 [ValidateSet('debug', 'release')]10 [string]$Preset = 'debug',1112 [switch]$Flash13)1415$ErrorActionPreference = 'Stop'16$Root = Split-Path -Parent $PSScriptRoot1718function Get-FirstExisting {19 param([string[]]$Paths)20 foreach ($p in $Paths) {21 if ([string]::IsNullOrWhiteSpace($p)) { continue }22 $hits = @(Get-Item -Path $p -ErrorAction SilentlyContinue)23 if ($hits.Count -gt 0) {24 return ($hits | Sort-Object FullName -Descending | Select-Object -First 1).FullName25 }26 }27 return $null28}2930function Find-Cmake {31 $cmd = Get-Command cmake -ErrorAction SilentlyContinue32 if ($cmd) { return $cmd.Source }33 return Get-FirstExisting @(34 'C:\Program Files\JetBrains\CLion *\bin\cmake\win\x64\bin\cmake.exe'35 'D:\Program Files\JetBrains\CLion *\bin\cmake\win\x64\bin\cmake.exe'36 'D:\JetBrains\CLion *\bin\cmake\win\x64\bin\cmake.exe'37 "$env:LOCALAPPDATA\Programs\CLion\bin\cmake\win\x64\bin\cmake.exe"38 'C:\Program Files\CMake\bin\cmake.exe'39 'D:\ClionProject\YFOCV3_LITE\tools\cmake\bin\cmake.exe'40 )41}4243$cmake = Find-Cmake44if (-not $cmake) {45 throw "cmake not found. Install CMake or CLion."46}47Write-Host "cmake: $cmake"4849Push-Location $Root50try {51 & $cmake --preset $Preset52 if ($LASTEXITCODE -ne 0) { throw "cmake configure failed ($LASTEXITCODE)" }53 & $cmake --build --preset $Preset54 if ($LASTEXITCODE -ne 0) { throw "cmake build failed ($LASTEXITCODE)" }55 Write-Host "OK: $Root\build\$Preset\Hall_Senser.elf"56}57finally {58 Pop-Location59}6061if ($Flash) {62 $flashScript = Join-Path $PSScriptRoot 'flash.ps1'63 & $flashScript -Preset $Preset64 if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }65}