I have unfortunately never tried to compile USD on macOS, and I’ve never used Xcode. But from what I understand of CMake’s documentation, -j<cpucount>
, -j <cpucount>
, --parallel<cpucount>
or --parallel <cpucount>
should be properly translated by CMake to the underlying build system if any of them is passed as a standard CMake flag (as opposed to after --
), from version 3.12 onward.
I believe there is a way to eliminate both the error Ben is encountering (supposing the problem comes from the absence of a varvars64.bat
execution context) and to reduce the bug surface for other similar execution context issues: lines 2362 to 2690 of build_usd.py
indicate that CMake 3.14 is the minimum required version. So it is safe to use CMake’s -j <cpucount>
parallel job flag. That would mean lines 444 to 446:
Run("cmake --build . --config {config} --target install -- {multiproc}"
.format(config=config,
multiproc=FormatMultiProcs(context.numJobs, generator)))
could be replaced by:
Run("cmake --build . --config {config} --target install -j {multiproc}"
.format(config=config, multiproc=context.numJobs))
Since the error Ben has encountered seems to be caused by generator
being None
when passed to FormatMultiProcs()
, that should do it. Does that look sound?
As to why the code responsible for adding /M:<cpucount>
is not firing, my guess is that Ben executed the python build command line outside of a vcvars64.bat
environment. This is what I believe happens in the python script, if that can help (I have reordered the functions):
def RunCMake(context, force, extraArgs = None):
# ...
# --generator "Visual Studio 17 2022" isn't passed to build_usd.py,
# context.cmakeGenerator and generator are None
generator = context.cmakeGenerator
if generator is None and Windows():
# All of these branches return False, generator remains None
if IsVisualStudio2022OrGreater():
generator = "Visual Studio 17 2022"
elif IsVisualStudio2019OrGreater():
generator = "Visual Studio 16 2019"
elif IsVisualStudio2017OrGreater():
generator = "Visual Studio 15 2017 Win64"
# ...
# generator is still None
Run("cmake --build . --config {config} --target install -- {multiproc}"
.format(config=config,
multiproc=FormatMultiProcs(context.numJobs, generator)))
def IsVisualStudio20xxOrGreater():
VISUAL_STUDIO_20xx_VERSION = (<version>, 0)
# This returns False
return IsVisualStudioVersionOrGreater(VISUAL_STUDIO_20xx_VERSION)
def IsVisualStudioVersionOrGreater(desiredVersion):
if not Windows():
return False
# msvcCompilerAndVersion is set to None, so False is returned
msvcCompilerAndVersion = GetVisualStudioCompilerAndVersion()
if msvcCompilerAndVersion:
_, version = msvcCompilerAndVersion
return version >= desiredVersion
return False
def GetVisualStudioCompilerAndVersion():
if not Windows():
return None
# If build_usd.py isn't executed in an environment iniatialised by
# `vcvarsall.bat x64` or `vcvars64.bat`, msvcCompiler is None
msvcCompiler = which('cl')
# As a consequence, None is returned
if msvcCompiler:
match = re.search(
r"(\d+)\.(\d+)",
os.environ.get("VisualStudioVersion", ""))
if match:
return (msvcCompiler, tuple(int(v) for v in match.groups()))
return None
def FormatMultiProcs(numJobs, generator):
tag = "-j"
# generator is None at this point, so -j<numJobs> is returned
if generator:
if "Visual Studio" in generator:
tag = "/M:" # This will build multiple projects at once.
elif "Xcode" in generator:
tag = "-j "
return "{tag}{procs}".format(tag=tag, procs=numJobs)
I hope that helps!