Skip to content

Commit

Permalink
Use FindMaterialX to find imported targets in pxrConfig.cmake
Browse files Browse the repository at this point in the history
Change 2230560 introduced the use of imported targets to
link against MaterialX instead of plain library paths.
These imported targets are listed as INTERFACE_LINK_LIBRARIES
for dependent libraries (like usdMtlx) in pxrConfig.cmake,
but they aren't defined in that file. This meant that
anyone using pxrConfig.cmake to configure a project to
build against USD would miss the MaterialX dependencies,
potentially leading to linker errors later on.

This was a regression; previously the paths to the MaterialX
libraries that were used in the USD build were also copied
into pxrConfig.cmake, so any projects building against USD
would link to those same libraries.

This change attempts to address the issue by calling
find_package in pxrConfig.cmake to ensure the MaterialX
targets are defined. By default this invokes the same
FindMaterialX.cmake module that was used by the USD build,
but this can be overridden by specifying MaterialX_DIR
when building the project that depends on USD.

TL;DR: a project that uses pxrConfig.cmake to build against
a MaterialX-enabled USD build should once again automatically
pick up the same MaterialX libraries that were used by that
USD build.

Fixes #1955

(Internal change: 2245213)
  • Loading branch information
sunyab authored and pixar-oss committed Aug 16, 2022
1 parent 8b130b6 commit 34d0891
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pxr/pxrConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ set(PXR_MINOR_VERSION "@PXR_MINOR_VERSION@")
set(PXR_PATCH_VERSION "@PXR_PATCH_VERSION@")
set(PXR_VERSION "@PXR_VERSION@")

# 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
# specifying a different MaterialX_DIR when running cmake.
if(@PXR_ENABLE_MATERIALX_SUPPORT@)
if (NOT DEFINED MaterialX_DIR)
set(MaterialX_DIR "@MaterialX_DIR@")
endif()
find_package(MaterialX REQUIRED)
endif()

include("${PXR_CMAKE_DIR}/cmake/pxrTargets.cmake")
set(libs "@PXR_ALL_LIBS@")
set(PXR_LIBRARIES "")
Expand Down

0 comments on commit 34d0891

Please sign in to comment.