Skip to content

Commit ebf3310

Browse files
theblackunknownmeshula
authored andcommitted
Modernize TBB CMake setup.
Adds additional targets for TBB components. Updates various CMakeLists.txt files to use TBB::tbb component Removes explicit TBB dependencies from CMakeLists.txt files for modules for which it is not necessary Updates pch headers for modules which do not utilize TBB Closes PixarAnimationStudios#3207 (Internal change: 2369739) (Internal change: 2369797)
1 parent b0a4680 commit ebf3310

File tree

46 files changed

+142
-318
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+142
-318
lines changed

cmake/defaults/Packages.cmake

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,13 @@ if(WIN32)
106106
endif()
107107

108108
# --TBB
109-
find_package(TBB CONFIG)
110-
if(TBB_DIR)
111-
# Found in CONFIG mode.
112-
set(TBB_tbb_LIBRARY TBB::tbb)
109+
find_package(TBB CONFIG COMPONENTS tbb)
110+
if(TBB_FOUND)
113111
set(PXR_FIND_TBB_IN_CONFIG ON)
114112
else()
115113
find_package(TBB REQUIRED COMPONENTS tbb)
116114
set(PXR_FIND_TBB_IN_CONFIG OFF)
117115
endif()
118-
add_definitions(${TBB_DEFINITIONS})
119116

120117
# --math
121118
if(WIN32)

cmake/modules/FindTBB.cmake

Lines changed: 119 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -137,21 +137,27 @@ if(NOT TBB_FOUND)
137137
set(TBB_ARCHITECTURE "ia32")
138138
endif()
139139

140-
# Set the TBB search library path search suffix based on the version of VC
140+
# Set the TBB search library/runtime path search suffix based on the version of VC
141141
if(WINDOWS_STORE)
142142
set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc11_ui")
143+
set(TBB_RUNTIME_PATH_SUFFIX "bin/${TBB_ARCHITECTURE}/vc11_ui")
143144
elseif(MSVC14)
144145
set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc14")
146+
set(TBB_RUNTIME_PATH_SUFFIX "bin/${TBB_ARCHITECTURE}/vc14")
145147
elseif(MSVC12)
146148
set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc12")
149+
set(TBB_RUNTIME_PATH_SUFFIX "bin/${TBB_ARCHITECTURE}/vc12")
147150
elseif(MSVC11)
148151
set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc11")
152+
set(TBB_RUNTIME_PATH_SUFFIX "bin/${TBB_ARCHITECTURE}/vc11")
149153
elseif(MSVC10)
150154
set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc10")
155+
set(TBB_RUNTIME_PATH_SUFFIX "bin/${TBB_ARCHITECTURE}/vc10")
151156
endif()
152157

153-
# Add the library path search suffix for the VC independent version of TBB
158+
# Add the library/runtime path search suffix for the VC independent version of TBB
154159
list(APPEND TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc_mt")
160+
list(APPEND TBB_RUNTIME_PATH_SUFFIX "bin/${TBB_ARCHITECTURE}/vc_mt")
155161

156162
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
157163
# OS X
@@ -176,12 +182,13 @@ if(NOT TBB_FOUND)
176182
endif()
177183
endif()
178184

179-
# The above TBB_LIB_PATH_SUFFIX is based on where Intel puts the libraries
185+
# The above TBB_LIB_PATH_SUFFIX/TBB_RUNTIME_PATH_SUFFIX is based on where Intel puts the libraries
180186
# in the package of prebuilt libraries it distributes. However, users may
181-
# install these shared libraries into the more conventional "lib" directory
187+
# install these shared libraries into the more conventional "lib"/"bin" directory
182188
# (especially when building from source), so we add that as an additional
183189
# location to search.
184190
list(APPEND TBB_LIB_PATH_SUFFIX "lib")
191+
list(APPEND TBB_RUNTIME_PATH_SUFFIX "bin")
185192

186193
##################################
187194
# Find the TBB include dir
@@ -224,13 +231,13 @@ if(NOT TBB_FOUND)
224231
endif()
225232

226233
if(TBB_VERSION VERSION_LESS 4.3)
227-
set(TBB_SEARCH_COMPOMPONENTS tbb_preview tbbmalloc tbb)
234+
set(TBB_SEARCH_COMPONENTS tbb_preview tbbmalloc tbb)
228235
else()
229-
set(TBB_SEARCH_COMPOMPONENTS tbb_preview tbbmalloc_proxy tbbmalloc tbb)
236+
set(TBB_SEARCH_COMPONENTS tbb_preview tbbmalloc_proxy tbbmalloc tbb)
230237
endif()
231238

232239
# Find each component
233-
foreach(_comp ${TBB_SEARCH_COMPOMPONENTS})
240+
foreach(_comp ${TBB_SEARCH_COMPONENTS})
234241
if(";${TBB_FIND_COMPONENTS};tbb" MATCHES ";${_comp};")
235242

236243
if(${_comp} STREQUAL tbb)
@@ -250,6 +257,32 @@ if(NOT TBB_FOUND)
250257
PATHS ${TBB_DEFAULT_SEARCH_DIR} ENV LIBRARY_PATH
251258
PATH_SUFFIXES ${TBB_LIB_PATH_SUFFIX})
252259

