diff --git a/build_scripts/build_usd.py b/build_scripts/build_usd.py index 3cdc458a74..dcb74d21ff 100644 --- a/build_scripts/build_usd.py +++ b/build_scripts/build_usd.py @@ -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" @@ -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")) @@ -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: + # 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") @@ -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")