From 15465c0fc47e5a84209881cfc7e6c77b25d5ee6c Mon Sep 17 00:00:00 2001 From: davidlatwe Date: Fri, 2 Dec 2022 00:45:34 +0800 Subject: [PATCH] Add cmake build script (pwsh) --- build_for_win32.ps1 | 47 +++++++++++++++++++++++++++++++++++++++++++++ vcvars2019.ps1 | 8 ++++++++ 2 files changed, 55 insertions(+) create mode 100644 build_for_win32.ps1 create mode 100644 vcvars2019.ps1 diff --git a/build_for_win32.ps1 b/build_for_win32.ps1 new file mode 100644 index 000000000..7921b747d --- /dev/null +++ b/build_for_win32.ps1 @@ -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 \ No newline at end of file diff --git a/vcvars2019.ps1 b/vcvars2019.ps1 new file mode 100644 index 000000000..cff75824a --- /dev/null +++ b/vcvars2019.ps1 @@ -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 \ No newline at end of file