Skip to content

Commit

Permalink
Add cmake build script (pwsh)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlatwe committed Dec 1, 2022
1 parent a5ca0e5 commit 15465c0
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
47 changes: 47 additions & 0 deletions build_for_win32.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
param (
[string]$buildtype = "Release",
[int]$clean = 0 # Before building, delete the build directory entirely
)

function check_command {
param([string]$command)
if ((get-command $command -ea silentlycontinue) -eq $null) {
return 1;
}
return 0;
}

if (check_command("cl") -e 0) {
./vcvars2019.ps1
}

# Check prerequisites
$missing = check_command("cmake")
$missing += check_command("ninja")
$missing += check_command("cl")

if ($missing) {
write-host "Visual Studio 2019 was not found!"
return;
}

$builddir = "$psscriptroot/build/win32/$buildtype"

if ($clean -ne 0) {
write-host "-- Cleaning.."
rm -r -force -ea silentlycontinue $builddir
}

write-host "Building $buildtype to $builddir"
pushd # Store current path

mkdir -ea silentlycontinue $builddir
cd $builddir

cmake ../../../physx -G Ninja -DCMAKE_BUILD_TYPE="$buildtype"

cmake --build . --config $buildtype --target install

popd # Restore current path

exit $LastExitCode
8 changes: 8 additions & 0 deletions vcvars2019.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pushd "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build"
cmd /c "vcvars64.bat&set" | foreach {
if ($_ -match "=") {
$v = $_.split("="); set-item -force -path "ENV:\$($v[0])" -value "$($v[1])"
}
}
popd
Write-Host "Visual Studio 2019 Command Prompt variables set." -ForegroundColor Yellow

0 comments on commit 15465c0

Please sign in to comment.