Files
stoneheart_at_home/build.ps1

50 lines
2.2 KiB
PowerShell

param(
[ValidateSet('Debug', 'Release', 'RelWithDebInfo')]
[string]$Configuration = 'Release',
[string]$Msys2Root = $env:SETTLEMENT_MSYS2_ROOT
)
$ErrorActionPreference = 'Stop'
$projectRoot = $PSScriptRoot
if (-not $Msys2Root) { $Msys2Root = Join-Path $projectRoot '.tools\toolchain\msys64' }
$bin = Join-Path $Msys2Root 'ucrt64\bin'
foreach ($tool in @('g++.exe', 'cmake.exe', 'ctest.exe', 'ninja.exe', 'windres.exe')) {
if (-not (Test-Path -LiteralPath (Join-Path $bin $tool) -PathType Leaf)) {
throw "MSYS2 UCRT64 tool missing: $tool. Run .\setup-toolchain.ps1."
}
}
$bin = (Get-Item -LiteralPath $bin).FullName.Replace('\', '/')
$buildRoot = Join-Path $projectRoot 'build'
$buildDirectory = Join-Path $buildRoot 'msys2-ucrt64'
$previousPath = $env:Path
try {
$env:Path = "$bin;$previousPath"
$version = & (Join-Path $bin 'g++.exe') -dumpfullversion
if ($LASTEXITCODE -ne 0 -or $version -notmatch '^16(\.|$)') {
throw "MSYS2 UCRT64 GCC 16 is required. Found: $version"
}
Write-Output "Building with MSYS2 UCRT64 GCC $version"
$cmake = Join-Path $bin 'cmake.exe'
$options = @('-S', $projectRoot, '-B', $buildDirectory, '-G', 'Ninja',
"-DCMAKE_CXX_COMPILER=$bin/g++.exe",
"-DCMAKE_RC_COMPILER=$bin/windres.exe",
"-DCMAKE_MAKE_PROGRAM=$bin/ninja.exe",
"-DCMAKE_BUILD_TYPE=$Configuration", '-DBUILD_TESTING=ON')
& $cmake @options
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
& $cmake --build $buildDirectory --parallel
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
& (Join-Path $bin 'ctest.exe') --test-dir $buildDirectory --output-on-failure
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
foreach ($runtime in @('libstdc++-6.dll', 'libgcc_s_seh-1.dll', 'libwinpthread-1.dll')) {
Copy-Item -LiteralPath (Join-Path $bin $runtime) -Destination $buildRoot -Force
}
foreach ($program in @('settlement_viewer', 'settlement_sim', 'settlement_colony_benchmark',
'settlement_core_tests', 'settlement_lan_tests')) {
Copy-Item -LiteralPath (Join-Path $buildDirectory "$program.exe") -Destination $buildRoot -Force
}
} finally {
$env:Path = $previousPath
}