1 # Search TBB library (4.1 - 4.4, 2017)
3 # Own TBB (3rdparty/tbb):
4 # - set cmake option BUILD_TBB to ON
6 # External TBB (from system):
7 # - Fedora: install 'tbb-devel' package
8 # - Ubuntu: install 'libtbb-dev' package
10 # External TBB (from official site):
12 # - in tbbvars.sh replace 'SUBSTITUTE_INSTALL_DIR_HERE' with absolute path to TBB dir
13 # - in terminal run 'source tbbvars.sh intel64 linux' ('source tbbvars.sh' in OSX)
15 # - in terminal run 'tbbvars.bat intel64 vs2015'
18 # - HAVE_TBB set to TRUE
19 # - "tbb" target exists and added to OPENCV_LINKER_LIBS
21 function(ocv_tbb_cmake_guess _found)
22 find_package(TBB QUIET COMPONENTS tbb PATHS "$ENV{TBBROOT}/cmake")
24 if(NOT TARGET TBB::tbb)
25 message(WARNING "No TBB::tbb target found!")
28 get_target_property(_lib TBB::tbb IMPORTED_LOCATION_RELEASE)
29 message(STATUS "Found TBB (cmake): ${_lib}")
30 get_target_property(_inc TBB::tbb INTERFACE_INCLUDE_DIRECTORIES)
31 ocv_tbb_read_version("${_inc}")
32 add_library(tbb INTERFACE)
33 target_link_libraries(tbb INTERFACE TBB::tbb)
34 set(${_found} TRUE PARENT_SCOPE)
38 function(ocv_tbb_env_verify)
39 if (NOT "$ENV{TBBROOT}" STREQUAL "")
40 # check that library and include dir are inside TBBROOT location
41 get_filename_component(_root "$ENV{TBBROOT}" ABSOLUTE)
42 get_filename_component(_lib "${TBB_ENV_LIB}" ABSOLUTE)
43 get_filename_component(_inc "${TBB_ENV_INCLUDE}" ABSOLUTE)
44 string(FIND "${_lib}" "${_root}" _lib_pos)
45 string(FIND "${_inc}" "${_root}" _inc_pos)
46 if (NOT (_lib_pos EQUAL 0 AND _inc_pos EQUAL 0))
48 "Possible issue with TBB detection - TBBROOT is set, "
49 "but library/include path is not inside it:\n "
50 "TBBROOT: $ENV{TBBROOT}\n "
51 "(absolute): ${_root}\n "
58 function(ocv_tbb_env_guess _found)
59 find_path(TBB_ENV_INCLUDE NAMES "tbb/tbb.h" PATHS ENV CPATH NO_DEFAULT_PATH)
60 find_path(TBB_ENV_INCLUDE NAMES "tbb/tbb.h")
61 find_library(TBB_ENV_LIB NAMES "tbb" PATHS ENV LIBRARY_PATH NO_DEFAULT_PATH)
62 find_library(TBB_ENV_LIB NAMES "tbb")
63 find_library(TBB_ENV_LIB_DEBUG NAMES "tbb_debug" PATHS ENV LIBRARY_PATH NO_DEFAULT_PATH)
64 find_library(TBB_ENV_LIB_DEBUG NAMES "tbb_debug")
65 if (TBB_ENV_INCLUDE AND (TBB_ENV_LIB OR TBB_ENV_LIB_DEBUG))
67 ocv_tbb_read_version("${TBB_ENV_INCLUDE}")
68 add_library(tbb UNKNOWN IMPORTED)
69 set_target_properties(tbb PROPERTIES
70 IMPORTED_LOCATION "${TBB_ENV_LIB}"
71 IMPORTED_LOCATION_DEBUG "${TBB_ENV_LIB_DEBUG}"
72 INTERFACE_INCLUDE_DIRECTORIES "${TBB_ENV_INCLUDE}"
74 # workaround: system TBB library is used for linking instead of provided
76 get_filename_component(_dir "${TBB_ENV_LIB}" DIRECTORY)
77 set_target_properties(tbb PROPERTIES INTERFACE_LINK_LIBRARIES "-L${_dir}")
79 message(STATUS "Found TBB (env): ${TBB_ENV_LIB}")
80 set(${_found} TRUE PARENT_SCOPE)
84 function(ocv_tbb_read_version _path)
85 find_file(TBB_VER_FILE tbb/tbb_stddef.h "${_path}" NO_DEFAULT_PATH CMAKE_FIND_ROOT_PATH_BOTH)
86 ocv_parse_header("${TBB_VER_FILE}" TBB_VERSION_LINES TBB_VERSION_MAJOR TBB_VERSION_MINOR TBB_INTERFACE_VERSION CACHE)
89 #=====================================================================
92 add_subdirectory("${OpenCV_SOURCE_DIR}/3rdparty/tbb")
100 ocv_tbb_cmake_guess(HAVE_TBB)
104 ocv_tbb_env_guess(HAVE_TBB)
107 if(TBB_INTERFACE_VERSION LESS 6000) # drop support of versions < 4.0