1if(BUILD_TBB)
2  add_subdirectory("${OpenCV_SOURCE_DIR}/3rdparty/tbb")
3  include_directories(SYSTEM ${TBB_INCLUDE_DIRS})
4  set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} tbb)
5  add_definitions(-DTBB_USE_GCC_BUILTINS=1 -D__TBB_GCC_BUILTIN_ATOMICS_PRESENT=1)
6  if(tbb_need_GENERIC_DWORD_LOAD_STORE)
7    add_definitions(-D__TBB_USE_GENERIC_DWORD_LOAD_STORE=1)
8  endif()
9  set(HAVE_TBB 1)
10elseif(UNIX AND NOT APPLE)
11  PKG_CHECK_MODULES(TBB tbb)
12
13  if(TBB_FOUND)
14    set(HAVE_TBB 1)
15    if(NOT ${TBB_INCLUDE_DIRS} STREQUAL "")
16      ocv_include_directories(${TBB_INCLUDE_DIRS})
17    endif()
18    link_directories(${TBB_LIBRARY_DIRS})
19    set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${TBB_LIBRARIES})
20  endif()
21endif()
22
23if(NOT HAVE_TBB)
24  set(TBB_DEFAULT_INCLUDE_DIRS
25    "/opt/intel/tbb/include" "/usr/local/include" "/usr/include"
26    "C:/Program Files/Intel/TBB" "C:/Program Files (x86)/Intel/TBB"
27    "C:/Program Files (x86)/tbb/include"
28    "C:/Program Files (x86)/tbb/include"
29    "${CMAKE_INSTALL_PREFIX}/include")
30
31  find_path(TBB_INCLUDE_DIRS "tbb/tbb.h" PATHS ${TBB_INCLUDE_DIR} ${TBB_DEFAULT_INCLUDE_DIRS} DOC "The path to TBB headers")
32  if(TBB_INCLUDE_DIRS)
33    if(UNIX)
34      set(TBB_LIB_DIR "${TBB_INCLUDE_DIRS}/../lib" CACHE PATH "Full path of TBB library directory")
35      link_directories("${TBB_LIB_DIR}")
36    endif()
37    if(APPLE)
38      set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} libtbb.dylib)
39    elseif(ANDROID)
40      set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS}  tbb)
41      add_definitions(-DTBB_USE_GCC_BUILTINS)
42    elseif (UNIX)
43      set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} tbb)
44    elseif (WIN32)
45      if(CMAKE_COMPILER_IS_GNUCXX)
46        set(TBB_LIB_DIR "${TBB_INCLUDE_DIRS}/../lib" CACHE PATH "Full path of TBB library directory")
47        link_directories("${TBB_LIB_DIR}")
48        set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} tbb)
49      else()
50        get_filename_component(_TBB_LIB_PATH "${TBB_INCLUDE_DIRS}/../lib" ABSOLUTE)
51
52        if(CMAKE_SYSTEM_PROCESSOR MATCHES amd64*|x86_64* OR MSVC64)
53          set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/intel64")
54        else()
55          set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/ia32")
56        endif()
57
58        if(MSVC80)
59          set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/vc8")
60        elseif(MSVC90)
61          set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/vc9")
62        elseif(MSVC10)
63          set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/vc10")
64        elseif(MSVC11)
65          set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/vc11")
66        elseif(MSVC12)
67          set(_TBB_LIB_PATH "${_TBB_LIB_PATH}/vc12")
68        endif()
69        set(TBB_LIB_DIR "${_TBB_LIB_PATH}" CACHE PATH "Full path of TBB library directory")
70        link_directories("${TBB_LIB_DIR}")
71      endif()
72    endif()
73
74    set(HAVE_TBB 1)
75    if(NOT "${TBB_INCLUDE_DIRS}" STREQUAL "")
76      ocv_include_directories("${TBB_INCLUDE_DIRS}")
77    endif()
78  endif(TBB_INCLUDE_DIRS)
79endif(NOT HAVE_TBB)
80
81# get TBB version
82if(HAVE_TBB)
83  find_file(TBB_STDDEF_PATH tbb/tbb_stddef.h "${TBB_INCLUDE_DIRS}")
84  mark_as_advanced(TBB _STDDEF_PATH)
85endif()
86if(HAVE_TBB AND TBB_STDDEF_PATH)
87  ocv_parse_header("${TBB_STDDEF_PATH}" TBB_VERSION_LINES TBB_VERSION_MAJOR TBB_VERSION_MINOR TBB_INTERFACE_VERSION)
88else()
89  unset(TBB_VERSION_MAJOR)
90  unset(TBB_VERSION_MINOR)
91  unset(TBB_INTERFACE_VERSION)
92endif()
93