CmvrControlStation/scripts/build_urdfdom_mingw.ps1

87 lines
3.1 KiB
PowerShell

param(
[ValidateRange(1, 32)]
[int]$Jobs = 4,
[switch]$Fresh
)
$ErrorActionPreference = "Stop"
. (Join-Path $PSScriptRoot "native_dep_versions.ps1")
$Cmake = Join-Path $CmakeRoot "bin\cmake.exe"
$requiredPaths = @(
$Cmake,
$Make,
(Join-Path $MingwBin "gcc.exe"),
(Join-Path $MingwBin "g++.exe"),
$TinyXml2Source,
$ConsoleBridgeSource,
$UrdfdomHeadersSource,
$UrdfdomSource
)
foreach ($required in $requiredPaths) {
if (-not (Test-Path -LiteralPath $required)) {
throw "Required path not found: $required"
}
}
$env:PATH = "$MingwBin;$(Join-Path $CmakeRoot 'bin');$env:PATH"
$installCmake = $UrdfdomInstall.Replace("\", "/")
$mingwBinCmake = $MingwBin.Replace("\", "/")
$makeCmake = $Make.Replace("\", "/")
function Build-CmakeDependency(
[string]$Name,
[string]$Source,
[string]$Build,
[string[]]$Options = @()
) {
$sourceCmake = $Source.Replace("\", "/")
$buildCmake = $Build.Replace("\", "/")
if ($Fresh -and (Test-Path -LiteralPath $Build)) {
$resolvedBuild = [System.IO.Path]::GetFullPath($Build)
$resolvedRoot = [System.IO.Path]::GetFullPath($UrdfdomBuildRoot)
if (-not $resolvedBuild.StartsWith($resolvedRoot, [System.StringComparison]::OrdinalIgnoreCase)) {
throw "Refusing to replace build path outside urdfdom build root: $Build"
}
Remove-Item -LiteralPath $Build -Recurse -Force
}
& $Cmake -S $sourceCmake -B $buildCmake -G "MinGW Makefiles" `
"-DCMAKE_BUILD_TYPE=Release" `
"-DCMAKE_INSTALL_PREFIX=$installCmake" `
"-DCMAKE_PREFIX_PATH=$installCmake" `
"-DCMAKE_C_COMPILER=$mingwBinCmake/gcc.exe" `
"-DCMAKE_CXX_COMPILER=$mingwBinCmake/g++.exe" `
"-DCMAKE_MAKE_PROGRAM=$makeCmake" `
"-DCMAKE_POSITION_INDEPENDENT_CODE=ON" `
"-DBUILD_SHARED_LIBS=OFF" `
"-DBUILD_TESTING=OFF" `
@Options
if ($LASTEXITCODE -ne 0) { throw "$Name configure failed" }
& $Cmake --build $Build --target install --parallel $Jobs
if ($LASTEXITCODE -ne 0) { throw "$Name build failed" }
}
New-Item -ItemType Directory -Force $UrdfdomBuildRoot, $UrdfdomInstall | Out-Null
Build-CmakeDependency "TinyXML2" $TinyXml2Source (Join-Path $UrdfdomBuildRoot "tinyxml2") @(
"-Dtinyxml2_BUILD_TESTING=OFF"
)
Build-CmakeDependency "console_bridge" $ConsoleBridgeSource (Join-Path $UrdfdomBuildRoot "console_bridge")
Build-CmakeDependency "urdfdom_headers" $UrdfdomHeadersSource (Join-Path $UrdfdomBuildRoot "urdfdom_headers")
Build-CmakeDependency "urdfdom" $UrdfdomSource (Join-Path $UrdfdomBuildRoot "urdfdom") @(
"-DAPPEND_PROJECT_NAME_TO_INCLUDEDIR=OFF"
)
$parserHeader = Join-Path $UrdfdomInstall "include\urdf_parser\urdf_parser.h"
$modelLibrary = Join-Path $UrdfdomInstall "lib\liburdfdom_model.dll.a"
$modelRuntime = Join-Path $UrdfdomInstall "bin\liburdfdom_model.dll"
if (-not (Test-Path -LiteralPath $parserHeader) `
-or -not (Test-Path -LiteralPath $modelLibrary) `
-or -not (Test-Path -LiteralPath $modelRuntime)) {
throw "urdfdom build finished but headers or libraries are missing"
}
Write-Host "urdfdom and parser dependencies installed to $UrdfdomInstall"