diff --git a/src/engine/build.bat b/src/engine/build.bat index 7466400ed..1998d54d5 100644 --- a/src/engine/build.bat +++ b/src/engine/build.bat @@ -31,9 +31,9 @@ ECHO ### Toolsets supported by this script are: borland, como, gcc, ECHO ### gcc-nocygwin, intel-win32, metrowerks, mingw, msvc, vc7, vc8, ECHO ### vc9, vc10, vc11, vc12, vc14, vc141 ECHO ### -ECHO ### If you have Visual Studio 2017 installed you will need to build from -ECHO ### the Visual Studio Command Prompt for VS 2017 as we where unable to -ECHO ### detect your toolset installtion. +ECHO ### If you have Visual Studio 2017 installed you will need either update +ECHO ### the Visual Studio 2017 installer or run from VS 2017 Command Prompt +ECHO ### as we where unable to detect your toolset installation. ECHO ### call :Set_Error endlocal diff --git a/src/engine/config_toolset.bat b/src/engine/config_toolset.bat index 560d5aa3b..a66317c2f 100644 --- a/src/engine/config_toolset.bat +++ b/src/engine/config_toolset.bat @@ -161,6 +161,7 @@ set "BOOST_JAM_OPT_YYACC=/Febootstrap\yyacc0" set "_known_=1" :Skip_VC14 if NOT "_%BOOST_JAM_TOOLSET%_" == "_vc141_" goto Skip_VC141 +call vswhere_usability_wrapper.cmd if "_%BOOST_JAM_TOOLSET_ROOT%_" == "__" ( if NOT "_%VS150COMNTOOLS%_" == "__" ( set "BOOST_JAM_TOOLSET_ROOT=%VS150COMNTOOLS%..\..\VC\" diff --git a/src/engine/guess_toolset.bat b/src/engine/guess_toolset.bat index a671802d3..419cffd16 100644 --- a/src/engine/guess_toolset.bat +++ b/src/engine/guess_toolset.bat @@ -28,10 +28,13 @@ goto :eof :Guess REM Check the variable first. This can be set manually by the user (by running the tools commmand prompt). call :Clear_Error +call vswhere_usability_wrapper.cmd if NOT "_%VS150COMNTOOLS%_" == "__" ( set "BOOST_JAM_TOOLSET=vc141" set "BOOST_JAM_TOOLSET_ROOT=%VS150COMNTOOLS%..\..\VC\" goto :eof) + +:skip_vswhere if EXIST "%VS_ProgramFiles%\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" ( set "BOOST_JAM_TOOLSET=vc141" set "BOOST_JAM_TOOLSET_ROOT=%VS_ProgramFiles%\Microsoft Visual Studio\2017\Enterprise\VC\" diff --git a/src/engine/vswhere_usability_wrapper.cmd b/src/engine/vswhere_usability_wrapper.cmd new file mode 100644 index 000000000..b5e5653ad --- /dev/null +++ b/src/engine/vswhere_usability_wrapper.cmd @@ -0,0 +1,20 @@ +:: Copyright 2017 - Refael Ackermann +:: Distributed under MIT style license +:: See accompanying file LICENSE at https://github.com/node4good/windows-autoconf +:: version: 1.14.0 + +@if not defined DEBUG_HELPER @ECHO OFF +setlocal +set VSWHERE_REQ=-requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 +set VSWHERE_PRP=-property installationPath +set VSWHERE_LMT=-version "[15.0,16.0)" +SET VSWHERE_ARGS=-latest -products * %VSWHERE_REQ% %VSWHERE_PRP% %VSWHERE_LMT% +set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer" +if not exist "%VSWHERE%" set "VSWHERE=%ProgramFiles%\Microsoft Visual Studio\Installer" +if not exist "%VSWHERE%" exit /B 1 +set Path=%Path%;%VSWHERE% +for /f "usebackq tokens=*" %%i in (`vswhere %VSWHERE_ARGS%`) do ( + endlocal + set "VCINSTALLDIR=%%i\VC\" + set "VS150COMNTOOLS=%%i\Common7\Tools\" + exit /B 0) diff --git a/src/tools/msvc.jam b/src/tools/msvc.jam index 5f179933d..b7b21a2d1 100644 --- a/src/tools/msvc.jam +++ b/src/tools/msvc.jam @@ -1250,10 +1250,40 @@ local rule default-path ( version ) } else { - # Check environment. + # try to use vswhere + local pseudo_env_VS150 ; + if $(version) = 14.1 || $(version) = "default" + { + local req = "-requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64" ; + local prop = "-property installationPath" ; + local limit = "-version \"[15.0,16.0)\"" ; + local root = [ os.environ "ProgramFiles(x86)" ] ; + if ( ! $(root) ) + { + root = [ os.environ "ProgramFiles" ] ; + } + local vswhere = "$(root)\\Microsoft Visual Studio\\Installer\\vswhere.exe" ; + if ( [ path.exists $(vswhere) ] ) + { + local vmwhere_cmd = "\"$(vswhere)\" -latest -products * $(req) $(prop) $(limit)" ; + local shell_ret = [ SPLIT_BY_CHARACTERS [ SHELL $(vmwhere_cmd) ] : "\n" ] ; + pseudo_env_VS150 = [ path.native [ path.join $(shell_ret) "\\Common7\\Tools" ] ] ; + } + } + + # Check environment or previous path_VS150 for local env in $(.version-$(version)-env) { - local env-path = [ os.environ $(env) ] ; + local env-path ; + if ( $(pseudo_env_VS150) && [ path.exists $(pseudo_env_VS150) ] ) + { + env-path = $(pseudo_env_VS150) ; + } + else + { + env-path = [ os.environ $(env) ] ; + } + ECHO "env-path $(env-path)" ; if $(env-path) && $(.version-$(version)-path) { for local bin-path in $(.version-$(version)-path) @@ -1669,8 +1699,7 @@ if [ MATCH (--debug-configuration) : [ modules.peek : ARGV ] ] .version-7.1toolkit-path = "Microsoft Visual C++ Toolkit 2003/bin" ; .version-7.1toolkit-env = VCToolkitInstallDir ; # Visual Studio 2017 doesn't use a registry at all. And the suggested methods -# of discovery involve having a compiled program. We can't do that as it would -# make for a recursive discovery and build dependency cycle. So we search +# of discovery involve having a compiled program. So as a fallback we search # paths for VS2017 (aka msvc >= 14.1). .version-14.1-path = "../../VC/Tools/MSVC/*/bin/Host*/*"