-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup_vs.bat
139 lines (103 loc) · 2.9 KB
/
setup_vs.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
@echo off
set A_CURR_DIR=%~d0%~p0
setlocal EnableDelayedExpansion
set args="%*"
:: Hard code 64 bit
set args=%args% /WIN64
echo %args% | find /i "/VS2017" >NUL
if not errorlevel 1 (
set version_lower=15.0
set version_upper=16.0
set generator_version=Visual Studio 15
)
echo %args% | find /i "/VS2019" >NUL
if not errorlevel 1 (
set version_lower=16.0
set version_upper=17.0
set generator_version=Visual Studio 16
)
echo %args% | find /i "/VS2022" >NUL
if not errorlevel 1 (
set version_lower=17.0
set version_upper=18.0
set generator_version=Visual Studio 17
)
:: Is /WIN64 specified?
set vs_build_type=x86
echo %args% | find /i "/WIN64" > nul
if not errorlevel 1 (
set vs_build_type=amd64
)
:: Is /x64 specified?
echo %args% | find /i "/x64" > nul
if not errorlevel 1 (
set vs_build_type=amd64
)
:: Looping over all installed Visual Studio versions.
:: %%i = "installationVersion" or "installationPath"
:: %%j = <number> <path>
for /f "usebackq tokens=1* delims=: " %%i in (`call "%A_CURR_DIR%\vswhere.exe" -legacy -all`) do (
if /i "%%i"=="installationVersion" (
set installed_version=%%j
:: Testing version range such that [lower, upper).
if !installed_version! geq !version_lower! (
if not !installed_version! geq !version_upper! (
goto version_found
)
)
)
:: Assumes "installationPath" comes before "installationVersion".
if /i "%%i"=="installationPath" (
set vs_installation_path=%%j
)
)
:: We didn't find the specified version. Reset vs_installation_path.
set vs_installation_path=
echo.
echo Unable to find installation of: %args%
echo Visual Studio installations found:
for /f "usebackq tokens=1* delims=: " %%i in (`call "%A_CURR_DIR%\vswhere.exe" -legacy -all`) do (
if /i "%%i"=="installationPath" (
echo %%i: %%j
)
if /i "%%i"=="installationVersion" (
echo %%i: %%j
)
)
goto done
:version_found
echo.
echo Visual Studio version range:
echo ^[!version_lower!, !version_upper!^)
:done
endlocal & (
set "VS_INSTALLATION_PATH=%vs_installation_path%"
set "VS_BUILD_TYPE=%vs_build_type%"
set "VS_GENERATOR_VERSION=%generator_version%"
)
if "%VS_INSTALLATION_PATH%"=="" (
goto exit
)
if %VS_BUILD_TYPE%==amd64 (
:: For VS2013.
set PreferredToolArchitecture=x64
)
:: VS2013 and VS2015: vs_installation_path/VC/vcvarsall.bat
:: VS2017: vs_installation_path/VC/Auxiliary/Build/vcvarsall.bat
set VS_VCVARSALL_FILE="%VS_INSTALLATION_PATH%\VC\vcvarsall.bat"
if not exist %VS_VCVARSALL_FILE% (
set VS_VCVARSALL_FILE="%VS_INSTALLATION_PATH%\VC\Auxiliary\Build\vcvarsall.bat"
)
if not exist %VS_VCVARSALL_FILE% (
echo. ERROR: Unable to find vcvarsall.bat!
goto exit
)
echo Visual Studio installation path:
echo %VS_INSTALLATION_PATH%
echo vcvarsall.bat used:
echo %VS_VCVARSALL_FILE%
echo.
call %VS_VCVARSALL_FILE% %VS_BUILD_TYPE%
echo.
set VC_INITIALIZED=1
:exit