From 6120da18d0b4363ef2571aab0546b650bf29fa17 Mon Sep 17 00:00:00 2001 From: Paul Molodowitch Date: Sun, 5 Aug 2018 07:58:59 -0700 Subject: [PATCH 1/4] [build_usd] Allow building with Ninja build generator under windows --- build_scripts/build_usd.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build_scripts/build_usd.py b/build_scripts/build_usd.py index 3cdc458a74..844af48305 100644 --- a/build_scripts/build_usd.py +++ b/build_scripts/build_usd.py @@ -232,8 +232,10 @@ def RunCMake(context, force, extraArgs = None): 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))) def PatchFile(filename, patches): """Applies patches to the specified file. patches is a list of tuples From d7cc37475058b92c83656a1bb446ff2d87285913 Mon Sep 17 00:00:00 2001 From: Paul Molodowitch Date: Sun, 5 Aug 2018 12:40:16 -0700 Subject: [PATCH 2/4] [build_usd] fix for building OpenEXR-2.2 with Ninja apparently fixed in dev branch - see: https://github.com/openexr/openexr/issues/94 https://github.com/openexr/openexr/pull/142 --- build_scripts/build_usd.py | 39 ++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/build_scripts/build_usd.py b/build_scripts/build_usd.py index 844af48305..bd7f526c35 100644 --- a/build_scripts/build_usd.py +++ b/build_scripts/build_usd.py @@ -237,13 +237,16 @@ def RunCMake(context, force, extraArgs = None): else "-j{procs}") .format(procs=context.numJobs))) -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")) @@ -648,6 +651,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") From c61a3c97433782fbcb3f33fb91fea0f49e099f10 Mon Sep 17 00:00:00 2001 From: Paul Molodowitch Date: Sun, 5 Aug 2018 19:39:46 -0700 Subject: [PATCH 3/4] [build_usd] Disable building OpenSubdiv with Ninja on windows Ninja seems to error - a bunch of warnings that are set as errors - so just use the Visual Studio builder for it for now --- build_scripts/build_usd.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/build_scripts/build_usd.py b/build_scripts/build_usd.py index bd7f526c35..58eb4602f9 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" @@ -839,7 +840,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") From e91c1ad2727876f112cb90060466ea5e74c98b55 Mon Sep 17 00:00:00 2001 From: Paul Molodowitch Date: Mon, 6 Aug 2018 04:23:42 -0700 Subject: [PATCH 4/4] [build_usd] ninja can't use --config - use CMAKE_BUILD_TYPE --- build_scripts/build_usd.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/build_scripts/build_usd.py b/build_scripts/build_usd.py index 58eb4602f9..dcb74d21ff 100644 --- a/build_scripts/build_usd.py +++ b/build_scripts/build_usd.py @@ -218,16 +218,22 @@ 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 ""), @@ -236,7 +242,8 @@ def RunCMake(context, force, extraArgs = None): .format(multiproc=("/M:{procs}" if generator and "Visual Studio" in generator else "-j{procs}") - .format(procs=context.numJobs))) + .format(procs=context.numJobs), + buildConfig=buildConfig)) def PatchFile(filename, patches, multiLineMatches=False): """Applies patches to the specified file. patches is a list of tuples