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
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).
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)
17 # This module respects
18 # TBB_INSTALL_DIR or $ENV{TBB21_INSTALL_DIR} or $ENV{TBB_INSTALL_DIR}
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.
28 # lets try in the obvious places first
29 find_path(TEST_TBB_INCLUDE_DIR
30 tbb/task_scheduler_init.h
32 find_library(TEST_TBB_LIBRARY tbb)
34 if (TEST_TBB_INCLUDE_DIR)
36 set(TBB_OBVIOUS_PLACE "YES")
42 # has em64t/vc8 em64t/vc9
43 # has ia32/vc7.1 ia32/vc8 ia32/vc9
44 set(_TBB_DEFAULT_INSTALL_DIR "C:/Program Files/Intel/TBB" "C:/Program Files (x86)/Intel/TBB")
45 set(_TBB_LIB_NAME "tbb")
46 set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc")
47 set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug")
48 set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug")
50 set (_TBB_COMPILER "vc7.1")
53 set(_TBB_COMPILER "vc8")
56 set(_TBB_COMPILER "vc9")
58 if (NOT _TBB_COMPILER)
59 message("ERROR: TBB supports only VC 7.1, 8 and 9 compilers on Windows platforms.")
60 endif (NOT _TBB_COMPILER)
61 set(_TBB_ARCHITECTURE ${TBB_ARCHITECTURE})
67 set(_TBB_DEFAULT_INSTALL_DIR "/Library/Frameworks/Intel_TBB.framework/Versions")
68 # libs: libtbb.dylib, libtbbmalloc.dylib, *_debug
69 set(_TBB_LIB_NAME "tbb")
70 set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc")
71 set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug")
72 set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug")
73 # has only one flavor: ia32/cc4.0.1_os10.4.9
74 set(_TBB_COMPILER "cc4.0.1_os10.4.9")
75 set(_TBB_ARCHITECTURE "ia32")
78 set(_TBB_DEFAULT_INSTALL_DIR "/opt/intel/tbb" "/usr/local/include" "/usr/include")
79 set(_TBB_LIB_NAME "tbb")
80 set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc")
81 set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug")
82 set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug")
83 # 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
86 set(_TBB_COMPILER ${TBB_COMPILER})
87 set(_TBB_ARCHITECTURE ${TBB_ARCHITECTURE})
91 if (CMAKE_SYSTEM MATCHES "SunOS.*")
94 # has em64t/cc3.4.3_kernel5.10
96 endif (CMAKE_SYSTEM MATCHES "SunOS.*")
99 #-- Clear the public variables
103 #-- Find TBB install dir and set ${_TBB_INSTALL_DIR} and cached ${TBB_INSTALL_DIR}
104 # first: use CMake variable TBB_INSTALL_DIR
106 set (_TBB_INSTALL_DIR ${TBB_INSTALL_DIR})
107 endif (TBB_INSTALL_DIR)
108 # second: use environment variable
109 if (NOT _TBB_INSTALL_DIR)
110 if (NOT "$ENV{TBB_INSTALL_DIR}" STREQUAL "")
111 set (_TBB_INSTALL_DIR $ENV{TBB_INSTALL_DIR})
112 endif (NOT "$ENV{TBB_INSTALL_DIR}" STREQUAL "")
113 # Intel recommends setting TBB21_INSTALL_DIR
114 if (NOT "$ENV{TBB21_INSTALL_DIR}" STREQUAL "")
115 set (_TBB_INSTALL_DIR $ENV{TBB21_INSTALL_DIR})
116 endif (NOT "$ENV{TBB21_INSTALL_DIR}" STREQUAL "")
117 endif (NOT _TBB_INSTALL_DIR)
118 # third: try to find path automatically
119 if (NOT _TBB_INSTALL_DIR)
120 if (_TBB_DEFAULT_INSTALL_DIR)
121 set (_TBB_INSTALL_DIR $ENV{_TBB_DEFAULT_INSTALL_DIR})
122 endif (_TBB_DEFAULT_INSTALL_DIR)
123 endif (NOT _TBB_INSTALL_DIR)
126 if (TBB_OBVIOUS_PLACE)
127 set (TBB_FOUND "YES")
128 set (TBB_LIBRARIES ${TEST_TBB_LIBRARY} ${TBB_LIBRARIES})
129 set (TBB_INCLUDE_DIRS ${TEST_TBB_INCLUDE_DIR} CACHE PATH "TBB include directory" FORCE)
130 mark_as_advanced(TBB_INCLUDE_DIRS TBB_LIBRARIES)
131 message(STATUS "Found Intel TBB")
132 elseif (NOT _TBB_INSTALL_DIR)
133 message ("ERROR: Unable to find Intel TBB install directory. ${_TBB_INSTALL_DIR}")
134 else (TBB_OBVIOUS_PLACE)
135 # finally: set the cached CMake variable TBB_INSTALL_DIR
136 if (NOT TBB_INSTALL_DIR)
137 set (TBB_INSTALL_DIR ${_TBB_INSTALL_DIR} CACHE PATH "Intel TBB install directory")
138 mark_as_advanced(TBB_INSTALL_DIR)
139 endif (NOT TBB_INSTALL_DIR)
142 #-- A macro to rewrite the paths of the library. This is necessary, because
143 # find_library() always found the em64t/vc9 version of the TBB libs
144 macro(TBB_CORRECT_LIB_DIR var_name)
145 # if (NOT "${_TBB_ARCHITECTURE}" STREQUAL "em64t")
146 string(REPLACE em64t "${_TBB_ARCHITECTURE}" ${var_name} ${${var_name}})
147 # endif (NOT "${_TBB_ARCHITECTURE}" STREQUAL "em64t")
148 string(REPLACE ia32 "${_TBB_ARCHITECTURE}" ${var_name} ${${var_name}})
149 string(REPLACE vc7.1 "${_TBB_COMPILER}" ${var_name} ${${var_name}})
150 string(REPLACE vc8 "${_TBB_COMPILER}" ${var_name} ${${var_name}})
151 string(REPLACE vc9 "${_TBB_COMPILER}" ${var_name} ${${var_name}})
152 endmacro(TBB_CORRECT_LIB_DIR var_content)
155 #-- Look for include directory and set ${TBB_INCLUDE_DIR}
156 set (TBB_INC_SEARCH_DIR ${_TBB_INSTALL_DIR}/include)
157 find_path(TBB_INCLUDE_DIR
158 tbb/task_scheduler_init.h
159 PATHS ${TBB_INC_SEARCH_DIR}
161 mark_as_advanced(TBB_INCLUDE_DIR)
164 #-- Look for libraries
165 # GvdB: $ENV{TBB_ARCH_PLATFORM} is set by the build script tbbvars[.bat|.sh|.csh]
166 if (NOT $ENV{TBB_ARCH_PLATFORM} STREQUAL "")
167 set (TBB_LIBRARY_DIR "${_TBB_INSTALL_DIR}/$ENV{TBB_ARCH_PLATFORM}/lib")
168 else (NOT $ENV{TBB_ARCH_PLATFORM} STREQUAL "")
170 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]).")
171 set (TBB_LIBRARY_DIR "${_TBB_INSTALL_DIR}/${_TBB_ARCHITECTURE}/${_TBB_COMPILER}/lib")
172 endif (NOT $ENV{TBB_ARCH_PLATFORM} STREQUAL "")
175 find_library(TBB_LIBRARY ${_TBB_LIB_NAME} ${TBB_LIBRARY_DIR} NO_DEFAULT_PATH)
176 find_library(TBB_MALLOC_LIBRARY ${_TBB_LIB_MALLOC_NAME} ${TBB_LIBRARY_DIR} NO_DEFAULT_PATH)
177 mark_as_advanced(TBB_LIBRARY TBB_MALLOC_LIBRARY)
179 #-- Look for debug libraries
180 find_library(TBB_LIBRARY_DEBUG ${_TBB_LIB_DEBUG_NAME} ${TBB_LIBRARY_DIR} NO_DEFAULT_PATH)
181 find_library(TBB_MALLOC_LIBRARY_DEBUG ${_TBB_LIB_MALLOC_DEBUG_NAME} ${TBB_LIBRARY_DIR} NO_DEFAULT_PATH)
182 mark_as_advanced(TBB_LIBRARY_DEBUG TBB_MALLOC_LIBRARY_DEBUG)
187 set (TBB_FOUND "YES")
188 set (TBB_LIBRARIES ${TBB_LIBRARY} ${TBB_MALLOC_LIBRARY} ${TBB_LIBRARIES})
189 set (TBB_DEBUG_LIBRARIES ${TBB_LIBRARY_DEBUG} ${TBB_MALLOC_LIBRARY_DEBUG} ${TBB_DEBUG_LIBRARIES})
190 set (TBB_INCLUDE_DIRS ${TBB_INCLUDE_DIR} CACHE PATH "TBB include directory" FORCE)
191 set (TBB_LIBRARY_DIRS ${TBB_LIBRARY_DIR} CACHE PATH "TBB library directory" FORCE)
192 mark_as_advanced(TBB_INCLUDE_DIRS TBB_LIBRARY_DIRS TBB_LIBRARIES TBB_DEBUG_LIBRARIES)
193 message(STATUS "Found Intel TBB")
195 endif (TBB_INCLUDE_DIR)
198 message("ERROR: Intel TBB NOT found!")
199 message(STATUS "Looked for Threading Building Blocks in ${_TBB_INSTALL_DIR}")
200 # do only throw fatal, if this pkg is REQUIRED
201 if (TBB_FIND_REQUIRED)
202 message(FATAL_ERROR "Could NOT find TBB library.")
203 endif (TBB_FIND_REQUIRED)
204 endif (NOT TBB_FOUND)
206 endif (TBB_OBVIOUS_PLACE)
209 set(TBB_INTERFACE_VERSION 0)
211 FILE(READ "${TBB_INCLUDE_DIRS}/tbb/tbb_stddef.h" _TBB_VERSION_CONTENTS)
212 STRING(REGEX REPLACE ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1" TBB_INTERFACE_VERSION "${_TBB_VERSION_CONTENTS}")
214 set(TBB_INTERFACE_VERSION "${TBB_INTERFACE_VERSION}")