[CmdletBinding()]
param(
    [string]$Preset = "windows-msvc-default",
    [string]$Configuration = "Debug",
    [string]$Target = ""
)

$ErrorActionPreference = "Stop"
$started = Get-Date
$argsList = @("--build", "--preset", $Preset, "--config", $Configuration)
if ($Target.Length -gt 0) {
    $argsList += @("--target", $Target)
}

& cmake @argsList
$exitCode = $LASTEXITCODE
$elapsed = [int]((Get-Date) - $started).TotalMilliseconds

[ordered]@{
    command = "build"
    preset = $Preset
    configuration = $Configuration
    target = $Target
    exitCode = $exitCode
    elapsedMs = $elapsed
} | ConvertTo-Json -Compress

exit $exitCode
