Skip to content

Commit 1db4a35

Browse files
theblackunknownMACHIZAUD Andréa
authored andcommitted
Modernize TBB CMake setup by exclusively relying on CMake namespace targets
Using CMake namespace target is the modern approach, it forward definitions, include directories and link libraries transitively to consumers. And one is already setup by the `FindTBB.cmake` module. As the main CMakeLists.txt already requires CMake 3.14 this should already be available to all CMake clients. - Additionally try to resolve TBB Config package before trying the module one. - Add missing linkage to TBB to targets which use it directly - Remove extra linkage to TBB to targets which dot not use it directly - Add missing call to `find_dependency(TBB ..)` to resolve indirect dependencies - Fix typo in FindTBB - Implement heuristic to resolve import/shared libraries on Windows
1 parent 1785543 commit 1db4a35

File tree

47 files changed

+121
-319
lines changed

Some content is hidden

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

47 files changed

+121
-319
lines changed

cmake/defaults/Packages.cmake

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,10 @@ endif()
102102

103103

104104
# --TBB
105-
find_package(TBB CONFIG)
106-
if(TBB_DIR)
107-
# Found in CONFIG mode.
108-
set(TBB_tbb_LIBRARY TBB::tbb)
109-
set(PXR_FIND_TBB_IN_CONFIG ON)
110-
else()
105+
find_package(TBB CONFIG COMPONENTS tbb)
106+
if(NOT TBB_FOUND)
111107
find_package(TBB REQUIRED COMPONENTS tbb)
112-
set(PXR_FIND_TBB_IN_CONFIG OFF)
113108
endif()
114-
add_definitions(${TBB_DEFINITIONS})
115109

116110
# --math
117111
if(WIN32)

cmake/modules/FindTBB.cmake

Lines changed: 96 additions & 27 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,61 @@ 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+
340+
foreach(_comp ${TBB_SEARCH_COMPONENTS})
341+
if(";${TBB_FIND_COMPONENTS};tbb" MATCHES ";${_comp};")
342+
343+
add_library(TBB::${_comp} ${TBB_${_comp}_TARGET_TYPE} IMPORTED)
344+
set_property(TARGET TBB::${_comp} APPEND PROPERTY
345+
INTERFACE_INCLUDE_DIRECTORIES ${TBB_INCLUDE_DIRS}
346+
)
347+
348+
if(WIN32 AND TBB_${_comp}_SHARED_LIBRARY_${TBB_BUILD_TYPE})
349+
set_target_properties(TBB::${_comp} PROPERTIES
350+
IMPORTED_IMPLIB ${TBB_${_comp}_LIBRARY_${TBB_BUILD_TYPE}}
351+
IMPORTED_LOCATION ${TBB_${_comp}_SHARED_LIBRARY_${TBB_BUILD_TYPE}})
352+
else()
353+
set_target_properties(TBB::${_comp} PROPERTIES
354+
IMPORTED_LOCATION ${TBB_${_comp}_LIBRARY_${TBB_BUILD_TYPE}})
355+
endif()
356+
357+
if(TBB_${_comp}_LIBRARY_DEBUG)
358+
set_property(TARGET TBB::${_comp} APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
359+
set_property(TARGET TBB::${_comp} APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS "$<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:TBB_USE_DEBUG=1>")
360+
361+
if(WIN32 AND TBB_${_comp}_SHARED_LIBRARY_DEBUG)
362+
set_target_properties(TBB::${_comp} PROPERTIES
363+
IMPORTED_IMPLIB_DEBUG ${TBB_${_comp}_LIBRARY_DEBUG}
364+
IMPORTED_IMPLIB_RELWITHDEBINFO ${TBB_${_comp}_LIBRARY_DEBUG}
365+
366+
IMPORTED_LOCATION_DEBUG ${TBB_${_comp}_SHARED_LIBRARY_DEBUG}
367+
IMPORTED_LOCATION_RELWITHDEBINFO ${TBB_${_comp}_SHARED_LIBRARY_DEBUG})
368+
else()
369+
set_target_properties(TBB::${_comp} PROPERTIES
370+
IMPORTED_LOCATION_DEBUG ${TBB_${_comp}_LIBRARY_DEBUG}
371+
IMPORTED_LOCATION_RELWITHDEBINFO ${TBB_${_comp}_LIBRARY_DEBUG})
372+
endif()
373+
endif()
374+
375+
if(TBB_${_comp}_LIBRARY_RELEASE)
376+
set_property(TARGET TBB::${_comp} APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
377+
378+
if(WIN32 AND TBB_${_comp}_SHARED_LIBRARY_RELEASE)
379+
set_target_properties(TBB::${_comp} PROPERTIES
380+
IMPORTED_IMPLIB_RELEASE ${TBB_${_comp}_LIBRARY_RELEASE}
381+
IMPORTED_IMPLIB_MINSIZEREL ${TBB_${_comp}_LIBRARY_RELEASE}
382+
383+
IMPORTED_LOCATION_RELEASE ${TBB_${_comp}_SHARED_LIBRARY_RELEASE}
384+
IMPORTED_LOCATION_MINSIZEREL ${TBB_${_comp}_SHARED_LIBRARY_RELEASE})
385+
else()
386+
set_target_properties(TBB::${_comp} PROPERTIES
387+
IMPORTED_LOCATION_RELEASE ${TBB_${_comp}_LIBRARY_RELEASE}
388+
IMPORTED_LOCATION_MINSIZEREL ${TBB_${_comp}_LIBRARY_RELEASE})
389+
endif()
390+
endif()
391+
392+
endif()
393+
endforeach()
325394
endif()
326395

327396
mark_as_advanced(TBB_INCLUDE_DIRS TBB_LIBRARIES)

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)