Skip to content

Commit d60da5e

Browse files
sunyabpixar-oss
authored andcommitted
build: Fix issue with missing TBB::tbb target in pxrConfig.cmake
Change 2369739 updated USD to specify library dependencies on TBB with the more modern TBB::tbb target. This caused the targets in USD's package config file to specify TBB::tbb as an interface link library instead of the absolute path to the .so/.dll. This caused problems when trying to link other cmake-based projects to the USD package for USD builds using legacy TBB. In this case, the TBB::tbb target (typically) is created by USD internally and isn't available to clients, which caused "target was not found" errors. This fix recreates the TBB::tbb target in pxrConfig.cmake to ensure its available in the above case. This should yield the same behavior as before the change mentioned above. (Internal change: 2372031)
1 parent 43fd404 commit d60da5e

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

pxr/CMakeLists.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,40 @@ pxr_core_epilogue()
2323

2424
export(PACKAGE pxr)
2525

26+
# XXX:
27+
# Libraries specify the TBB::tbb target to link against TBB. This target
28+
# is either imported from the package config file that is installed with
29+
# oneTBB (and is optionally installed with TBB), or it is created by the
30+
# USD build as part of the FindTBB cmake module.
31+
#
32+
# The TBB::tbb target must be available when a client builds against USD
33+
# using its pxrConfig.cmake package config file. In the former case above,
34+
# clients can use the same package config file from TBB they used when
35+
# building USD itself. But in the latter case, USD itself needs to export
36+
# the TBB::tbb target it created.
37+
#
38+
# Typically a target would be exported using `export(TARGETS ...)` but
39+
# this doesn't work for TBB::tbb because it's an imported target. So we
40+
# manually set up this target in pxrConfig.cmake and copy over the
41+
# relevant properties that are set up in FindTBB.cmake. These properties
42+
# specify the TBB library that USD was actually built against and don't
43+
# include other configurations.
44+
#
45+
# This can all go away when support for TBB is dropped in favor of oneTBB
46+
# and we solely rely on its package config file.
47+
foreach(property IN ITEMS
48+
INTERFACE_INCLUDE_DIRECTORIES
49+
INTERFACE_COMPILE_DEFINITIONS
50+
INTERFACE_LINK_DIRECTORIES
51+
IMPORTED_IMPLIB
52+
IMPORTED_LOCATION)
53+
54+
get_target_property(value TBB::tbb ${property})
55+
if (value)
56+
set(tbb_${property} "${value}")
57+
endif()
58+
endforeach()
59+
2660
configure_file(pxrConfig.cmake.in
2761
"${PROJECT_BINARY_DIR}/pxrConfig.cmake" @ONLY)
2862
install(FILES

pxr/pxrConfig.cmake.in

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ if (NOT DEFINED PXR_FIND_TBB_IN_CONFIG)
5454
endif()
5555
if (PXR_FIND_TBB_IN_CONFIG)
5656
find_dependency(TBB @TBB_VERSION@ CONFIG)
57+
else()
58+
add_library(TBB::tbb SHARED IMPORTED)
59+
60+
macro(_add_property name value)
61+
if (NOT "${value}" STREQUAL "")
62+
set_target_properties(TBB::tbb PROPERTIES ${name} "${value}")
63+
endif()
64+
endmacro()
65+
66+
_add_property(INTERFACE_INCLUDE_DIRECTORIES "@tbb_INTERFACE_INCLUDE_DIRECTORIES@")
67+
_add_property(INTERFACE_COMPILE_DEFINITIONS "@tbb_INTERFACE_COMPILE_DEFINITIONS@")
68+
_add_property(INTERFACE_LINK_DIRECTORIES "@tbb_INTERFACE_LINK_DIRECTORIES@")
69+
_add_property(IMPORTED_IMPLIB "@tbb_IMPORTED_IMPLIB@")
70+
_add_property(IMPORTED_LOCATION "@tbb_IMPORTED_LOCATION@")
5771
endif()
5872

5973
if (NOT DEFINED PXR_FIND_OPENSUBDIV_IN_CONFIG)

0 commit comments

Comments
 (0)