Find TBB using TBB's CMake config

Updated the CMake build to locate TBB using TBB's CMake config
and deleted the local cmake/FindTBB.cmake module.

While the source code remains compatible with earlier versions of
TBB, updated the minimum TBB version from 4.4 to 2018 since that
is the earliest TBB release to include a CMake config.  This is
the version of TBB specified for the CY2019 VFX Reference Platform.

Tested on Windows, Linux, and macOS using TBB 2018 Update 6,
TBB 2020 Update 3, and oneTBB 2021.10.0
This commit is contained in:
David G Yu 2023-09-11 10:05:34 -07:00
parent 2f335a427b
commit dbb75b650c
7 changed files with 14 additions and 196 deletions

View File

@ -353,7 +353,7 @@ if(NOT NO_OMP)
find_package(OpenMP)
endif()
if(NOT NO_TBB)
find_package(TBB 4.0)
find_package(TBB 2018 COMPONENTS tbb)
endif()
if (NOT NO_OPENGL)
find_package(OpenGL)
@ -446,9 +446,9 @@ else()
if (NOT NO_TBB)
message(WARNING
"TBB was not found : support for TBB parallel compute kernels "
"will be disabled in Osd. If your compiler supports TBB "
"directives, please refer to the FindTBB.cmake shared module "
"in your cmake installation.")
"will be disabled in Osd. If your environment supports TBB, "
"please make sure that TBB's CMake config is available in the "
"find_package() search path.")
endif()
endif()

View File

