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