diff --git a/CraftSettings.ini.template b/CraftSettings.ini.template --- a/CraftSettings.ini.template +++ b/CraftSettings.ini.template @@ -16,6 +16,10 @@ ## This option should be set to False if you use the msvc 201X Express Edition 64bit compiler ## in all other cases, simply keep this option commented out #Native=False +## This option specifies which MSVC toolset to use. Leave this commented out for MSVC to pick +## the newest available toolset. +## This is an expert option, do not touch it unless you know exactly what it means. +#MSVCToolset=14.16 ## This option can be used to enable a notification backend. ## As soon as the buildprocess of a project has finished a notification will be displayed. diff --git a/bin/CraftCompiler.py b/bin/CraftCompiler.py --- a/bin/CraftCompiler.py +++ b/bin/CraftCompiler.py @@ -105,6 +105,10 @@ self._architecture = "x86" if self._abi.endswith("32") else "x64" + self._MSVCToolset = None + if self.isMSVC(): + self._MSVCToolset = CraftCore.settings.get("General", "MSVCToolset") + def __str__(self): return "-".join(self.signature) @@ -128,6 +132,10 @@ def architecture(self): return self._architecture + @property + def msvcToolset(self): + return self._MSVCToolset + @property def gnuArchitecture(self): return "x86" if self.isX86() else "x86_64" diff --git a/bin/CraftSetupHelper.py b/bin/CraftSetupHelper.py --- a/bin/CraftSetupHelper.py +++ b/bin/CraftSetupHelper.py @@ -175,7 +175,7 @@ return SetupHelper._getOutput(command + args)[1] @staticmethod - def getMSVCEnv(version=None, architecture="x86", native=True) -> str: + def getMSVCEnv(version=None, architecture="x86", toolset=None, native=True) -> str: if native: architectures = {"x86": "amd64_x86", "x64": "amd64"} else: @@ -186,8 +186,12 @@ if version == 14: # are we using msvc2017 with "VC++ 2015.3 v14.00 (v140) toolset for desktop" path = SetupHelper._callVCVER(15, args=["-products", "*", "-requires", "Microsoft.VisualStudio.Component.VC.140"], native=native) - if path: - args += " -vcvars_ver=14.0" + if path and not toolset: + toolset = "14.0" + + if toolset: + args += f" -vcvars_ver={toolset}" + if not path: path = SetupHelper._callVCVER(version, native=native) if not path: @@ -210,6 +214,7 @@ if CraftCore.compiler.isMSVC(): return SetupHelper.getMSVCEnv(CraftCore.compiler.getInternalVersion(), CraftCore.compiler.architecture, + CraftCore.compiler.msvcToolset, CraftCore.compiler.isNative()) elif CraftCore.compiler.isIntel(): architectures = {"x86": "ia32", "x64": "intel64"}