diff --git a/share/dev/windows/ocio.bat b/share/dev/windows/ocio.bat index a4762a97d9..9dd42745be 100644 --- a/share/dev/windows/ocio.bat +++ b/share/dev/windows/ocio.bat @@ -22,8 +22,8 @@ set INSTALL_PATH_OK=n rem Python location set PYTHON_PATH= -rem Microsoft Visual Studio path -set MSVS_PATH=%programfiles%\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build +rem Microsoft Visual Studio path (will auto-find if not passed in cmd args) +set MSVS_PATH= set DO_CONFIGURE=0 @@ -75,6 +75,22 @@ if NOT "%~1"=="" ( goto :args_loop ) +rem If not overridden by the cmd line args, find and use the latest Visual Studio +if NOT DEFINED MSVS_PATH ( + for /f %%i in ('"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -format value -property installationPath -latest') do ( + echo Found Visual Studio installation at '%%i' + set MSVS_PATH=%%i + ) +) + +IF NOT EXIST "!MSVS_PATH!" ( + echo Could not find MS Visual Studio. Please provide the location for Microsoft Visual Studio vcvars64.bat or modify MSVS_PATH in the script. + rem The double dash are in quote here because otherwise the echo command thow an error. + echo "--msvs " + echo E.g. C:\Program Files\Microsoft Visual Studio\2022\Enterprise\ + exit /b +) + rem Testing the path before cmake IF NOT EXIST "!VCPKG_PATH!" ( echo Could not find Vcpkg. Please provide the location for vcpkg or modify VCPKG_PATH in this script. @@ -103,14 +119,6 @@ if NOT EXIST "!PYTHON_PATH!\python.exe" ( ) ) -IF NOT EXIST "!MSVS_PATH!" ( - echo Could not find MS Visual Studio. Please provide the location for Microsoft Visual Studio vcvars64.bat or modify MSVS_PATH in the script. - rem The double dash are in quote here because otherwise the echo command thow an error. - echo "--msvs " - echo E.g. C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build - exit /b -) - if !CUSTOM_BUILD_PATH!==0 ( echo. set /p BUILD_PATH_OK=Default build path [!BUILD_PATH!] is used. Is it ok? [y/n]: @@ -139,7 +147,7 @@ set INSTALL_PATH=!INSTALL_PATH!\!CMAKE_BUILD_TYPE! rem **************************************************************************************************************** rem Setting up the environment using MS Visual Studio batch script -set VCVARS64_PATH="!MSVS_PATH!\vcvars64.bat" +set VCVARS64_PATH="!MSVS_PATH!\VC\Auxiliary\Build\vcvars64.bat" IF NOT EXIST !VCVARS64_PATH! ( rem Checking for vcvars64.bat script. rem !MSVS_PATH! is checked earlier in the script @@ -295,8 +303,8 @@ echo. echo Optional options depending on the environment: echo --python Python installation location echo. -echo --msvs path where to find vcvars64.bat from Microsoft Visual Studio -echo Default: C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build +echo --msvs Root folder of the Microsoft Visual Studio. (E.g. C:\Program Files\Microsoft Visual Studio\2022) +echo Default: installation path of the latest Visual Studio found in the system by the vswhere.exe tool. echo. echo --b build location echo Default: %TEMP%\OCIO\build diff --git a/share/dev/windows/ocio_deps.bat b/share/dev/windows/ocio_deps.bat index af420cd33d..c616bebf5a 100644 --- a/share/dev/windows/ocio_deps.bat +++ b/share/dev/windows/ocio_deps.bat @@ -104,16 +104,14 @@ if ErrorLevel 1 ( ) echo Checking for Microsoft Visual Studio... -set MSVS=0 -for /d %%a in ("%programfiles%\Microsoft Visual Studio*") do ( - for /f "tokens=3 delims=\" %%x in ("%%a") do set MSVS=1 +set MSVS_PATH= +for /f %%i in ('"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -format value -property installationPath -latest') do ( + echo Found Visual Studio installation at '%%i' + set MSVS_PATH=%%i ) -if !MSVS!==0 ( - echo No Microsoft Visual Studio installation was found in !programfiles!. - echo For non-standard installation path, please use the following option: - rem The double dash are in quote here because otherwise the echo command thow an error. - echo "ocio_deps --vs " +if NOT EXIST !MSVS_PATH! ( + echo No Microsoft Visual Studio installation was found in the system. exit /b )