@ -36,7 +36,7 @@ For more details about OpenSubdiv, see [Pixar Graphics Technologies](http://grap
| Lib | Min Version | Note |
| ------------------------------------------------------------------ | ----------- | ----------------------------|
| [CUDA](http://developer.nvidia.com/cuda-toolkit) | 4.0 | cuda backend |
| [TBB](https://www.threadingbuildingblocks.org) | 4.0 | TBB backend |
| [TBB](https://www.threadingbuildingblocks.org) | 2018 | TBB backend |
| [OpenCL](http://www.khronos.org/opencl) | 1.1 | CL backend |
| [DX11 SDK](http://www.microsoft.com/download/details.aspx?id=6812) | | DX backend |
| [Metal](https://developer.apple.com/metal/) | 1.2 | Metal backend |

View File

@ -1,183 +0,0 @@
#
# Copyright 2013 Pixar
#
# Licensed under the Apache License, Version 2.0 (the "Apache License")
# with the following modification; you may not use this file except in
# compliance with the Apache License and the following modification to it:
# Section 6. Trademarks. is deleted and replaced with:
#
# 6. Trademarks. This License does not grant permission to use the trade
# names, trademarks, service marks, or product names of the Licensor
# and its affiliates, except as required to comply with Section 4(c) of
# the License and to reproduce the content of the NOTICE file.
#
# You may obtain a copy of the Apache License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the Apache License with the above modification is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the Apache License for the specific
# language governing permissions and limitations under the Apache License.
#
# - Try to find Intel's Threading Building Blocks
# Once done this will define
#
# TBB_FOUND - System has OPENCL
# TBB_INCLUDE_DIR - The TBB include directory
# TBB_LIBRARIES - The libraries needed to use TBB
# Obtain include directory
if (WIN32)
find_path(TBB_INCLUDE_DIR
NAMES
tbb/tbb.h
HINTS
"${TBB_LOCATION}/include"
"$ENV{TBB_LOCATION}/include"
PATHS
"$ENV{PROGRAMFILES}/Intel/TBB/include"
/usr/include
DOC "The directory where TBB headers reside")
elseif (APPLE)
find_path(TBB_INCLUDE_DIR
NAMES
tbb/tbb.h
HINTS
"${TBB_LOCATION}/include"
"$ENV{TBB_LOCATION}/include"
PATHS
DOC "The directory where TBB headers reside")
else ()
find_path(TBB_INCLUDE_DIR
NAMES
tbb/tbb.h
HINTS
"${TBB_LOCATION}/include"
"$ENV{TBB_LOCATION}/include"
PATHS
/usr/include
/usr/local/include
/usr/openwin/share/include
/usr/openwin/include
DOC "The directory where TBB headers reside")
endif ()
set (TBB_LIB_ARCH "")
if (WIN32)
if ("${CMAKE_GENERATOR}" MATCHES "[Ww]in64" OR
"${CMAKE_GENERATOR_PLATFORM}" MATCHES "x64")
set(WINPATH intel64)
else ()
set(WINPATH ia32)
endif()
if (MSVC80)
set(WINPATH "${WINPATH}/vc8")
elseif (MSVC90)
set(WINPATH "${WINPATH}/vc9")
elseif (MSVC10)
set(WINPATH "${WINPATH}/vc10")
elseif (MSVC11)
set(WINPATH "${WINPATH}/vc11")
elseif (MSVC12)
set(WINPATH "${WINPATH}/vc12")
elseif (MSVC14)
set(WINPATH "${WINPATH}/vc14")
endif()
list(APPEND TBB_LIB_ARCH ${WINPATH})
elseif(ANDROID)
list(APPEND TBB_LIB_ARCH "android")
else()
if(CMAKE_SIZEOF_VOID_P MATCHES "8")
list(APPEND TBB_LIB_ARCH "intel64")
elseif(CMAKE_SIZEOF_VOID_P MATCHES "4")
list(APPEND TBB_LIB_ARCH "ia32")
endif()
endif()
# List library files
foreach(TBB_LIB tbb tbb_debug)
find_library(TBB_${TBB_LIB}_LIBRARY
NAMES
${TBB_LIB}
HINTS
"${TBB_LOCATION}/lib"
"${TBB_LOCATION}/bin"
"$ENV{TBB_LOCATION}/lib"
"$ENV{TBB_LOCATION}/bin"
"$ENV{PROGRAMFILES}/TBB/lib"
/usr/lib
/usr/lib/w32api
/usr/local/lib
/usr/X11R6/lib
PATH_SUFFIXES
"${TBB_LIB_ARCH}"
"${TBB_LIB_ARCH}/${TBB_COMPILER}"
"${TBB_LIB_ARCH}/gcc4.4"
"${TBB_LIB_ARCH}/gcc4.1"
DOC "Intel's Threading Building Blocks library")
if (TBB_${TBB_LIB}_LIBRARY)
list(APPEND TBB_LIBRARIES ${TBB_${TBB_LIB}_LIBRARY})
endif()
endforeach()
# Obtain version information
if(TBB_INCLUDE_DIR)
# Tease the TBB version numbers from the lib headers
function(parseVersion FILENAME VARNAME)
set(PATTERN "^#define ${VARNAME}.*$")
file(STRINGS "${TBB_INCLUDE_DIR}/${FILENAME}" TMP REGEX ${PATTERN})
string(REGEX MATCHALL "[0-9]+" TMP ${TMP})
set(${VARNAME} ${TMP} PARENT_SCOPE)
endfunction()
if(EXISTS "${TBB_INCLUDE_DIR}/tbb/tbb_stddef.h")
parseVersion(tbb/tbb_stddef.h TBB_VERSION_MAJOR)
parseVersion(tbb/tbb_stddef.h TBB_VERSION_MINOR)
endif()
if(${TBB_VERSION_MAJOR} OR ${TBB_VERSION_MINOR})
set(TBB_VERSION "${TBB_VERSION_MAJOR}.${TBB_VERSION_MINOR}")
set(TBB_VERSION_STRING "${TBB_VERSION}")
mark_as_advanced(TBB_VERSION)
endif()
endif(TBB_INCLUDE_DIR)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(TBB
REQUIRED_VARS
TBB_INCLUDE_DIR
TBB_LIBRARIES
VERSION_VAR
TBB_VERSION
)
mark_as_advanced(
TBB_INCLUDE_DIR
TBB_LIBRARIES
)

View File

@ -104,12 +104,13 @@ The following configuration arguments can be passed to the CMake command line.
-DCMAKE_INSTALL_PREFIX=[base path to install OpenSubdiv (default: Current directory)]
-DCMAKE_LIBDIR_BASE=[library directory basename (default: lib)]
-DCMAKE_PREFIX_PATH=[semicolon-separated list of directories specifying installation prefixes to be searched by the find_package() command (default: empty list)]
-DCUDA_TOOLKIT_ROOT_DIR=[path to CUDA]
-DOSD_CUDA_NVCC_FLAGS=[CUDA options, e.g. --gpu-architecture]
-DPTEX_LOCATION=[path to Ptex]
-DGLFW_LOCATION=[path to GLFW]
-DTBB_LOCATION=[path to Intel's TBB]
-DICC_LOCATION=[path to Intel's C++ Studio XE]
-DNO_LIB=1 // disable the opensubdiv libs build (caveat emptor)

View File

@ -41,9 +41,8 @@ if( OPENCL_FOUND )
endif()
if( TBB_FOUND )
include_directories("${TBB_INCLUDE_DIR}")
list(APPEND PLATFORM_LIBRARIES
"${TBB_LIBRARIES}"
TBB::tbb
)
endif()

View File

@ -49,9 +49,8 @@ if (NOT NO_LIB)
endif()
if( TBB_FOUND )
include_directories("${TBB_INCLUDE_DIR}")
list(APPEND PLATFORM_CPU_LIBRARIES
${TBB_LIBRARIES}
TBB::tbb
)
endif()

View File

@ -88,8 +88,6 @@ set(TBB_PUBLIC_HEADERS
)
if( TBB_FOUND )
include_directories("${TBB_INCLUDE_DIR}")
list(APPEND CPU_SOURCE_FILES
tbbEvaluator.cpp
tbbKernel.cpp
@ -102,7 +100,7 @@ if( TBB_FOUND )
endif()
list(APPEND PLATFORM_CPU_LIBRARIES
${TBB_LIBRARIES}
TBB::tbb
)
endif()
@ -384,6 +382,10 @@ set_target_properties(osd_cpu_obj
FOLDER "opensubdiv"
)
target_link_libraries(osd_cpu_obj
${PLATFORM_CPU_LIBRARIES}
)
if( GPU_SOURCE_FILES )
add_library(osd_gpu_obj
OBJECT