param( [ValidateSet('Debug', 'Release', 'RelWithDebInfo')] [string]$Configuration = 'Release' ) $ErrorActionPreference = 'Stop' $projectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path $toolRoot = Join-Path $projectRoot '.tools\toolchain' if (-not (Test-Path -LiteralPath $toolRoot -PathType Container)) { throw 'Portable tools are missing. Run .\setup-toolchain.ps1 first.' } $cmakeExe = Get-ChildItem -LiteralPath (Join-Path $toolRoot 'cmake') -Filter 'cmake.exe' -File -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 $clangxxExe = Get-ChildItem -LiteralPath (Join-Path $toolRoot 'llvm-mingw') -Filter 'clang++.exe' -File -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 $ninjaExe = Get-ChildItem -LiteralPath (Join-Path $toolRoot 'llvm-mingw') -Filter 'ninja.exe' -File -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 $makeExe = Get-ChildItem -LiteralPath (Join-Path $toolRoot 'llvm-mingw') -Filter 'mingw32-make.exe' -File -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 if ($null -eq $cmakeExe -or $null -eq $clangxxExe) { throw 'CMake or Clang is missing. Run .\setup-toolchain.ps1 again.' } $compilerBin = Split-Path -Parent $clangxxExe.FullName $cmakeBin = Split-Path -Parent $cmakeExe.FullName $env:Path = "$compilerBin;$cmakeBin;$env:Path" $buildDirectory = Join-Path $projectRoot 'build' $generatorArguments = @() if ($null -ne $ninjaExe) { $generatorArguments = @('-G', 'Ninja', "-DCMAKE_MAKE_PROGRAM=$($ninjaExe.FullName)") } elseif ($null -ne $makeExe) { $generatorArguments = @('-G', 'MinGW Makefiles', "-DCMAKE_MAKE_PROGRAM=$($makeExe.FullName)") } else { throw 'The LLVM-MinGW archive contains neither Ninja nor mingw32-make.' } & $cmakeExe.FullName -S $projectRoot -B $buildDirectory @generatorArguments -U CMAKE_C_COMPILER ` "-DCMAKE_CXX_COMPILER=$($clangxxExe.FullName)" ` "-DCMAKE_BUILD_TYPE=$Configuration" if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } & $cmakeExe.FullName --build $buildDirectory --parallel --config $Configuration if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } # LLVM-MinGW links libc++ dynamically. Copy its runtime beside the executables # so they can be launched from Explorer without editing the system PATH. foreach ($runtimeName in @('libc++.dll', 'libunwind.dll')) { $runtimeSource = Join-Path $compilerBin $runtimeName if (-not (Test-Path -LiteralPath $runtimeSource -PathType Leaf)) { throw "Required LLVM-MinGW runtime was not found: $runtimeSource" } Copy-Item -LiteralPath $runtimeSource -Destination $buildDirectory -Force } $ctestExe = Join-Path $cmakeBin 'ctest.exe' if (-not (Test-Path -LiteralPath $ctestExe -PathType Leaf)) { throw 'CTest was not found beside CMake.' } & $ctestExe --test-dir $buildDirectory -C $Configuration --output-on-failure exit $LASTEXITCODE