Commit: eed13c06f2d32bb7c2a9eae8bac1bb29c5cf7129 Author: Sybren A. Stüvel Date: Thu Nov 28 14:29:07 2019 +0100 Branches: temp-sybren-usd-patch-01 https://developer.blender.org/rBeed13c06f2d32bb7c2a9eae8bac1bb29c5cf7129
USD: Revamped building & bundling process - USD is now built as monolithic library, instead of 25 smaller libraries. We were linking all of them as 'whole archive' anyway, so this doesn't affect the final file size. It does, however, make life easier with respect to linking order, and handling upstream changes. - The JSON files required by USD are installed into bin/usd; they are required on every platform. - USD is patched so that it finds the aforementioned JSON files in a path relative to the running executable. When left unpatched, the only way to influence the search path for those files is to set an environment variable BEFORE Blender starts (USD uses static initialisers, so by the time the USD exporter runs, it has already unsuccessfully tried loading the JSON files, and won't re-investigate that environment variable ever again). - USD is patched to have a `PXR_BUILD_USD_TOOLS` CMake option to disable building the tools in its `bin` directory. This is sent as a pull request at https://github.com/PixarAnimationStudios/USD/pull/1048 =================================================================== M build_files/build_environment/cmake/harvest.cmake M build_files/build_environment/cmake/usd.cmake M build_files/build_environment/patches/usd.diff M build_files/cmake/Modules/FindUSD.cmake M build_files/cmake/macros.cmake M build_files/cmake/platform/platform_apple.cmake M build_files/cmake/platform/platform_win32.cmake M source/blender/usd/CMakeLists.txt M source/creator/CMakeLists.txt =================================================================== diff --git a/build_files/build_environment/cmake/harvest.cmake b/build_files/build_environment/cmake/harvest.cmake index 0df8fe39443..94e28eda6b2 100644 --- a/build_files/build_environment/cmake/harvest.cmake +++ b/build_files/build_environment/cmake/harvest.cmake @@ -198,11 +198,13 @@ harvest(xvidcore/lib ffmpeg/lib "*.a") harvest(embree/include embree/include "*.h") harvest(embree/lib embree/lib "*.a") harvest(usd/include usd/include "*.h") -harvest(usd/lib usd/lib "*") +harvest(usd/lib/usd usd/lib/usd "*") harvest(usd/plugin usd/plugin "*") -harvest(usd/pxrConfig.cmake usd/pxrConfig.cmake) -harvest(usd/cmake/pxrTargets.cmake usd/cmake/pxrTargets.cmake) -harvest(usd/cmake/pxrTargets-release.cmake usd/cmake/pxrTargets.cmake) +# Because 'make install' doesn't install the monolithic static library. +# See https://groups.google.com/d/msg/usd-interest/JgbM0RD8KnY/uHLghBA3BAAJ +install( + FILES ${BUILD_DIR}/usd/src/external_usd-build/pxr/libusd_m.a + DESTINATION ${HARVEST_TARGET}/usd/lib/) if(UNIX AND NOT APPLE) harvest(libglu/lib mesa/lib "*.so*") diff --git a/build_files/build_environment/cmake/usd.cmake b/build_files/build_environment/cmake/usd.cmake index 29893f3ce9c..c4b1d3f73b1 100644 --- a/build_files/build_environment/cmake/usd.cmake +++ b/build_files/build_environment/cmake/usd.cmake @@ -30,6 +30,8 @@ set(USD_EXTRA_ARGS -DPXR_BUILD_TESTS=OFF -DBUILD_SHARED_LIBS=OFF -DPYTHON_EXECUTABLE=${PYTHON_BINARY} + -DPXR_BUILD_MONOLITHIC=ON + -DPXR_BUILD_USD_TOOLS=OFF -DCMAKE_DEBUG_POSTFIX=_d ) @@ -48,20 +50,3 @@ add_dependencies( external_tbb external_boost ) - -if(WIN32) - if(BUILD_MODE STREQUAL Release) - ExternalProject_Add_Step(external_usd after_install - COMMAND ${CMAKE_COMMAND} -E copy_directory ${LIBDIR}/usd/ ${HARVEST_TARGET}/usd - DEPENDEES install - ) - endif() - if(BUILD_MODE STREQUAL Debug) - ExternalProject_Add_Step(external_usd after_install - COMMAND ${CMAKE_COMMAND} -E copy_directory ${LIBDIR}/usd/lib ${HARVEST_TARGET}/usd/lib - DEPENDEES install - ) - endif() - -endif() - diff --git a/build_files/build_environment/patches/usd.diff b/build_files/build_environment/patches/usd.diff index 69e6f335ea5..d5a4d286e5e 100644 --- a/build_files/build_environment/patches/usd.diff +++ b/build_files/build_environment/patches/usd.diff @@ -1,7 +1,20 @@ -diff -Naur usd.orig/cmake/defaults/Packages.cmake external_usd/cmake/defaults/Packages.cmake ---- usd.orig/cmake/defaults/Packages.cmake 2019-06-17 16:56:45 -0600 -+++ external_usd/cmake/defaults/Packages.cmake 2019-07-19 14:58:06 -0600 -@@ -64,7 +64,7 @@ +diff --git a/cmake/defaults/Options.cmake b/cmake/defaults/Options.cmake +index bcda89885..3cb541885 100644 +--- a/cmake/defaults/Options.cmake ++++ b/cmake/defaults/Options.cmake +@@ -25,6 +25,7 @@ option(PXR_STRICT_BUILD_MODE "Turn on additional warnings. Enforce all warnings + option(PXR_VALIDATE_GENERATED_CODE "Validate script generated code" OFF) + option(PXR_HEADLESS_TEST_MODE "Disallow GUI based tests, useful for running under headless CI systems." OFF) + option(PXR_BUILD_TESTS "Build tests" ON) ++option(PXR_BUILD_USD_TOOLS "Build commandline tools" ON) + option(PXR_BUILD_IMAGING "Build imaging components" ON) + option(PXR_BUILD_EMBREE_PLUGIN "Build embree imaging plugin" OFF) + option(PXR_BUILD_OPENIMAGEIO_PLUGIN "Build OpenImageIO plugin" OFF) +diff --git a/cmake/defaults/Packages.cmake b/cmake/defaults/Packages.cmake +index 9be215b36..0ce6e6fd5 100644 +--- a/cmake/defaults/Packages.cmake ++++ b/cmake/defaults/Packages.cmake +@@ -64,7 +64,7 @@ else() endif() # --TBB @@ -10,9 +23,37 @@ diff -Naur usd.orig/cmake/defaults/Packages.cmake external_usd/cmake/defaults/Pa add_definitions(${TBB_DEFINITIONS}) # --math -diff -Naur usd.orig/pxr/usd/CMakeLists.txt external_usd/pxr/usd/CMakeLists.txt ---- usd.orig/pxr/usd/CMakeLists.txt 2019-06-17 16:56:45 -0600 -+++ external_usd/pxr/usd/CMakeLists.txt 2019-07-19 15:08:15 -0600 +diff --git a/pxr/base/lib/plug/initConfig.cpp b/pxr/base/lib/plug/initConfig.cpp +index 91d01cadc..8b29aa493 100644 +--- a/pxr/base/lib/plug/initConfig.cpp ++++ b/pxr/base/lib/plug/initConfig.cpp +@@ -33,6 +33,7 @@ + #include "pxr/base/arch/symbols.h" + + #include <boost/preprocessor/stringize.hpp> ++#include <boost/dll/runtime_symbol_info.hpp> + + PXR_NAMESPACE_OPEN_SCOPE + +@@ -83,6 +84,14 @@ ARCH_CONSTRUCTOR(Plug_InitConfig, 2, void) + + sharedLibPath = TfGetPathName(sharedLibPath); + ++ // Executable location, which is relevant when using static linking. ++ boost::filesystem::path executablePath = boost::dll::program_location(); ++ if (!executablePath.empty()) { ++ // The path MUST end in a slash, or symlinks will not be treated as directory. ++ boost::filesystem::path pluginPath = executablePath.parent_path() / "usd/"; ++ result.push_back(pluginPath.string()); ++ } ++ + // Environment locations. + _AppendPathList(&result, TfGetenv(pathEnvVarName), sharedLibPath); + +diff --git a/pxr/usd/CMakeLists.txt b/pxr/usd/CMakeLists.txt +index c894cca37..df087a418 100644 +--- a/pxr/usd/CMakeLists.txt ++++ b/pxr/usd/CMakeLists.txt @@ -1,6 +1,5 @@ set(DIRS lib @@ -20,3 +61,12 @@ diff -Naur usd.orig/pxr/usd/CMakeLists.txt external_usd/pxr/usd/CMakeLists.txt plugin ) +@@ -8,3 +7,8 @@ foreach(d ${DIRS}) + add_subdirectory(${d}) + endforeach() + ++if (PXR_BUILD_USD_TOOLS) ++ add_subdirectory(bin) ++else() ++ message(STATUS "Skipping commandline tools because PXR_BUILD_USD_TOOLS=OFF") ++endif() diff --git a/build_files/cmake/Modules/FindUSD.cmake b/build_files/cmake/Modules/FindUSD.cmake index ec1a9e4a551..1fd931f7688 100644 --- a/build_files/cmake/Modules/FindUSD.cmake +++ b/build_files/cmake/Modules/FindUSD.cmake @@ -32,13 +32,6 @@ SET(_usd_SEARCH_DIRS /opt/usd ) -FIND_PATH(USD_ROOT_DIR - NAMES - pxrConfig.cmake - HINTS - ${_usd_SEARCH_DIRS} -) - FIND_PATH(USD_INCLUDE_DIR NAMES pxr/usd/usd/api.h @@ -46,40 +39,37 @@ FIND_PATH(USD_INCLUDE_DIR ${_usd_SEARCH_DIRS} PATH_SUFFIXES include + DOC "Universal Scene Description (USD) header files" ) -FIND_LIBRARY(_usd_LIBRARY +FIND_LIBRARY(USD_LIBRARY NAMES - usd + usd_m HINTS ${_usd_SEARCH_DIRS} PATH_SUFFIXES lib64 lib lib/static + DOC "Universal Scene Description (USD) monolithic library" ) +if (${USD_LIBRARY} STREQUAL "USD_LIBRARY-NOTFOUND") + message(FATAL_ERROR "USD library not found") +endif() + # handle the QUIETLY and REQUIRED arguments and set USD_FOUND to TRUE if # all listed variables are TRUE INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(USD DEFAULT_MSG USD_ROOT_DIR _usd_LIBRARY USD_INCLUDE_DIR) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(USD DEFAULT_MSG USD_LIBRARY USD_INCLUDE_DIR) IF(USD_FOUND) - get_filename_component(USD_LIBRARY_DIR ${_usd_LIBRARY} DIRECTORY) - - SET(USD_LIBRARIES) - # List copied from pxrTargets.cmake, which is created when building USD. - foreach(_usd_lib arch tf gf js trace work plug vt ar kind sdf ndr sdr pcp usd usdGeom usdVol usdLux usdShade usdRender usdHydra usdRi usdSkel usdUI usdUtils) - list(APPEND USD_LIBRARIES "${USD_LIBRARY_DIR}/lib${_usd_lib}.a") - endforeach() - list(REVERSE USD_LIBRARIES) - + get_filename_component(USD_LIBRARY_DIR ${USD_LIBRARY} DIRECTORY) SET(USD_INCLUDE_DIRS ${USD_INCLUDE_DIR}) + set(USD_LIBRARIES ${USD_LIBRARY}) ENDIF(USD_FOUND) MARK_AS_ADVANCED( USD_INCLUDE_DIR USD_LIBRARY_DIR - USD_ROOT_DIR ) -UNSET(_usd_LIBRARY) UNSET(_usd_SEARCH_DIRS) diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake index 7dff91bc2b2..7fc9baf36c9 100644 --- a/build_files/cmake/macros.cmake +++ b/build_files/cmake/macros.cmake @@ -466,6 +466,19 @@ function(setup_liblinks if(WITH_OPENVDB) target_link_libraries(${target} ${OPENVDB_LIBRARIES} ${BLOSC_LIBRARIES}) endif() + if(WITH_USD) + # Source: https://github.com/PixarAnimationStudios/USD/blob/master/BUILDING.md#linking-whole-archives + if(WIN32) + # whole-archive linking is handled in platform_win32.cmake. + target_link_libraries(${target} ${USD_LIBRARIES}) + elseif(CMAKE_COMPILER_IS_GNUCXX) + target_link_libraries(${target} -Wl,--whole-archive ${USD_LIBRARIES} -Wl,--no-whole-archive) + elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + target_link_libraries(${target} -Wl,-force_load ${USD_LIBRARIES}) + else() + message(FATAL_ERROR "Unknown how to link USD with your compiler ${CMAKE_CXX_COMPILER_ID}") + endif() + endif() if(WITH_OPENIMAGEIO) target_link_libraries(${target} ${OPENIMAGEIO_LIBRARIES}) endif() @@ -1220,10 +1233,10 @@ macro(openmp_delayload else() set(OPENMP_DLL_NAME "vcomp140") endif() - SET_TARGET_PROPERTIES(${projectname} PROPERTIES LINK_FLAGS_RELEASE "/DELAYLOAD:${OPENMP_DLL_NAME}.dll delayimp.lib") - SET_TARGET_PROPERTIES(${projectname} PROPERTIES LINK_FLAGS_DEBUG "/DELAYLOAD:${OPENMP_DLL_NAME}d.dll delayimp.lib") - SET_TARGET_PROPERTIES(${projectname} PROPERTIES LINK_FLAGS_RELWITHDEBINFO "/DELAYLOAD:${OPENMP_DLL_NAME}.dll delayimp.lib") - SET_TARGET_PROPERTIES(${projectname} PROPERTIES LINK_FLAGS_MINSIZEREL "/DELAYLOAD:${OPENMP_DLL_NAME}.dll delayimp.lib") + set_property(TARGET ${projectname} APPEND_STRING PROPERTY LINK_FLAGS_RELEASE " /DELAYLOAD:${OPENMP_DLL_NAME}.dll delayimp.lib") + set_property(TARGET ${projectname} APPEND_STRING PROPERTY LINK_FLAGS_DEBUG " /DELAYLOAD:${OPENMP_DLL_NAME}d.dll delayimp.lib") + set_property(TARGET ${projectname} APPEND_STRING PROPERTY LINK_FLAGS_RELWITHDEBINFO " /DELAYLOAD:${OPENMP_DLL_NAME}.dll delayimp.lib") + set_property(TARGET ${projectname} APPEND_STRING PROPERTY LINK_FLAGS_MINSIZEREL " /DELAYLOAD:${OPENMP_DLL_NAME}.dll delayimp.lib") endif() endif() endmacro() diff --git a/build_files/cmake/platform/platform_apple.cmake b/build_files/cmake/platform/platform_apple.cmake index 578ad143d59..d99d7ec3c0c 100644 --- a/build_files/cmake/platform/platform_apple.cmake +++ b/build_files/cmake/platform/platform_apple.cmake @@ -56,6 +56,11 @@ if(WITH_ALEMBIC) set(ALEMBIC_FOUND ON) @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs