]> rtime.felk.cvut.cz Git - opencv.git/blob - opencv/OpenCVFindTBB.cmake
reversed the order of libraries in opencv.pc (ticket #231)
[opencv.git] / opencv / OpenCVFindTBB.cmake
1 # Locate Intel Threading Building Blocks include paths and libraries
2 # TBB can be found at http://www.threadingbuildingblocks.org/ 
3 # Written by Hannes Hofmann, hannes.hofmann _at_ informatik.uni-erlangen.de
4 # Adapted by Gino van den Bergen gino _at_ dtecta.com
5
6 # GvdB: This module uses the environment variable TBB_ARCH_PLATFORM which defines architecture and compiler.
7 #   e.g. "ia32/vc8" or "em64t/cc4.1.0_libc2.4_kernel2.6.16.21"
8 #   TBB_ARCH_PLATFORM is set by the build script tbbvars[.bat|.sh|.csh], which can be found
9 #   in the TBB installation directory (TBB_INSTALL_DIR).
10 #
11 # For backwards compatibility, you may explicitely set the CMake variables TBB_ARCHITECTURE and TBB_COMPILER.
12 # TBB_ARCHITECTURE     [ ia32 | em64t | itanium ]
13 #   which architecture to use
14 # TBB_COMPILER         e.g. vc9 or cc3.2.3_libc2.3.2_kernel2.4.21 or cc4.0.1_os10.4.9
15 #   which compiler to use (detected automatically on Windows)
16
17 # This module respects
18 # TBB_INSTALL_DIR or $ENV{TBB22_INSTALL_DIR} or $ENV{TBB_INSTALL_DIR}
19
20 # This module defines
21 # TBB_INCLUDE_DIRS, where to find task_scheduler_init.h, etc.
22 # TBB_LIBRARY_DIRS, where to find libtbb, libtbbmalloc
23 # TBB_INSTALL_DIR, the base TBB install directory
24 # TBB_LIBRARIES, the libraries to link against to use TBB.
25 # TBB_DEBUG_LIBRARIES, the libraries to link against to use TBB with debug symbols.
26 # TBB_FOUND, If false, don't try to use TBB.
27
28
29 if (WIN32)
30     # has em64t/vc8   em64t/vc9
31     # has ia32/vc7.1  ia32/vc8   ia32/vc9
32     set(_TBB_DEFAULT_INSTALL_DIR "C:/Program Files/Intel/TBB" "C:/Program Files (x86)/Intel/TBB")
33     set(_TBB_LIB_NAME "tbb")
34     set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc")
35     set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug")
36     set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug")
37     if (MSVC71)
38         set (_TBB_COMPILER "vc7.1")
39     endif(MSVC71)
40     if (MSVC80)
41         set(_TBB_COMPILER "vc8")
42     endif(MSVC80)
43     if (MSVC90)
44         set(_TBB_COMPILER "vc9")
45     endif(MSVC90)
46     if (NOT _TBB_COMPILER)
47         message("ERROR: TBB supports only VC 7.1, 8 and 9 compilers on Windows platforms.")
48     endif (NOT _TBB_COMPILER)
49     set(_TBB_ARCHITECTURE ${TBB_ARCHITECTURE})
50 endif (WIN32)
51
52 if (UNIX)
53     if (APPLE)
54         # MAC
55         set(_TBB_DEFAULT_INSTALL_DIR "/Library/Frameworks/Intel_TBB.framework/Versions")
56         # libs: libtbb.dylib, libtbbmalloc.dylib, *_debug
57         set(_TBB_LIB_NAME "tbb")
58         set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc")
59         set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug")
60         set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug")
61         # has only one flavor: ia32/cc4.0.1_os10.4.9
62         set(_TBB_COMPILER "cc4.0.1_os10.4.9")
63         set(_TBB_ARCHITECTURE "ia32")
64     else (APPLE)
65         # LINUX
66         set(_TBB_DEFAULT_INSTALL_DIR "/opt/intel/tbb" "/usr/local/include" "/usr/include")
67         set(_TBB_LIB_NAME "tbb")
68         set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc")
69         set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug")
70         set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug")
71         # has em64t/cc3.2.3_libc2.3.2_kernel2.4.21  em64t/cc3.3.3_libc2.3.3_kernel2.6.5  em64t/cc3.4.3_libc2.3.4_kernel2.6.9  em64t/cc4.1.0_libc2.4_kernel2.6.16.21
72         # has ia32/*
73         # has itanium/*
74         set(_TBB_COMPILER ${TBB_COMPILER})
75         set(_TBB_ARCHITECTURE ${TBB_ARCHITECTURE})
76     endif (APPLE)
77 endif (UNIX)
78
79 if (CMAKE_SYSTEM MATCHES "SunOS.*")
80 # SUN
81 # not yet supported
82 # has em64t/cc3.4.3_kernel5.10
83 # has ia32/*
84 endif (CMAKE_SYSTEM MATCHES "SunOS.*")
85
86
87 #-- Clear the public variables
88 set (TBB_FOUND "NO")
89
90
91 #-- Find TBB install dir and set ${_TBB_INSTALL_DIR} and cached ${TBB_INSTALL_DIR}
92 # first: use CMake variable TBB_INSTALL_DIR
93 if (TBB_INSTALL_DIR)
94     set (_TBB_INSTALL_DIR ${TBB_INSTALL_DIR})
95 endif (TBB_INSTALL_DIR)
96 # second: use environment variable
97 if (NOT _TBB_INSTALL_DIR)
98     if (NOT "$ENV{TBB_INSTALL_DIR}" STREQUAL "")
99         set (_TBB_INSTALL_DIR $ENV{TBB_INSTALL_DIR})
100     endif (NOT "$ENV{TBB_INSTALL_DIR}" STREQUAL "")
101     # Intel recommends setting TBB22_INSTALL_DIR
102     if (NOT "$ENV{TBB22_INSTALL_DIR}" STREQUAL "")
103         set (_TBB_INSTALL_DIR $ENV{TBB22_INSTALL_DIR})
104     endif (NOT "$ENV{TBB22_INSTALL_DIR}" STREQUAL "")
105 endif (NOT _TBB_INSTALL_DIR)
106 # third: try to find path automatically
107 if (NOT _TBB_INSTALL_DIR)
108     if (_TBB_DEFAULT_INSTALL_DIR)
109         set (_TBB_INSTALL_DIR $ENV{_TBB_DEFAULT_INSTALL_DIR})
110     endif (_TBB_DEFAULT_INSTALL_DIR)
111 endif (NOT _TBB_INSTALL_DIR)
112 # sanity check
113 if (NOT _TBB_INSTALL_DIR)
114     message ("ERROR: TBB_INSTALL_DIR not found. ${_TBB_INSTALL_DIR}")
115 else (NOT _TBB_INSTALL_DIR)
116 # finally: set the cached CMake variable TBB_INSTALL_DIR
117 if (NOT TBB_INSTALL_DIR)
118     set (TBB_INSTALL_DIR ${_TBB_INSTALL_DIR} CACHE PATH "Intel TBB install directory")
119     mark_as_advanced(TBB_INSTALL_DIR)
120 endif (NOT TBB_INSTALL_DIR)
121
122
123 #-- A macro to rewrite the paths of the library. This is necessary, because 
124 #   find_library() always found the em64t/vc9 version of the TBB libs
125 macro(TBB_CORRECT_LIB_DIR var_name)
126 #    if (NOT "${_TBB_ARCHITECTURE}" STREQUAL "em64t")
127         string(REPLACE em64t "${_TBB_ARCHITECTURE}" ${var_name} ${${var_name}})
128 #    endif (NOT "${_TBB_ARCHITECTURE}" STREQUAL "em64t")
129     string(REPLACE ia32 "${_TBB_ARCHITECTURE}" ${var_name} ${${var_name}})
130     string(REPLACE vc7.1 "${_TBB_COMPILER}" ${var_name} ${${var_name}})
131     string(REPLACE vc8 "${_TBB_COMPILER}" ${var_name} ${${var_name}})
132     string(REPLACE vc9 "${_TBB_COMPILER}" ${var_name} ${${var_name}})
133 endmacro(TBB_CORRECT_LIB_DIR var_content)
134
135
136 #-- Look for include directory and set ${TBB_INCLUDE_DIR}
137 set (TBB_INC_SEARCH_DIR ${_TBB_INSTALL_DIR}/include)
138 find_path(TBB_INCLUDE_DIR
139     tbb/task_scheduler_init.h
140     PATHS ${TBB_INC_SEARCH_DIR}
141 )
142 mark_as_advanced(TBB_INCLUDE_DIR)
143
144
145 #-- Look for libraries
146 # GvdB: $ENV{TBB_ARCH_PLATFORM} is set by the build script tbbvars[.bat|.sh|.csh]
147 if (NOT $ENV{TBB_ARCH_PLATFORM} STREQUAL "")
148     set (TBB_LIBRARY_DIR "${_TBB_INSTALL_DIR}/$ENV{TBB_ARCH_PLATFORM}/lib")
149 else (NOT $ENV{TBB_ARCH_PLATFORM} STREQUAL "")
150     # HH: deprecated
151     message(STATUS "[Warning] FindTBB.cmake: The use of TBB_ARCHITECTURE and TBB_COMPILER is deprecated and may not be supported in future versions. Please set $ENV{TBB_ARCH_PLATFORM} (using tbbvars.[bat|csh|sh]).")
152     set (TBB_LIBRARY_DIR "${_TBB_INSTALL_DIR}/${_TBB_ARCHITECTURE}/${_TBB_COMPILER}/lib")
153 endif (NOT $ENV{TBB_ARCH_PLATFORM} STREQUAL "")
154
155
156 find_library(TBB_LIBRARY        ${_TBB_LIB_NAME}        ${TBB_LIBRARY_DIR} NO_DEFAULT_PATH)
157 find_library(TBB_MALLOC_LIBRARY ${_TBB_LIB_MALLOC_NAME} ${TBB_LIBRARY_DIR} NO_DEFAULT_PATH)
158 #TBB_CORRECT_LIB_DIR(TBB_LIBRARY)
159 #TBB_CORRECT_LIB_DIR(TBB_MALLOC_LIBRARY)
160 mark_as_advanced(TBB_LIBRARY TBB_MALLOC_LIBRARY)
161
162 #-- Look for debug libraries
163 find_library(TBB_LIBRARY_DEBUG        ${_TBB_LIB_DEBUG_NAME}        ${TBB_LIBRARY_DIR} NO_DEFAULT_PATH)
164 find_library(TBB_MALLOC_LIBRARY_DEBUG ${_TBB_LIB_MALLOC_DEBUG_NAME} ${TBB_LIBRARY_DIR} NO_DEFAULT_PATH)
165 #TBB_CORRECT_LIB_DIR(TBB_LIBRARY_DEBUG)
166 #TBB_CORRECT_LIB_DIR(TBB_MALLOC_LIBRARY_DEBUG)
167 mark_as_advanced(TBB_LIBRARY_DEBUG TBB_MALLOC_LIBRARY_DEBUG)
168
169
170 if (TBB_INCLUDE_DIR)
171     if (TBB_LIBRARY)
172         set (TBB_FOUND "YES")
173         set (TBB_LIBRARIES ${TBB_LIBRARY} ${TBB_MALLOC_LIBRARY} ${TBB_LIBRARIES})
174         set (TBB_DEBUG_LIBRARIES ${TBB_LIBRARY_DEBUG} ${TBB_MALLOC_LIBRARY_DEBUG} ${TBB_DEBUG_LIBRARIES})
175         set (TBB_INCLUDE_DIRS ${TBB_INCLUDE_DIR} CACHE PATH "TBB include directory" FORCE)
176         set (TBB_LIBRARY_DIRS ${TBB_LIBRARY_DIR} CACHE PATH "TBB library directory" FORCE)
177         mark_as_advanced(TBB_INCLUDE_DIRS TBB_LIBRARY_DIRS TBB_LIBRARIES TBB_DEBUG_LIBRARIES)
178         message(STATUS "Found Intel TBB")
179     endif (TBB_LIBRARY)
180 endif (TBB_INCLUDE_DIR)
181
182 if (NOT TBB_FOUND)
183     message("ERROR: Intel TBB NOT found!")
184     message(STATUS "Looked for Threading Building Blocks in ${_TBB_INSTALL_DIR}")
185     # do only throw fatal, if this pkg is REQUIRED
186     if (TBB_FIND_REQUIRED)
187         message(FATAL_ERROR "Could NOT find TBB library.")
188     endif (TBB_FIND_REQUIRED)
189 endif (NOT TBB_FOUND)
190
191 endif (NOT _TBB_INSTALL_DIR)