1
0

Bootstrap.bat 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. @ECHO OFF
  2. SETLOCAL
  3. SETLOCAL ENABLEDELAYEDEXPANSION
  4. REM ===========================================================================
  5. SET SelfPath="%0"
  6. SET VsWherePath="C:/Program Files (x86)/Microsoft Visual Studio/Installer/vswhere.exe"
  7. REM ===========================================================================
  8. SET vsversion=%1
  9. IF "%vsversion%" == "" (
  10. CALL :BootstrapLatest
  11. EXIT /B %ERRORLEVEL%
  12. )
  13. IF "%vsversion%" == "vs2010" (
  14. CALL :LegacyVisualBootstrap "%vsversion%" "100"
  15. ) ELSE IF "%vsversion%" == "vs2012" (
  16. CALL :LegacyVisualBootstrap "%vsversion%" "110"
  17. ) ELSE IF "%vsversion%" == "vs2013" (
  18. CALL :LegacyVisualBootstrap "%vsversion%" "120"
  19. ) ELSE IF "%vsversion%" == "vs2015" (
  20. CALL :LegacyVisualBootstrap "%vsversion%" "140"
  21. ) ELSE IF "%vsversion%" == "vs2017" (
  22. CALL :VsWhereVisualBootstrap "%vsversion%" "15.0" "16.0"
  23. ) ELSE IF "%vsversion%" == "vs2019" (
  24. CALL :VsWhereVisualBootstrap "%vsversion%" "16.0" "17.0"
  25. ) ELSE IF "%vsversion%" == "vs2022" (
  26. CALL :VsWhereVisualBootstrap "%vsversion%" "17.0" "18.0"
  27. ) ELSE (
  28. ECHO Unrecognized Visual Studio version %vsversion%
  29. EXIT /B 2
  30. )
  31. REM On error, pause to allow user to notice it if script was launched through explorer
  32. IF %ERRORLEVEL% NEQ 0 (
  33. PAUSE
  34. )
  35. EXIT /B %ERRORLEVEL%
  36. REM ===========================================================================
  37. REM Utils
  38. REM ===========================================================================
  39. REM %1: PremakeVsVersion -> ex: vs2015
  40. REM %2: VsVersion envvar -> ex: 140
  41. :LegacyVisualBootstrap
  42. SET "VsVersion_NoPoint=%~2"
  43. SET "VsEnvVar=VS%VsVersion_NoPoint%COMNTOOLS"
  44. SET "VsPath=!%VsEnvVar%!"
  45. IF NOT EXIST "%VsPath%vsdevcmd.bat" (
  46. ECHO Could not find vsdevcmd.bat to setup Visual Studio environment
  47. EXIT /B 2
  48. )
  49. CALL "%VsPath%vsdevcmd.bat" && nmake MSDEV="%~1" -f Bootstrap.mak windows
  50. EXIT /B %ERRORLEVEL%
  51. REM :LegacyVisualBootstrap
  52. REM ===========================================================================
  53. REM %1: PremakeVsVersion -> ex: vs2010
  54. REM %2: VisualStudio-style VSversionMin -> ex: 15.0
  55. REM %3: VisualStudio-style VSversionMax -> ex: 16.0
  56. :VsWhereVisualBootstrap
  57. SET "PremakeVsVersion=%~1"
  58. SET "VsVersionMin=%~2"
  59. SET "VsVersionMax=%~3"
  60. REM ref: https://github.com/Microsoft/vswhere/wiki/Start-Developer-Command-Prompt
  61. IF NOT EXIST %VsWherePath% (
  62. ECHO Could not find vswhere.exe
  63. EXIT /B 2
  64. )
  65. SET VsWhereCmdLine="!VsWherePath! -nologo -latest -version [%VsVersionMin%,%VsVersionMax%) -property installationPath"
  66. FOR /F "usebackq delims=" %%i in (`!VsWhereCmdLine!`) DO (
  67. IF EXIST "%%i\VC\Auxiliary\Build\vcvars32.bat" (
  68. CALL "%%i\VC\Auxiliary\Build\vcvars32.bat" && nmake MSDEV="%PremakeVsVersion%" -f Bootstrap.mak windows
  69. EXIT /B %ERRORLEVEL%
  70. )
  71. )
  72. ECHO Could not find vcvars32.bat to setup Visual Studio environment
  73. EXIT /B 2
  74. REM :VsWhereVisualBootstrap
  75. REM ===========================================================================
  76. :BootstrapLatest
  77. IF EXIST %VsWherePath% (
  78. REM First try for not legacy Visual Studios ( >vs2017 )
  79. SET VsWhereCmdLine="!VsWherePath! -nologo -latest -property catalog.productLineVersion"
  80. FOR /F "usebackq delims=" %%i in (`!VsWhereCmdLine!`) DO (
  81. CALL %SelfPath% vs%%i
  82. EXIT /B %ERRORLEVEL%
  83. )
  84. )
  85. SET LegacyVSVersions=
  86. REM Get latest Visual Studio legacy version
  87. REM For all env var starting with VS
  88. FOR /F "usebackq delims==" %%i in (`SET VS`) DO (
  89. REM Check if env var match pattern VS*COMNTOOLS (ie: VS140COMNTOOLS)
  90. ECHO "%%i" | FINDSTR /R /C:VS.*COMNTOOLS >nul && (
  91. SET "LegacyVSVersions=%%i"
  92. )
  93. )
  94. REM Strip VS
  95. SET LegacyVSVersions=%LegacyVSVersions:VS=%
  96. REM Strip COMNTOOLS
  97. SET LegacyVSVersions=%LegacyVSVersions:COMNTOOLS=%
  98. SET "VsVersionMap=140-vs2015;120-vs2013;110-vs2012;100-vs2010"
  99. CALL SET PremakeVsVersion=%%VsVersionMap:*%LegacyVSVersions%-=%%
  100. SET PremakeVsVersion=%PremakeVsVersion:;=&REM.%
  101. IF NOT "%PremakeVsVersion%" == "" (
  102. CALL %SelfPath% %PremakeVsVersion%
  103. EXIT /B %ERRORLEVEL%
  104. )
  105. ECHO Could not find a Visual Studio installation
  106. EXIT /B 2
  107. REM :BootstrapLatest
  108. REM ===========================================================================
  109. REM SETLOCAL ENABLEDELAYEDEXPANSION
  110. ENDLOCAL
  111. REM SETLOCAL
  112. ENDLOCAL