@@ -19,14 +19,28 @@ set(DNNL_CPU_RUNTIME "@DNNL_CPU_RUNTIME@")
1919set (DNNL_CPU_THREADING_RUNTIME "@DNNL_CPU_THREADING_RUNTIME@" )
2020set (DNNL_GPU_RUNTIME "@DNNL_GPU_RUNTIME@" )
2121
22+ if (DNNL_CPU_THREADING_RUNTIME STREQUAL "TBB" )
23+ # Try to find TBB using a TBB-provided CMake config file.
24+ find_package (TBB QUIET COMPONENTS tbb)
25+ # If the previous `find_package` call failed then try to
26+ # use a TBB CMake config file that is maintained by oneDNN.
27+ # The reason the previous call may fail is that TBB package is
28+ # very old and doesn't provide a CMake config file.
29+ if (NOT TBB_FOUND)
30+ message (STATUS "TBB-provided CMake config either failed or was not found. Trying to use a custom one." )
31+ # Use a custom find module for transitive dependencies
32+ set (DNNL_ORIGINAL_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} )
33+ list (INSERT CMAKE_MODULE_PATH 0 ${PACKAGE_PREFIX_DIR} /@LIB_CONFIG_INSTALL_DIR@)
34+ find_package (TBB REQUIRED COMPONENTS tbb)
35+ # Reverting the CMAKE_MODULE_PATH to its original state
36+ set (CMAKE_MODULE_PATH ${DNNL_ORIGINAL_CMAKE_MODULE_PATH} )
37+ endif ()
38+ endif ()
39+
2240# Use a custom find module for transitive dependencies
2341set (DNNL_ORIGINAL_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} )
2442list (INSERT CMAKE_MODULE_PATH 0 ${PACKAGE_PREFIX_DIR} /@LIB_CONFIG_INSTALL_DIR@)
2543
26- if (DNNL_CPU_THREADING_RUNTIME STREQUAL "TBB" )
27- find_package (TBB REQUIRED COMPONENTS tbb)
28- endif ()
29-
3044if (DNNL_GPU_RUNTIME STREQUAL "OCL" )
3145 find_package (OpenCL REQUIRED)
3246 set (DNNL_COMPILE_FLAGS "-DCL_TARGET_OPENCL_VERSION=220" )
0 commit comments