260+
# On Windows platforms also looks for .dll binaries.
261+
# If we find some, assume TBB is built as a shared library with the .lib/.dll pair,
262+
# otherwise assume it is built as a static library
263+
set(TBB_${_comp}_TARGET_TYPE SHARED)
264+
if(WIN32)
265+
find_file(TBB_${_comp}_SHARED_LIBRARY_RELEASE
266+
NAMES ${CMAKE_SHARED_LIBRARY_PREFIX}${_lib_name}${CMAKE_SHARED_LIBRARY_SUFFIX}
267+
HINTS ${TBB_LIBRARY} ${TBB_SEARCH_DIR}
268+
PATHS ${TBB_DEFAULT_SEARCH_DIR} ENV LIBRARY_PATH
269+
PATH_SUFFIXES ${TBB_RUNTIME_PATH_SUFFIX})
270+
271+
find_file(TBB_${_comp}_SHARED_LIBRARY_DEBUG
272+
NAMES ${CMAKE_SHARED_LIBRARY_PREFIX}${_lib_name}_debug${CMAKE_SHARED_LIBRARY_SUFFIX}
273+
HINTS ${TBB_LIBRARY} ${TBB_SEARCH_DIR}
274+
PATHS ${TBB_DEFAULT_SEARCH_DIR} ENV LIBRARY_PATH
275+
PATH_SUFFIXES ${TBB_RUNTIME_PATH_SUFFIX})
276+
277+
if(TBB_${_comp}_LIBRARY_RELEASE AND TBB_${_comp}_SHARED_LIBRARY_RELEASE)
278+
set(TBB_${_comp}_TARGET_TYPE SHARED)
279+
elseif(TBB_${_comp}_LIBRARY_DEBUG AND TBB_${_comp}_SHARED_LIBRARY_DEBUG)
280+
set(TBB_${_comp}_TARGET_TYPE SHARED)
281+
else()
282+
set(TBB_${_comp}_TARGET_TYPE STATIC)
283+
endif()
284+
endif()
285+
253286
if(TBB_${_comp}_LIBRARY_DEBUG)
254287
list(APPEND TBB_LIBRARIES_DEBUG "${TBB_${_comp}_LIBRARY_DEBUG}")
255288
endif()
@@ -270,6 +303,7 @@ if(NOT TBB_FOUND)
270303
mark_as_advanced(TBB_${_comp}_LIBRARY_RELEASE)
271304
mark_as_advanced(TBB_${_comp}_LIBRARY_DEBUG)
272305
mark_as_advanced(TBB_${_comp}_LIBRARY)
306+
mark_as_advanced(TBB_${_comp}_TARGET_TYPE)
273307

274308
endif()
275309
endforeach()
@@ -302,26 +336,83 @@ if(NOT TBB_FOUND)
302336
##################################
303337

