K.Takata | c3430cb | 2022-09-21 11:56:41 +0100 | [diff] [blame^] | 1 | @echo off |
| 2 | rem To be used on MS-Windows for Visual C++ 2017 or later. |
| 3 | rem See INSTALLpc.txt for information. |
| 4 | rem |
| 5 | rem Usage: |
| 6 | rem For x86 builds run this with "x86" option: |
| 7 | rem msvc-latest x86 |
| 8 | rem For x64 builds run this with "x86_amd64" option or "x64" option: |
| 9 | rem msvc-latest x86_amd64 |
| 10 | rem msvc-latest x64 |
| 11 | rem |
| 12 | rem Optional environment variables: |
| 13 | rem VSWHERE: |
| 14 | rem Full path to vswhere.exe. |
| 15 | rem VSVEROPT: |
| 16 | rem Option to search specific version of Visual Studio. |
| 17 | rem Default: -latest |
| 18 | rem To search VS2017: |
| 19 | rem set "VSVEROPT=-version [15.0^,16.0^)" |
| 20 | rem To search VS2019: |
| 21 | rem set "VSVEROPT=-version [16.0^,17.0^)" |
| 22 | rem To search VS2022: |
| 23 | rem set "VSVEROPT=-version [17.0^,18.0^)" |
| 24 | |
| 25 | if "%VSWHERE%"=="" ( |
| 26 | set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" |
| 27 | set VSWHERE_SET=yes |
| 28 | ) |
| 29 | if not exist "%VSWHERE%" ( |
| 30 | echo Error: vswhere not found. |
| 31 | set VSWHERE= |
| 32 | set VSWHERE_SET= |
| 33 | exit /b 1 |
| 34 | ) |
| 35 | |
| 36 | if "%VSVEROPT%"=="" ( |
| 37 | set VSVEROPT=-latest |
| 38 | set VSVEROPT_SET=yes |
| 39 | ) |
| 40 | |
| 41 | rem Search Visual Studio Community, Professional or above. |
| 42 | for /f "usebackq tokens=*" %%i in (`"%VSWHERE%" %VSVEROPT% -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do ( |
| 43 | set InstallDir=%%i |
| 44 | ) |
| 45 | if exist "%InstallDir%\VC\Auxiliary\Build\vcvarsall.bat" ( |
| 46 | call "%InstallDir%\VC\Auxiliary\Build\vcvarsall.bat" %* |
| 47 | goto done |
| 48 | ) |
| 49 | |
| 50 | rem Search Visual Studio 2017 Express. |
| 51 | rem (Visual Studio 2017 Express uses different component IDs.) |
| 52 | for /f "usebackq tokens=*" %%i in (`"%VSWHERE%" %VSVEROPT% -products Microsoft.VisualStudio.Product.WDExpress -property installationPath`) do ( |
| 53 | set InstallDir=%%i |
| 54 | ) |
| 55 | if exist "%InstallDir%\VC\Auxiliary\Build\vcvarsall.bat" ( |
| 56 | call "%InstallDir%\VC\Auxiliary\Build\vcvarsall.bat" %* |
| 57 | ) else ( |
| 58 | echo Error: vcvarsall.bat not found. |
| 59 | rem Set ERRORLEVEL to 1. |
| 60 | call |
| 61 | ) |
| 62 | |
| 63 | :done |
| 64 | if "%VSWHERE_SET%"=="yes" ( |
| 65 | set VSWHERE= |
| 66 | set VSWHERE_SET= |
| 67 | ) |
| 68 | if "%VSVEROPT_SET%"=="yes" ( |
| 69 | set VSVEROPT= |
| 70 | set VSVEROPT_SET= |
| 71 | ) |
| 72 | set InstallDir= |