Skip to content

Commit

Permalink
Use vswhere to set environment variables for MSVS 2017
Browse files Browse the repository at this point in the history
Allow building official releases with MSVS 2017 without doing it from
its "developer command prompt" by using the vswhere utility to set up
the paths correctly.

Closes wxWidgets#18083.
  • Loading branch information
Danny Scott authored and vadz committed Feb 17, 2018
1 parent ac608af commit a52b839
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 4 deletions.
54 changes: 54 additions & 0 deletions build/tools/msvs/findvs.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
@echo off

rem This is used to set up the VS2017 and later (hopefully) environment.

rem Called with two paramaters, the inclusive low and the exclusisve high.
if "%1" == "" goto ERR_NOPARM
if "%2" == "" goto ERR_NOPARM

rem If not running from official build, remember where we are.

if "%curr_dir%" == "" (
set curr_dir=%cd%
)

@echo Checking if vswhere in path
vswhere 1>nul

if errorlevel 9009 (
@echo "vswhere not found, trying C:\Program Files (x86)\Microsoft Visual Studio\Installer"
set "PATH=C:\Program Files (x86)\Microsoft Visual Studio\Installer;%PATH%"
)

vswhere 1>nul
if errorlevel 9009 (
@echo "vswhere not found"
goto ERR_EXIT
)

for /f "usebackq tokens=*" %%i in (`vswhere -latest -version "[%1,%2)" -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do (
set InstallDir=%%i
)

if "%InstallDir%" == "" (
@echo Install directory not found
goto ERR_EXIT
)

if NOT exist "%InstallDir%\Common7\Tools\vsdevcmd.bat" (
@echo Can't find an vsdevcmd.bat
goto ERR_EXIT
)

call "%InstallDir%"\Common7\Tools\vsdevcmd.bat

rem Go back to where we were before vsdevcmd changed things.
cd %curr_dir%

goto end

:ERR_NOPARM
@echo Need to specifiy version min/max range, eg.: 15.0 16.0
:ERR_EXIT
exit /b 1
:end
19 changes: 15 additions & 4 deletions build/tools/msvs/officialbuild.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
ECHO ON
@echo off

rem SetLocal EnableDelayedExpansion

if "%1" == "" goto ERR_NOPARM

Expand All @@ -22,11 +24,20 @@ set compvers="Unknown"

if "%1" == "vc141" (
@echo Building for vc141 / vs2017
@echo This will only work if the environment varialbe VS150COMNTOOLS is set
@echo or a VS2017 command prompt is used.
set comp=141
set compvers=vc141
call "%VS150COMNTOOLS%VsDevCmd.bat"

if NOT "%VS150COMNTOOLS%" == "" (
call "%VS150COMNTOOLS%VsDevCmd.bat"
)
if "%VS150COMNTOOLS%" == "" (
call %curr_dir%\findvs 15.0 16.0

if errorlevel 1 (
@echo vswhere.exe must be in your path or a VS2017 developer command prompt must be used.
goto end
)
)
)
if "%1" == "vc140" (
@echo Building for vc140 / vs2015
Expand Down

0 comments on commit a52b839

Please sign in to comment.