mirror of
https://git.recroomarchive.org/Radium/libradhook.git
synced 2026-08-07 09:10:59 +00:00
108 lines
2.5 KiB
PowerShell
108 lines
2.5 KiB
PowerShell
param(
|
|
[ValidateSet("msvc", "gcc", "android")]
|
|
[string]$Target = "msvc",
|
|
|
|
[ValidateSet("Debug", "Release")]
|
|
[string]$Config = "Release",
|
|
|
|
[switch]$Clean,
|
|
|
|
[string]$AndroidNDK = $env:ANDROID_NDK_HOME,
|
|
|
|
[switch]$Static,
|
|
|
|
[switch]$RunTests
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$BuildDir = "build/$Target-$Config"
|
|
$Generator = ""
|
|
$Toolchain = ""
|
|
$ExtraArgs = @()
|
|
|
|
if ($Clean -and (Test-Path $BuildDir)) {
|
|
Remove-Item $BuildDir -Recurse -Force
|
|
}
|
|
|
|
switch ($Target) {
|
|
|
|
"msvc" {
|
|
$VsPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\VsDevCmd.bat"
|
|
if (-not (Test-Path $VsPath)) {
|
|
$VsPath = "${env:ProgramFiles}\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat"
|
|
}
|
|
|
|
if (-not (Test-Path $VsPath)) {
|
|
throw "MSVC environment not found. Install Visual Studio C++ build tools."
|
|
}
|
|
|
|
$Generator = "Visual Studio 17 2022"
|
|
$Arch = "x64"
|
|
$ExtraArgs += "-A $Arch"
|
|
}
|
|
|
|
"gcc" {
|
|
$Generator = "Ninja"
|
|
$ExtraArgs += "-DCMAKE_C_COMPILER=gcc"
|
|
$ExtraArgs += "-DCMAKE_CXX_COMPILER=g++"
|
|
$ExtraArgs += "-DCMAKE_BUILD_TYPE=$Config"
|
|
}
|
|
|
|
"android" {
|
|
if (-not $AndroidNDK) {
|
|
throw "Android NDK path not set. Pass -AndroidNDK or set ANDROID_NDK_HOME."
|
|
}
|
|
|
|
$Generator = "Ninja"
|
|
|
|
$Toolchain = "$AndroidNDK/build/cmake/android.toolchain.cmake"
|
|
|
|
$ExtraArgs += "-DCMAKE_TOOLCHAIN_FILE=$Toolchain"
|
|
$ExtraArgs += "-DANDROID_ABI=arm64-v8a"
|
|
$ExtraArgs += "-DANDROID_PLATFORM=android-24"
|
|
$ExtraArgs += "-DCMAKE_BUILD_TYPE=$Config"
|
|
}
|
|
}
|
|
|
|
$SharedLibs = if ($Static) { "OFF" } else { "ON" }
|
|
$ExtraArgs += "-DBUILD_SHARED_LIBS=$SharedLibs"
|
|
|
|
Write-Host "=== Building RadHook ==="
|
|
Write-Host "Target: $Target"
|
|
Write-Host "Config: $Config"
|
|
Write-Host "Build dir: $BuildDir"
|
|
Write-Host "Shared libs: $SharedLibs"
|
|
Write-Host ""
|
|
|
|
cmake -S . -B $BuildDir -G $Generator @ExtraArgs
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "CMake configure failed"
|
|
}
|
|
|
|
if ($Target -eq "msvc") {
|
|
cmake --build $BuildDir --config $Config
|
|
} else {
|
|
cmake --build $BuildDir
|
|
}
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Build failed"
|
|
}
|
|
|
|
if ($RunTests) {
|
|
Write-Host "`n=== Running tests ==="
|
|
|
|
if ($Target -eq "msvc") {
|
|
ctest --test-dir $BuildDir --build-config $Config --output-on-failure
|
|
} else {
|
|
ctest --test-dir $BuildDir --output-on-failure
|
|
}
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Tests failed"
|
|
}
|
|
}
|
|
|
|
Write-Host "`nBuild complete: $BuildDir" |