Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweaks to make build_usd.py work with ninja #590

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 58 additions & 7 deletions build_scripts/build_usd.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ def RunCMake(context, force, extraArgs = None):

# On Windows, we need to explicitly specify the generator to ensure we're
# building a 64-bit project. (Surely there is a better way to do this?)
# TODO: figure out exactly what "vcvarsall.bat x64" sets to force x64
if generator is None and Windows():
if IsVisualStudio2017OrGreater():
generator = "Visual Studio 15 2017 Win64"
Expand All @@ -217,31 +218,43 @@ def RunCMake(context, force, extraArgs = None):
if MacOS():
osx_rpath = "-DCMAKE_MACOSX_RPATH=ON"

# Note: we use -DCMAKE_BUILD_TYPE=Release for single-configuration
# generators (Ninja, make), and --config Relase for multi-configuration
# generators (Visual Studio); technically we don't need BOTH at the same
# time, but specifying both is simpler than branching
with CurrentWorkingDirectory(buildDir):
Run('cmake '
'-DCMAKE_INSTALL_PREFIX="{instDir}" '
'-DCMAKE_PREFIX_PATH="{depsInstDir}" '
'-DCMAKE_BUILD_TYPE=Release '
'{osx_rpath} '
'{generator} '
'{extraArgs} '
'"{srcDir}"'
.format(instDir=instDir,
depsInstDir=context.instDir,
cmakeBuildType=cmakeBuildType,
srcDir=srcDir,
osx_rpath=(osx_rpath or ""),
generator=(generator or ""),
extraArgs=(" ".join(extraArgs) if extraArgs else "")))
Run("cmake --build . --config Release --target install -- {multiproc}"
.format(multiproc=("/M:{procs}" if Windows() else "-j{procs}")
.format(procs=context.numJobs)))
.format(multiproc=("/M:{procs}"
if generator and "Visual Studio" in generator
else "-j{procs}")
.format(procs=context.numJobs),
buildConfig=buildConfig))

def PatchFile(filename, patches):
def PatchFile(filename, patches, multiLineMatches=False):
"""Applies patches to the specified file. patches is a list of tuples
(old string, new string)."""
oldLines = open(filename, 'r').readlines()
if multiLineMatches:
oldLines = [open(filename, 'r').read()]
else:
oldLines = open(filename, 'r').readlines()
newLines = oldLines
for (oldLine, newLine) in patches:
newLines = [s.replace(oldLine, newLine) for s in newLines]
for (oldString, newString) in patches:
newLines = [s.replace(oldString, newString) for s in newLines]
if newLines != oldLines:
PrintInfo("Patching file {filename} (original in {oldFilename})..."
.format(filename=filename, oldFilename=filename + ".old"))
Expand Down Expand Up @@ -646,6 +659,34 @@ def InstallOpenEXR(context, force, buildArgs):

ilmbaseSrcDir = os.path.join(srcDir, "IlmBase")
with CurrentWorkingDirectory(ilmbaseSrcDir):
# openexr 2.2 has a bug with Ninja:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for documenting this!

# https://github.com/openexr/openexr/issues/94
# https://github.com/openexr/openexr/pull/142
# Fix commit here:
# https://github.com/openexr/openexr/commit/8eed7012c10f1a835385d750fd55f228d1d35df9
# Merged here:
# https://github.com/openexr/openexr/commit/b206a243a03724650b04efcdf863c7761d5d5d5b
if context.cmakeGenerator == "Ninja":
PatchFile(
os.path.join('Half', 'CMakeLists.txt'),
[
("TARGET eLut POST_BUILD",
"OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/eLut.h"),
(" COMMAND eLut > ${CMAKE_CURRENT_BINARY_DIR}/eLut.h",
" COMMAND eLut ARGS > ${CMAKE_CURRENT_BINARY_DIR}/eLut.h\n"
" DEPENDS eLut"),
("TARGET toFloat POST_BUILD",
"OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/toFloat.h"),
(" COMMAND toFloat > ${CMAKE_CURRENT_BINARY_DIR}/toFloat.h",
" COMMAND toFloat ARGS > ${CMAKE_CURRENT_BINARY_DIR}/toFloat.h\n"
" DEPENDS toFloat"),

(" ${CMAKE_CURRENT_BINARY_DIR}/eLut.h\n"
" OBJECT_DEPENDS\n"
" ${CMAKE_CURRENT_BINARY_DIR}/toFloat.h\n",
' "${CMAKE_CURRENT_BINARY_DIR}/eLut.h;${CMAKE_CURRENT_BINARY_DIR}/toFloat.h"\n'),
],
multiLineMatches=True)
RunCMake(context, force, buildArgs)

openexrSrcDir = os.path.join(srcDir, "OpenEXR")
Expand Down Expand Up @@ -806,7 +847,17 @@ def InstallOpenSubdiv(context, force, buildArgs):
# Add on any user-specified extra arguments.
extraArgs += buildArgs

RunCMake(context, force, extraArgs)
oldGenerator = context.cmakeGenerator

# OpenSubdiv seems to error when building on windows w/ Ninja...
# ...so just use the default generator (ie, VisualStudio on windows)
# until someone can sort it out
if oldGenerator == "Ninja" and Windows():
context.cmakeGenerator = None
try:
RunCMake(context, force, extraArgs)
finally:
context.cmakeGenerator = oldGenerator

OPENSUBDIV = Dependency("OpenSubdiv", InstallOpenSubdiv,
"include/opensubdiv/version.h")
Expand Down