304338
if(NOT CMAKE_VERSION VERSION_LESS 3.0 AND TBB_FOUND)
305-
add_library(TBB::tbb SHARED IMPORTED)
306-
set_target_properties(TBB::tbb PROPERTIES
307-
INTERFACE_INCLUDE_DIRECTORIES ${TBB_INCLUDE_DIRS}
308-
IMPORTED_LOCATION ${TBB_LIBRARIES})
309-
if(TBB_LIBRARIES_RELEASE AND TBB_LIBRARIES_DEBUG)
310-
set_target_properties(TBB::tbb PROPERTIES
311-
INTERFACE_COMPILE_DEFINITIONS "$<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:TBB_USE_DEBUG=1>"
312-
IMPORTED_LOCATION_DEBUG ${TBB_LIBRARIES_DEBUG}
313-
IMPORTED_LOCATION_RELWITHDEBINFO ${TBB_LIBRARIES_DEBUG}
314-
IMPORTED_LOCATION_RELEASE ${TBB_LIBRARIES_RELEASE}
315-
IMPORTED_LOCATION_MINSIZEREL ${TBB_LIBRARIES_RELEASE}
316-
)
317-
elseif(TBB_LIBRARIES_RELEASE)
318-
set_target_properties(TBB::tbb PROPERTIES IMPORTED_LOCATION ${TBB_LIBRARIES_RELEASE})
319-
else()
320-
set_target_properties(TBB::tbb PROPERTIES
321-
INTERFACE_COMPILE_DEFINITIONS "${TBB_DEFINITIONS_DEBUG}"
322-
IMPORTED_LOCATION ${TBB_LIBRARIES_DEBUG}
323-
)
324-
endif()
339+
foreach(_comp ${TBB_SEARCH_COMPONENTS})
340+
if(";${TBB_FIND_COMPONENTS};tbb" MATCHES ";${_comp};")
341+
342+
add_library(TBB::${_comp} ${TBB_${_comp}_TARGET_TYPE} IMPORTED)
343+
set_property(TARGET TBB::${_comp} APPEND PROPERTY
344+
INTERFACE_INCLUDE_DIRECTORIES ${TBB_INCLUDE_DIRS}
345+
)
346+
347+
set(TBB_LINK_DIR_DEBUG)
348+
set(TBB_LINK_DIR_RELEASE)
349+
350+
if(WIN32 AND TBB_${_comp}_SHARED_LIBRARY_${TBB_BUILD_TYPE})
351+
set_target_properties(TBB::${_comp} PROPERTIES
352+
IMPORTED_IMPLIB ${TBB_${_comp}_LIBRARY_${TBB_BUILD_TYPE}}
353+
IMPORTED_LOCATION ${TBB_${_comp}_SHARED_LIBRARY_${TBB_BUILD_TYPE}})
354+
else()
355+
set_target_properties(TBB::${_comp} PROPERTIES
356+
IMPORTED_LOCATION ${TBB_${_comp}_LIBRARY_${TBB_BUILD_TYPE}})
357+
endif()
358+
359+
if(TBB_${_comp}_LIBRARY_DEBUG)
360+
set_property(TARGET TBB::${_comp} APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
361+
set_property(TARGET TBB::${_comp} APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS "$<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:TBB_USE_DEBUG=1>")
362+
cmake_path(GET TBB_${_comp}_LIBRARY_DEBUG PARENT_PATH TBB_LINK_DIR_DEBUG)
363+
364+
if(WIN32 AND TBB_${_comp}_SHARED_LIBRARY_DEBUG)
365+
set_target_properties(TBB::${_comp} PROPERTIES
366+
IMPORTED_IMPLIB_DEBUG ${TBB_${_comp}_LIBRARY_DEBUG}
367+
IMPORTED_IMPLIB_RELWITHDEBINFO ${TBB_${_comp}_LIBRARY_DEBUG}
368+
369+
IMPORTED_LOCATION_DEBUG ${TBB_${_comp}_SHARED_LIBRARY_DEBUG}
370+
IMPORTED_LOCATION_RELWITHDEBINFO ${TBB_${_comp}_SHARED_LIBRARY_DEBUG})
371+
else()
372+
set_target_properties(TBB::${_comp} PROPERTIES
373+
IMPORTED_LOCATION_DEBUG ${TBB_${_comp}_LIBRARY_DEBUG}
374+
IMPORTED_LOCATION_RELWITHDEBINFO ${TBB_${_comp}_LIBRARY_DEBUG})
375+
endif()
376+
endif()
377+
378+
if(TBB_${_comp}_LIBRARY_RELEASE)
379+
set_property(TARGET TBB::${_comp} APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
380+
cmake_path(GET TBB_${_comp}_LIBRARY_RELEASE PARENT_PATH TBB_LINK_DIR_RELEASE)
381+
382+
if(WIN32 AND TBB_${_comp}_SHARED_LIBRARY_RELEASE)
383+
set_target_properties(TBB::${_comp} PROPERTIES
384+
IMPORTED_IMPLIB_RELEASE ${TBB_${_comp}_LIBRARY_RELEASE}
385+
IMPORTED_IMPLIB_MINSIZEREL ${TBB_${_comp}_LIBRARY_RELEASE}
386+
387+
IMPORTED_LOCATION_RELEASE ${TBB_${_comp}_SHARED_LIBRARY_RELEASE}
388+
IMPORTED_LOCATION_MINSIZEREL ${TBB_${_comp}_SHARED_LIBRARY_RELEASE})
389+
else()
390+
set_target_properties(TBB::${_comp} PROPERTIES
391+
IMPORTED_LOCATION_RELEASE ${TBB_${_comp}_LIBRARY_RELEASE}
392+
IMPORTED_LOCATION_MINSIZEREL ${TBB_${_comp}_LIBRARY_RELEASE})
393+
endif()
394+
endif()
395+
396+
endif()
397+
398+
# Set the linker directory path for the target. This is specifically
399+
# used on linux so that the linker can find the appropriate
400+
# numbered shared object
401+
if (TBB_LINK_DIR_DEBUG AND TBB_LINK_DIR_RELEASE)
402+
set(TBB_LINK_DIRS "$<$<CONFIG:Debug>:${TBB_LINK_DIR_DEBUG}>;$<$<CONFIG:Release>:${TBB_LINK_DIR_RELEASE}>")
403+
elseif(TBB_LINK_DIRS_DEBUG)
404+
set(TBB_LINK_DIRS ${TBB_LINK_DIR_DEBUG})
405+
elseif(TBB_LINK_DIR_RELEASE)
406+
set(TBB_LINK_DIRS ${TBB_LINK_DIR_RELEASE})
407+
endif()
408+
if (TBB_LINK_DIRS)
409+
set_property(TARGET TBB::${_comp} APPEND PROPERTY INTERFACE_LINK_DIRECTORIES ${TBB_LINK_DIRS})
410+
endif()
411+
412+
unset(TBB_LINK_DIR_DEBUG)
413+
unset(TBB_LINK_DIR_RELEASE)
414+
unset(TBB_LINK_DIRS)
415+
endforeach()
325416
endif()
326417

327418
mark_as_advanced(TBB_INCLUDE_DIRS TBB_LIBRARIES)
@@ -330,5 +421,4 @@ if(NOT TBB_FOUND)
330421
unset(TBB_BUILD_TYPE)
331422
unset(TBB_LIB_PATH_SUFFIX)
332423
unset(TBB_DEFAULT_SEARCH_DIR)
333-
334-
endif()
424+
endif()

pxr/base/plug/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ pxr_library(plug
88
js
99
trace
1010
work
11-
${TBB_tbb_LIBRARY}
12-
13-
INCLUDE_DIRS
14-
${TBB_INCLUDE_DIRS}
11+
TBB::tbb
1512

1613
PUBLIC_CLASSES
1714
interfaceFactory

pxr/base/tf/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,7 @@ pxr_library(tf
114114
LIBRARIES
115115
arch
116116
${WINLIBS}
117-
${TBB_tbb_LIBRARY}
118-
119-
INCLUDE_DIRS
120-
${TBB_INCLUDE_DIRS}
117+
TBB::tbb
121118

122119
PUBLIC_CLASSES
123120
anyUniquePtr

pxr/base/trace/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ pxr_library(trace
66
arch
77
js
88
tf
9-
${TBB_tbb_LIBRARY}
10-
11-
INCLUDE_DIRS
12-
${TBB_INCLUDE_DIRS}
9+
TBB::tbb
1310

1411
PUBLIC_CLASSES
1512
aggregateTree

pxr/base/vt/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ pxr_library(vt
77
tf
88
gf
99
trace
10-
${TBB_tbb_LIBRARY}
11-
12-
INCLUDE_DIRS
13-
${TBB_INCLUDE_DIRS}
10+
TBB::tbb
1411

1512
PUBLIC_CLASSES
1613
array

pxr/base/work/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ pxr_library(work
55
LIBRARIES
66
tf
77
trace
8-
${TBB_tbb_LIBRARY}
9-
10-
INCLUDE_DIRS
11-
${TBB_INCLUDE_DIRS}
8+
TBB::tbb
129

1310
PUBLIC_CLASSES
1411
detachedTask

pxr/imaging/hd/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ pxr_library(hd
1515
hf
1616
pxOsd
1717
sdr
18-
${TBB_tbb_LIBRARY}
19-
20-
INCLUDE_DIRS
21-
${TBB_INCLUDE_DIRS}
18+
TBB::tbb
2219

2320
PUBLIC_CLASSES
2421
aov

pxr/imaging/hdGp/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ pxr_library(hdGp
77
LIBRARIES
88
hd
99
hf
10-
${TBB_tbb_LIBRARY}
11-
12-
INCLUDE_DIRS
13-
${TBB_INCLUDE_DIRS}
10+
TBB::tbb
1411

1512
PUBLIC_CLASSES
1613
generativeProcedural

pxr/imaging/hdSt/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,11 @@ pxr_library(hdSt
4646
sdr
4747
tf
4848
trace
49-
${TBB_tbb_LIBRARY}
49+
TBB::tbb
5050
${OPENSUBDIV_LIBRARIES}
5151
${optionalLibs}
5252

5353
INCLUDE_DIRS
54-
${TBB_INCLUDE_DIRS}
5554
${OPENSUBDIV_INCLUDE_DIR}
5655
${optionalIncludeDirs}
5756

0 commit comments

Comments
 (0)