diff --git a/cmake/defaults/Packages.cmake b/cmake/defaults/Packages.cmake index 5746dfc912..683286c153 100644 --- a/cmake/defaults/Packages.cmake +++ b/cmake/defaults/Packages.cmake @@ -139,7 +139,16 @@ endif() # --TBB -find_package(TBB REQUIRED COMPONENTS tbb) +find_package(TBB CONFIG) +if(TBB_DIR) + # Found in CONFIG mode. + set(TBB_tbb_LIBRARY TBB::tbb) + set(PXR_FIND_TBB_IN_CONFIG ON) +else() + find_package(TBB REQUIRED COMPONENTS tbb) + set(PXR_FIND_TBB_IN_CONFIG OFF) +endif() + add_definitions(${TBB_DEFINITIONS}) # --math @@ -251,7 +260,29 @@ if (PXR_BUILD_IMAGING) endif() # --Opensubdiv set(OPENSUBDIV_USE_GPU ${PXR_BUILD_GPU_SUPPORT}) - find_package(OpenSubdiv 3 REQUIRED) + find_package(OpenSubdiv 3 CONFIG) + if(OpenSubdiv_DIR) + # Found in CONFIG mode. + # First check the shared, then the static library, just like find_library() in FindOpenSubdiv.cmake. + foreach(postfix "" "_static") + if(NOT TARGET OpenSubdiv::osdCPU${postfix}) + continue() + endif() + set(OPENSUBDIV_LIBRARIES OpenSubdiv::osdCPU${postfix}) + if(OPENSUBDIV_USE_GPU) + list(APPEND OPENSUBDIV_LIBRARIES OpenSubdiv::osdGPU${postfix}) + endif() + break() + endforeach() + endif() + if(OPENSUBDIV_LIBRARIES) + list(GET OPENSUBDIV_LIBRARIES 0 OPENSUBDIV_OSDCPU_LIBRARY) + set(PXR_FIND_OPENSUBDIV_IN_CONFIG ON) + else() + # Try again with the find-module. + find_package(OpenSubdiv 3 REQUIRED) + set(PXR_FIND_OPENSUBDIV_IN_CONFIG OFF) + endif() # --Ptex if (PXR_ENABLE_PTEX_SUPPORT) find_package(PTex REQUIRED) diff --git a/pxr/pxrConfig.cmake.in b/pxr/pxrConfig.cmake.in index b26f1ea31b..7a9798feec 100644 --- a/pxr/pxrConfig.cmake.in +++ b/pxr/pxrConfig.cmake.in @@ -47,6 +47,18 @@ if(@PXR_ENABLE_PYTHON_SUPPORT@) endif() endif() +include(CMakeFindDependencyMacro) + +set(PXR_FIND_TBB_IN_CONFIG "@PXR_FIND_TBB_IN_CONFIG@") +if(PXR_FIND_TBB_IN_CONFIG) + find_dependency(TBB @TBB_VERSION@ CONFIG) +endif() + +set(PXR_FIND_OPENSUBDIV_IN_CONFIG "@PXR_FIND_OPENSUBDIV_IN_CONFIG@") +if(PXR_FIND_OPENSUBDIV_IN_CONFIG) + find_dependency(OpenSubdiv @OpenSubdiv_VERSION@ CONFIG) +endif() + # If MaterialX support was enabled for this USD build, try to find the # associated import targets by invoking the same FindMaterialX.cmake # module that was used for that build. This can be overridden by