From bbe0059e474ee4d26be2aee2a52250a9be381867 Mon Sep 17 00:00:00 2001 From: Damien Courtois Date: Tue, 31 Jan 2023 15:07:06 +0100 Subject: [PATCH] [build] Fix toolchain detection on Windows when using Microsoft Build Tools instead of Visual Studio. --- build_scripts/build_usd.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/build_scripts/build_usd.py b/build_scripts/build_usd.py index d972749492..92f5cb1240 100644 --- a/build_scripts/build_usd.py +++ b/build_scripts/build_usd.py @@ -127,11 +127,11 @@ def GetVisualStudioCompilerAndVersion(): msvcCompiler = which('cl') if msvcCompiler: - # VisualStudioVersion environment variable should be set by the + # VCToolsVersion environment variable should be set by the # Visual Studio Command Prompt. match = re.search( r"(\d+)\.(\d+)", - os.environ.get("VisualStudioVersion", "")) + os.environ.get("VCToolsVersion", "")) if match: return (msvcCompiler, tuple(int(v) for v in match.groups())) return None @@ -146,16 +146,17 @@ def IsVisualStudioVersionOrGreater(desiredVersion): return version >= desiredVersion return False +# Helpers to determine the version of "Visual Studio" (also support the Build Tools) based +# on the version of the MSVC compiler. +# See MSVC++ versions table on https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B def IsVisualStudio2022OrGreater(): - VISUAL_STUDIO_2022_VERSION = (17, 0) + VISUAL_STUDIO_2022_VERSION = (14, 30) return IsVisualStudioVersionOrGreater(VISUAL_STUDIO_2022_VERSION) - def IsVisualStudio2019OrGreater(): - VISUAL_STUDIO_2019_VERSION = (16, 0) + VISUAL_STUDIO_2019_VERSION = (14, 20) return IsVisualStudioVersionOrGreater(VISUAL_STUDIO_2019_VERSION) - def IsVisualStudio2017OrGreater(): - VISUAL_STUDIO_2017_VERSION = (15, 0) + VISUAL_STUDIO_2017_VERSION = (14, 1) return IsVisualStudioVersionOrGreater(VISUAL_STUDIO_2017_VERSION) def GetPythonInfo(context): @@ -387,7 +388,7 @@ def RunCMake(context, force, extraArgs = None): if generator is not None: generator = '-G "{gen}"'.format(gen=generator) - if IsVisualStudio2019OrGreater(): + if "Visual Studio" in generator and IsVisualStudio2019OrGreater(): generator = generator + " -A x64" toolset = context.cmakeToolset