Last active
November 19, 2015 12:40
-
-
Save iki/48fe1b0a7d8ff0c4177f to your computer and use it in GitHub Desktop.
Visual Studio 10/11/14 environment setup for python, or node.js/node-gyp. Determines VS version and architecture, calls respective vcVarsAll.bat and sets vcTargetsPath if needed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
setlocal enableextensions | |
::: echo === "%~f0" %* >&2 | |
set vcArgs=%* | |
set vcVersions=14 11 10 | |
call :poparg vcArgs vcVersions 10 10 %1 && shift | |
call :poparg vcArgs vcVersions 11 11 %1 && shift | |
call :poparg vcArgs vcVersions 14 14 %1 && shift | |
call :cleartest | |
for %%v in (%vcVersions%) do ( | |
call :test "%%~v" "%ProgramFiles%\Microsoft Visual Studio %%v.0\VC" | |
call :test "%%~v" "%ProgramFiles(x86)%\Microsoft Visual Studio %%v.0\VC" | |
) | |
if not defined vcVarsAll echo Could not locate Visual Studio %vcVersions: =/%. >&2 && exit /b 1 | |
if defined vcVersion call :testtarget "%ProgramFiles%\MSBuild\Microsoft.Cpp\v4.0\V%vcVersion%0" | |
if defined vcVersion call :testtarget "%ProgramFiles(x86)%\MSBuild\Microsoft.Cpp\v4.0\V%vcVersion%0" | |
set vcArch= | |
if defined PROCESSOR_ARCHITECTURE set vcArch=%PROCESSOR_ARCHITECTURE% | |
if defined PROCESSOR_ARCHITEW6432 set vcArch=%PROCESSOR_ARCHITECTURE%_%PROCESSOR_ARCHITEW6432% | |
call :poparg vcArgs vcArch x86 32 %1 && shift | |
call :poparg vcArgs vcArch amd64 64 %1 && shift | |
call :poparg vcArgs vcArch x86_amd64 3264 %1 && shift | |
for %%a in (x86 x64 amd64 arm x86_arm x86_amd64) do call :poparg vcArgs vcArch %%a %%a %1 && shift | |
if "%~1"=="" goto shell | |
echo === [%vcVersion%] "%vcVarsAll%" %vcArch% >&2 | |
call "%vcVarsAll%" %vcArch% | |
if errorlevel 1 exit /b %errorlevel% | |
echo === %vcArgs% >&2 | |
call %vcArgs% | |
exit /b %errorlevel% | |
:shell | |
echo === "%comspec%" /k "%vcVarsAll%" %vcArch% >&2 | |
"%comspec%" /k "%vcVarsAll%" %vcArch% | |
exit /b %errorlevel% | |
:poparg | |
if /i not "%~5"=="%~4" if /i not "%~5"=="--%~4" exit /b 1 | |
::: echo ... %~2: %~3 [%~5] >&2 | |
set %~2=%~3 | |
if "%~1"=="" exit /b 0 | |
if defined %~1 call :eval set %~1=%%%~1:*%4=%% | |
if defined %~1 call :eval if "%%%~1:~0,1%%"==" " set %~1=%%%~1:* =%% | |
exit /b 0 | |
:eval | |
%* | |
exit /b %errorlevel% | |
:testtarget | |
if defined vcTargetsPath exit /b 0 | |
if "%~1"=="" exit /b 2 | |
if not exist "%~1" exit /b 1 | |
set vcTargetsPath=%~1 | |
exit /b 0 | |
:test | |
if defined vcVersion if defined vcVarsAll exit /b 0 | |
if "%~1"=="" exit /b 2 | |
if not exist "%~2\vcvarsall.bat" exit /b 1 | |
set vcVersion=%~1 | |
set vcVarsAll=%~2\vcvarsall.bat | |
exit /b 0 | |
:cleartest | |
set vcVersion= | |
set vcVarsAll= | |
exit /b 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample usage: