@echo off
setlocal EnableDelayedExpansion
cd /d "%~dp0"

if not exist build\CMakeCache.txt (
  echo Run configure_msvc.bat first.
  exit /b 1
)

set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
for /f "usebackq tokens=*" %%i in (`"%VSWHERE%" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do set "VSINSTALL=%%i"
if not defined VSINSTALL (
  echo MSVC not found. Add C++ workload in Visual Studio Installer.
  exit /b 1
)
call "!VSINSTALL!\Common7\Tools\VsDevCmd.bat" -arch=x64 -host_arch=x64
if errorlevel 1 exit /b 1

cmake --build build
pause
exit /b %ERRORLEVEL%
