FindTBB.cmake
Go to the documentation of this file.
1 #.rst:
2 # FindTBB
3 # -------
4 #
5 # Find Intel's Threading Building Blocks (TBB) include path and libraries.
6 #
7 # This module reads hints about search locations from variables:
8 #
9 # ::
10 #
11 # TBB_ROOT - Root directory of pre-built TBB package.
12 # Can be an environment variable instead. It is
13 # derived from the found TBB_INCLUDE_DIR if unset.
14 # TBB_ARCH_PLATFORM - Environment variable which can be used to specify
15 # architecture and platform specific library path
16 # suffix (excluding "/lib/" suffix or prefix).
17 # For MSVC, the appropriate link library path of the
18 # official pre-built download package from the TBB
19 # web site is chosen by this module. The path suffix
20 # derived from this variable takes precedence.
21 #
22 # This module considers the following CMake variables set by find_package:
23 #
24 # ::
25 #
26 # TBB_FIND_COMPONENTS - Case-insensitive names of requested libraries:
27 # tbb, [tbb]malloc, [tbb]malloc_proxy
28 # TBB_FIND_REQUIRED_<C> - Whether TBB library component <C> is required.
29 # TBB is considered to be not found when at least
30 # one required library or its include path is missing.
31 # When no TBB_FIND_COMPONENTS are specified, only the
32 # threading library "tbb" is required.
33 # TBB_FIND_REQUIRED - Raise FATAL_ERROR when required components not found.
34 # TBB_FIND_QUIETLY - Suppress all other (status) messages.
35 #
36 # The TBB_DEBUG variable can be set to TRUE before find_package(TBB) to
37 # enable verbose output which helps to debug the processing of this module:
38 #
39 # ::
40 #
41 # set(TBB_DEBUG TRUE)
42 # find_package(TBB)
43 #
44 # This module defines the following variables:
45 #
46 # ::
47 #
48 # TBB_FOUND - Whether TBB libraries were found.
49 # TBB_INCLUDE_DIR - TBB library include path where tbb/tbb_stddef.h is located.
50 # Used as HINTS for find_path of TBB_<C>_INCLUDE_DIR.
51 # TBB_INCLUDE_DIRS - Include paths of found TBB libraries.
52 # TBB_LIBRARIES - File paths of found TBB libraries.
53 # TBB_VERSION - Version for use in VERSION_LESS et al. comparisons.
54 # TBB_VERSION_MAJOR - Major library version number.
55 # TBB_VERSION_MINOR - Minor library version number.
56 # TBB_VERSION_STRING - Version string for output messages.
57 # TBB_INTERFACE_VERSION - API version number.
58 # TBB_COMPATIBLE_INTERFACE_VERSION - The oldest major version still supported.
59 #
60 # Additionally, for each requested component, this module defines the following variables:
61 #
62 # ::
63 #
64 # TBB_TBB_FOUND - Whether TBB threading library was found.
65 # TBB_TBB_INCLUDE_DIR - Include path of TBB threading library.
66 # TBB_TBB_INCLUDE_DIRS - Include paths for use of TBB library.
67 # TBB_TBB_LIBRARIES - TBB threading library and transitive link dependencies.
68 # TBB_TBB_LIBRARY_RELEASE - File path of optimized TBB link library.
69 # TBB_TBB_LIBRARY_DEBUG - File path of TBB link library with debug symbols.
70 # TBB_TBB_LIBRARY - File paths of both "optimized" and "debug" TBB threading link libraries.
71 # When only one of these is found, this variable is set to either
72 # TBB_TBB_LIBRARY_RELEASE or TBB_TBB_LIBRARY_DEBUG.
73 #
74 # TBB_MALLOC_FOUND - Whether TBB malloc library was found.
75 # TBB_MALLOC_INCLUDE_DIR - Include path of TBB malloc library.
76 # TBB_MALLOC_INCLUDE_DIRS - Include paths for use of TBB malloc library.
77 # TBB_MALLOC_LIBRARIES - TBB malloc library and transitive link dependencies.
78 # TBB_MALLOC_LIBRARY_RELEASE - File path of optimized TBB malloc link library.
79 # TBB_MALLOC_LIBRARY_DEBUG - File path of TBB malloc link library with debug symbols.
80 # TBB_MALLOC_LIBRARY - File paths of both "optimized" and "debug" TBB malloc link libraries.
81 # When only one of these is found, this variable is set to either
82 # TBB_MALLOC_LIBRARY_RELEASE or TBB_MALLOC_LIBRARY_DEBUG.
83 #
84 # TBB_MALLOC_PROXY_FOUND - Whether TBB malloc proxy library was found.
85 # TBB_MALLOC_PROXY_INCLUDE_DIR - Include path of TBB malloc proxy library.
86 # TBB_MALLOC_PROXY_INCLUDE_DIRS - Include paths for use of TBB malloc proxy library.
87 # TBB_MALLOC_PROXY_LIBRARIES - TBB malloc proxy library and transitive link dependencies.
88 # TBB_MALLOC_PROXY_LIBRARY_RELEASE - File path of optimized TBB malloc proxy link library.
89 # TBB_MALLOC_PROXY_LIBRARY_DEBUG - File path of TBB malloc proxy link library with debug symbols.
90 # TBB_MALLOC_PROXY_LIBRARY - File paths of both "optimized" and "debug" TBB malloc proxy link libraries.
91 # When only one of these is found, this variable is set to either
92 # TBB_MALLOC_PROXY_LIBRARY_RELEASE or TBB_MALLOC_PROXY_LIBRARY_DEBUG.
93 #
94 # of these, the following variables are added as advanced cache entries:
95 #
96 # ::
97 #
98 # TBB_INCLUDE_DIR
99 # TBB_<C>_INCLUDE_DIR
100 # TBB_<C>_LIBRARY_RELEASE
101 # TBB_<C>_LIBRARY_DEBUG
102 #
103 # This module further defines the following import targets with the IMPORTED and INTERFACE
104 # properties set appropriately such that only a target_link_libraries command is required
105 # to declare the dependency of another target on the respective TBB library component.
106 # The use of these import targets instead of above defined variables is recommended.
107 #
108 # ::
109 #
110 # TBB::tbb - TBB threading library.
111 # TBB::malloc - TBB malloc library.
112 # TBB::malloc_proxy - TBB malloc proxy library.
113 #
114 # Example usage:
115 #
116 # ::
117 #
118 # find_package(TBB REQUIRED COMPONENTS tbb OPTIONAL_COMPONENTS malloc)
119 #
120 # add_executable(foo foo.cc)
121 # target_link_libraries(foo TBB::tbb)
122 # if (TARGET TBB::malloc)
123 # # or if (TBB_MALLOC_FOUND)
124 # target_link_libraries(foo TBB::malloc)
125 # endif ()
126 #
127 # This module was written by Andreas Schuh for CMake BASIS with inspiration
128 # from the FindTBB module which was originally part of the Object-oriented
129 # Graphics Rendering Engine (OGRE) project with modifications by Robert Maynard.
130 
131 #=============================================================================
132 # Copyright 2016 Andreas Schuh <andreas.schuh.84@gmail.com>
133 #
134 # Distributed under the OSI-approved BSD License (the "License");
135 # see accompanying file Copyright.txt for details.
136 #
137 # This software is distributed WITHOUT ANY WARRANTY; without even the
138 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
139 # See the License for more information.
140 #=============================================================================
141 # (To distribute this file outside of CMake, substitute the full
142 # License text for the above reference.)
143 
144 if (NOT TBB_FIND_QUIETLY)
145  set(_TBB_FIND_STATUS "Looking for TBB")
147  set(_TBB_FIND_STATUS "${_TBB_FIND_STATUS} [${TBB_FIND_COMPONENTS}]")
148  endif ()
149  if (NOT TBB_FIND_REQUIRED)
150  set(_TBB_FIND_STATUS "${_TBB_FIND_STATUS} (optional)")
151  endif ()
152  message(STATUS "${_TBB_FIND_STATUS}...")
153 endif ()
154 
155 # ------------------------------------------------------------------------------
156 # Default required/optional components
157 if (NOT TBB_FIND_COMPONENTS)
158  set(TBB_FIND_COMPONENTS tbb malloc malloc_proxy)
162 endif ()
163 
164 # ------------------------------------------------------------------------------
165 # Normalize component names
166 set(_TBB_FIND_COMPONENTS)
167 foreach (__TBB_COMPONENT IN LISTS TBB_FIND_COMPONENTS)
168  string(TOUPPER "${__TBB_COMPONENT}" _TBB_COMPONENT)
169  string(REGEX REPLACE "^TBB_?([A-Z_]+)$" "\\1" _TBB_COMPONENT "${_TBB_COMPONENT}")
170  if (_TBB_COMPONENT MATCHES "^(TBB|MALLOC|MALLOC_PROXY)$")
171  set(_TBB_${_TBB_COMPONENT}_NAME ${__TBB_COMPONENT})
172  list(APPEND _TBB_FIND_COMPONENTS ${_TBB_COMPONENT})
173  if (TBB_FIND_REQUIRED_${__TBB_COMPONENT})
174  set(_TBB_FIND_REQUIRED_${_TBB_COMPONENT} TRUE)
175  else ()
176  set(_TBB_FIND_REQUIRED_${_TBB_COMPONENT} FALSE)
177  endif ()
178  else ()
179  message(FATAL_ERROR "Unknown TBB library component: ${__TBB_COMPONENT}\n"
180  "Valid component names are: tbb, [tbb]malloc, [tbb]malloc_proxy")
181  endif ()
182 endforeach ()
183 unset(__TBB_COMPONENT)
184 
185 if (TBB_DEBUG)
186  message("** FindTBB: Components = [${_TBB_FIND_COMPONENTS}]")
187 endif ()
188 
189 # ------------------------------------------------------------------------------
190 # Names of headers and libraries for each component
193 set(_TBB_TBB_INC_NAMES tbb/tbb.h)
194 
196 set(_TBB_MALLOC_LIB_NAMES_DEBUG tbbmalloc_debug)
197 set(_TBB_MALLOC_INC_NAMES tbb/tbb.h)
198 
200 set(_TBB_MALLOC_PROXY_LIB_NAMES_DEBUG tbbmalloc_proxy_debug)
201 set(_TBB_MALLOC_PROXY_INC_NAMES tbb/tbbmalloc_proxy.h)
202 
203 # ------------------------------------------------------------------------------
204 # Transitive link dependencies
205 set(_TBB_TBB_LIB_LINK_DEPENDS)
206 set(_TBB_MALLOC_LIB_LINK_DEPENDS)
207 set(_TBB_MALLOC_PROXY_LIB_LINK_DEPENDS)
208 
209 if (UNIX AND NOT APPLE)
210  # On Linux, the TBB threading library requires librt.so
211  list(APPEND _TBB_TBB_LIB_LINK_DEPENDS rt)
212 endif ()
213 
214 # ------------------------------------------------------------------------------
215 # Construct a set of search paths
216 set(_TBB_ARCH_PLATFORM $ENV{TBB_ARCH_PLATFORM})
217 
218 if (NOT TBB_ROOT)
219  file(TO_CMAKE_PATH "$ENV{TBB_ROOT}" TBB_ROOT)
220 endif ()
221 
223 
224 set(_TBB_LIB_PATH_SUFFIXES)
226  list(APPEND _TBB_LIB_PATH_SUFFIXES lib/${_TBB_ARCH_PLATFORM})
227  list(APPEND _TBB_LIB_PATH_SUFFIXES ${_TBB_ARCH_PLATFORM}/lib)
228 endif ()
229 list(APPEND _TBB_LIB_PATH_SUFFIXES lib)
230 
231 if (WIN32 AND MSVC AND CMAKE_GENERATOR MATCHES "Visual Studio ([0-9]+)")
232  set(_TBB_MSVS_VERSION ${CMAKE_MATCH_1})
233  if (CMAKE_CL_64)
234  list(APPEND _TBB_LIB_PATH_SUFFIXES lib/intel64/vc${_TBB_MSVS_VERSION})
235  list(APPEND _TBB_LIB_PATH_SUFFIXES intel64/vc${_TBB_MSVS_VERSION}/lib)
236  list(APPEND _TBB_LIB_PATH_SUFFIXES lib/ia64/vc${_TBB_MSVS_VERSION})
237  list(APPEND _TBB_LIB_PATH_SUFFIXES ia64/vc${_TBB_MSVS_VERSION}/lib)
238  else ()
239  list(APPEND _TBB_LIB_PATH_SUFFIXES lib/ia32/vc${_TBB_MSVS_VERSION})
240  list(APPEND _TBB_LIB_PATH_SUFFIXES ia32/vc${_TBB_MSVS_VERSION}/lib)
241  endif ()
242  unset(_TBB_MSVS_VERSION)
243 endif ()
244 
245 if (TBB_DEBUG)
246  message("** FindTBB: Initial search paths:")
247  message("** FindTBB: - Root directory hints = [${TBB_ROOT}]")
248  message("** FindTBB: - Include path suffixes = [${_TBB_INC_PATH_SUFFIXES}]")
249  message("** FindTBB: - Library path suffixes = [${_TBB_LIB_PATH_SUFFIXES}]")
250 endif ()
251 
252 # ------------------------------------------------------------------------------
253 # Find common include directory
254 #
255 # Looking for tbb/tbb_stddef.h because we use this path later to read this file
256 # in order to extract the version information. The tbb.h header should be in the
257 # same directory and is searched for separately as part of the "tbb" and "malloc"
258 # component search. The TBB_INCLUDE_DIR is then used as HINTS.
259 find_path(TBB_INCLUDE_DIR
260  NAMES tbb/tbb_stddef.h
261  HINTS ${TBB_ROOT}
262  PATH_SUFFIXES ${_TBB_INC_PATH_SUFFIXES}
263 )
264 
265 mark_as_advanced(TBB_INCLUDE_DIR)
266 
267 # ------------------------------------------------------------------------------
268 # Derive TBB_ROOT from TBB_INCLUDE_DIR if unset
269 if (TBB_INCLUDE_DIR AND NOT TBB_ROOT)
270  if (_TBB_INC_PATH_SUFFIXES MATCHES "[^/;]/[^/;]")
271  string(LENGTH "${TBB_INCLUDE_DIR}" _TBB_INCLUDE_DIR_LENGTH)
272  foreach (_TBB_INC_PATH_SUFFIX IN LISTS _TBB_INC_PATH_SUFFIXES)
273  string(LENGTH "${_TBB_INC_PATH_SUFFIX}" _TBB_INC_PATH_SUFFIX_LENGTH)
274  if (_TBB_INC_PATH_SUFFIX_LENGTH GREATER 0)
275  math(EXPR _TBB_SUBSTRING_START "${_TBB_INCLUDE_DIR_LENGTH} - ${_TBB_INC_PATH_SUFFIX_LENGTH}")
276  string(SUBSTRING "${TBB_INCLUDE_DIR}" _TBB_SUBSTRING_START -1 _TBB_SUBSTRING)
277  if (_TBB_SUBSTRING STREQUAL _TBB_INC_PATH_SUFFIX)
278  if (_TBB_SUBSTRING_START GREATER 0)
279  string(SUBSTRING "${TBB_INCLUDE_DIR}" 0 _TBB_SUBSTRING_START TBB_ROOT)
280  string(REGEX REPLACE "/+$" "" TBB_ROOT "${TBB_ROOT}")
281  else ()
282  set(TBB_ROOT "/")
283  endif ()
284  break()
285  endif ()
286  endif ()
287  endforeach ()
288  unset(_TBB_SUBSTRING)
289  unset(_TBB_SUBSTRING_START)
290  unset(_TBB_INCLUDE_DIR_LENGTH)
291  unset(_TBB_INC_PATH_SUFFIX_LENGTH)
292  else ()
293  get_filename_component(TBB_ROOT "${TBB_INCLUDE_DIR}" DIRECTORY)
294  endif ()
295 endif ()
296 
297 if (TBB_DEBUG)
298  message("** FindTBB: After initial search of TBB include path")
299  message("** FindTBB: - TBB_INCLUDE_DIR = ${TBB_INCLUDE_DIR}")
300  message("** FindTBB: - TBB_ROOT = [${TBB_ROOT}]")
301 endif ()
302 
303 # ------------------------------------------------------------------------------
304 # Find library components
305 set(TBB_INCLUDE_DIRS)
306 set(TBB_LIBRARIES)
307 
308 foreach (_TBB_COMPONENT IN LISTS _TBB_FIND_COMPONENTS)
309  if (TBB_DEBUG)
310  message("** FindTBB: Looking for component ${_TBB_COMPONENT}...")
311  endif ()
312 
313  # Find include path and library files of this component
314  find_path(TBB_${_TBB_COMPONENT}_INCLUDE_DIR
315  NAMES ${_TBB_${_TBB_COMPONENT}_INC_NAMES}
316  HINTS ${TBB_INCLUDE_DIR} ${TBB_ROOT}
317  PATH_SUFFIXES ${_TBB_INC_PATH_SUFFIXES}
318  )
319 
320  find_library(TBB_${_TBB_COMPONENT}_LIBRARY_RELEASE
321  NAMES ${_TBB_${_TBB_COMPONENT}_LIB_NAMES_RELEASE}
322  HINTS ${TBB_ROOT}
323  PATH_SUFFIXES ${_TBB_LIB_PATH_SUFFIXES}
324  )
325 
326  find_library(TBB_${_TBB_COMPONENT}_LIBRARY_DEBUG
327  NAMES ${_TBB_${_TBB_COMPONENT}_LIB_NAMES_DEBUG}
328  HINTS ${TBB_ROOT}
329  PATH_SUFFIXES ${_TBB_LIB_PATH_SUFFIXES}
330  )
331 
332  if (TBB_DEBUG)
333  message("** FindTBB: - TBB_${_TBB_COMPONENT}_INCLUDE_DIR = ${TBB_${_TBB_COMPONENT}_INCLUDE_DIR}")
334  message("** FindTBB: - TBB_${_TBB_COMPONENT}_LIBRARY_RELEASE = ${TBB_${_TBB_COMPONENT}_LIBRARY_RELEASE}")
335  message("** FindTBB: - TBB_${_TBB_COMPONENT}_LIBRARY_DEBUG = ${TBB_${_TBB_COMPONENT}_LIBRARY_DEBUG}")
336  endif ()
337 
338  # Mark cache entries as advanced
339  mark_as_advanced(TBB_${_TBB_COMPONENT}_INCLUDE_DIR)
340  mark_as_advanced(TBB_${_TBB_COMPONENT}_LIBRARY_RELEASE)
341  mark_as_advanced(TBB_${_TBB_COMPONENT}_LIBRARY_DEBUG)
342 
343  # Set TBB_<C>_LIBRARY
344  if (TBB_${_TBB_COMPONENT}_LIBRARY_RELEASE AND TBB_${_TBB_COMPONENT}_LIBRARY_DEBUG)
345  set(TBB_${_TBB_COMPONENT}_LIBRARY
346  optimized ${TBB_${_TBB_COMPONENT}_LIBRARY_RELEASE}
347  debug ${TBB_${_TBB_COMPONENT}_LIBRARY_DEBUG}
348  )
349  elseif (TBB_${_TBB_COMPONENT}_LIBRARY_RELEASE)
350  set(TBB_${_TBB_COMPONENT}_LIBRARY ${TBB_${_TBB_COMPONENT}_LIBRARY_RELEASE})
351  elseif (TBB_${_TBB_COMPONENT}_LIBRARY_DEBUG)
352  set(TBB_${_TBB_COMPONENT}_LIBRARY ${TBB_${_TBB_COMPONENT}_LIBRARY_DEBUG})
353  else ()
354  set(TBB_${_TBB_COMPONENT}_LIBRARY TBB_${_TBB_COMPONENT}_LIBRARY-NOTFOUND)
355  endif ()
356 
357  # Set TBB_<C>_FOUND
358  if (TBB_${_TBB_COMPONENT}_INCLUDE_DIR AND TBB_${_TBB_COMPONENT}_LIBRARY)
359  set(TBB_${_TBB_COMPONENT}_FOUND TRUE)
360  else ()
361  set(TBB_${_TBB_COMPONENT}_FOUND FALSE)
362  endif ()
363  set(TBB_${_TBB_${_TBB_COMPONENT}_NAME}_FOUND ${TBB_${_TBB_COMPONENT}_FOUND})
364 
365  if (TBB_${_TBB_COMPONENT}_FOUND)
366 
367  # Add transitive dependencies
368  set(TBB_${_TBB_COMPONENT}_INCLUDE_DIRS ${TBB_${_TBB_COMPONENT}_INCLUDE_DIR})
369  set(TBB_${_TBB_COMPONENT}_LIBRARIES ${TBB_${_TBB_COMPONENT}_LIBRARY})
370  if (_TBB_${_TBB_COMPONENT}_LIB_LINK_DEPENDS)
371  list(APPEND TBB_${_TBB_COMPONENT}_LIBRARIES "${_TBB_${_TBB_COMPONENT}_LIB_LINK_DEPENDS}")
372  endif ()
373 
374  if (TBB_DEBUG)
375  message("** FindTBB: - TBB_${_TBB_COMPONENT}_INCLUDE_DIRS = [${TBB_${_TBB_COMPONENT}_INCLUDE_DIRS}]")
376  message("** FindTBB: - TBB_${_TBB_COMPONENT}_LIBRARIES = [${TBB_${_TBB_COMPONENT}_LIBRARIES}]")
377  endif ()
378 
379  # Add to TBB_INCLUDE_DIRS and TBB_LIBRARIES
380  list(APPEND TBB_INCLUDE_DIRS ${TBB_${_TBB_COMPONENT}_INCLUDE_DIRS})
381  list(APPEND TBB_LIBRARIES ${TBB_${_TBB_COMPONENT}_LIBRARIES})
382 
383  # Add TBB::<C> import target
384  string(TOLOWER ${_TBB_COMPONENT} _TBB_TARGET_NAME)
385  set(_TBB_TARGET_NAME "TBB::${_TBB_TARGET_NAME}")
386  add_library(${_TBB_TARGET_NAME} SHARED IMPORTED)
387 
388  set_target_properties(${_TBB_TARGET_NAME} PROPERTIES
389  INTERFACE_INCLUDE_DIRECTORIES "${TBB_${_TBB_COMPONENT}_INCLUDE_DIRS}"
390  IMPORTED_LINK_INTERFACE_LANGUAGES CXX
391  IMPORTED_NO_SONAME TRUE
392  )
393  if (_TBB_${_TBB_COMPONENT}_LIB_LINK_DEPENDS)
394  set_target_properties(${_TBB_TARGET_NAME} PROPERTIES
395  INTERFACE_LINK_LIBRARIES "${_TBB_${_TBB_COMPONENT}_LIB_LINK_DEPENDS}"
396  )
397  endif ()
398 
399  foreach (_TBB_CONFIGURATION IN ITEMS DEBUG RELEASE)
400  if (TBB_${_TBB_COMPONENT}_LIBRARY_${_TBB_CONFIGURATION})
401  set_property(TARGET ${_TBB_TARGET_NAME} APPEND PROPERTY IMPORTED_CONFIGURATIONS ${_TBB_CONFIGURATION})
402  if (WIN32)
403  set_target_properties(${_TBB_TARGET_NAME} PROPERTIES
404  IMPORTED_IMPLIB_${_TBB_CONFIGURATION} "${TBB_${_TBB_COMPONENT}_LIBRARY_${_TBB_CONFIGURATION}}"
405  )
406  string(REPLACE "/lib/" "/bin/" _TBB_LIB_PATH_DLL "${TBB_${_TBB_COMPONENT}_LIBRARY_${_TBB_CONFIGURATION}}")
407  string(REGEX REPLACE "\\.lib$" ".dll" _TBB_LIB_PATH_DLL "${_TBB_LIB_PATH_DLL}")
408  if (EXISTS "${_TBB_LIB_PATH_DLL}")
409  set_target_properties(${_TBB_TARGET_NAME} PROPERTIES
410  IMPORTED_LOCATION_${_TBB_CONFIGURATION} "${_TBB_LIB_PATH_DLL}"
411  )
412  if (TBB_DEBUG)
413  message("** FindTBB: - IMPORTED_LOCATION_${_TBB_CONFIGURATION} = ${_TBB_LIB_PATH_DLL}")
414  endif ()
415  elseif (TBB_DEBUG)
416  message("** FindTBB: Could not determine ${_TBB_CONFIGURATION} DLL path from import library, tried: "
417  "\n\t${_TBB_LIB_PATH_DLL}")
418  endif ()
419  else ()
420  set_target_properties(${_TBB_TARGET_NAME} PROPERTIES
421  IMPORTED_LOCATION_${_TBB_CONFIGURATION} "${TBB_${_TBB_COMPONENT}_LIBRARY_${_TBB_CONFIGURATION}}"
422  )
423  endif ()
424  endif ()
425  endforeach ()
426 
427  if (TBB_DEBUG)
428  message("** FindTBB: Looking for component ${_TBB_COMPONENT}... - found")
429  endif ()
430 
431  else ()
432 
433  if (TBB_DEBUG)
434  message("** FindTBB: Looking for component ${_TBB_COMPONENT}... - not found")
435  endif ()
436  unset(TBB_${_TBB_COMPONENT}_INCLUDE_DIRS)
437  unset(TBB_${_TBB_COMPONENT}_LIBRARIES)
438 
439  endif ()
440 endforeach ()
441 
442 if (TBB_INCLUDE_DIRS)
443  list(REMOVE_DUPLICATES TBB_INCLUDE_DIRS)
444 endif ()
445 
446 if (TBB_DEBUG)
447  message("** FindTBB: Include paths and libraries of all found components:")
448  message("** FindTBB: - TBB_INCLUDE_DIRS = [${TBB_INCLUDE_DIRS}]")
449  message("** FindTBB: - TBB_LIBRARIES = [${TBB_LIBRARIES}]")
450 endif ()
451 
452 # ------------------------------------------------------------------------------
453 # Extract library version from start of tbb_stddef.h
454 if (TBB_INCLUDE_DIR)
455  if (NOT DEFINED TBB_VERSION_MAJOR OR
456  NOT DEFINED TBB_VERSION_MINOR OR
457  NOT DEFINED TBB_INTERFACE_VERSION OR
458  NOT DEFINED TBB_COMPATIBLE_INTERFACE_VERSION)
459  file(READ "${TBB_INCLUDE_DIR}/tbb/tbb_stddef.h" _TBB_VERSION_CONTENTS LIMIT 2048)
460  string(REGEX REPLACE
461  ".*#define TBB_VERSION_MAJOR ([0-9]+).*" "\\1"
462  TBB_VERSION_MAJOR "${_TBB_VERSION_CONTENTS}"
463  )
464  string(REGEX REPLACE
465  ".*#define TBB_VERSION_MINOR ([0-9]+).*" "\\1"
466  TBB_VERSION_MINOR "${_TBB_VERSION_CONTENTS}"
467  )
468  string(REGEX REPLACE
469  ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1"
470  TBB_INTERFACE_VERSION "${_TBB_VERSION_CONTENTS}"
471  )
472  string(REGEX REPLACE
473  ".*#define TBB_COMPATIBLE_INTERFACE_VERSION ([0-9]+).*" "\\1"
474  TBB_COMPATIBLE_INTERFACE_VERSION "${_TBB_VERSION_CONTENTS}"
475  )
476  unset(_TBB_VERSION_CONTENTS)
477  endif ()
478  set(TBB_VERSION "${TBB_VERSION_MAJOR}.${TBB_VERSION_MINOR}")
479  set(TBB_VERSION_STRING "${TBB_VERSION}")
480 else ()
481  unset(TBB_VERSION)
482  unset(TBB_VERSION_MAJOR)
483  unset(TBB_VERSION_MINOR)
484  unset(TBB_VERSION_STRING)
485  unset(TBB_INTERFACE_VERSION)
486  unset(TBB_COMPATIBLE_INTERFACE_VERSION)
487 endif ()
488 
489 if (TBB_DEBUG)
490  message("** FindTBB: Version information from ${TBB_INCLUDE_DIR}/tbb/tbb_stddef.h")
491  message("** FindTBB: - TBB_VERSION_STRING = ${TBB_VERSION_STRING}")
492  message("** FindTBB: - TBB_VERSION_MAJOR = ${TBB_VERSION_MAJOR}")
493  message("** FindTBB: - TBB_VERSION_MINOR = ${TBB_VERSION_MINOR}")
494  message("** FindTBB: - TBB_INTERFACE_VERSION = ${TBB_INTERFACE_VERSION}")
495  message("** FindTBB: - TBB_COMPATIBLE_INTERFACE_VERSION = ${TBB_COMPATIBLE_INTERFACE_VERSION}")
496 endif ()
497 
498 # ------------------------------------------------------------------------------
499 # Handle QUIET, REQUIRED, and [EXACT] VERSION arguments and set TBB_FOUND
500 include(FindPackageHandleStandardArgs)
501 find_package_handle_standard_args(TBB
502  REQUIRED_VARS TBB_INCLUDE_DIR
503  VERSION_VAR TBB_VERSION
504  HANDLE_COMPONENTS
505 )
506 
507 if (NOT TBB_FIND_QUIETLY)
508  if (TBB_FOUND)
509  message(STATUS "${_TBB_FIND_STATUS}... - found v${TBB_VERSION_STRING}")
510  else ()
511  message(STATUS "${_TBB_FIND_STATUS}... - not found")
512  endif ()
513 endif ()
514 
515 # ------------------------------------------------------------------------------
516 # Unset local auxiliary variables
517 foreach (_TBB_COMPONENT IN ITEMS TBB MALLOC MALLOC_PROXY)
518  unset(_TBB_FIND_REQUIRED_${_TBB_COMPONENT})
519  unset(_TBB_${_TBB_COMPONENT}_LIB_NAMES_RELEASE)
520  unset(_TBB_${_TBB_COMPONENT}_LIB_NAMES_DEBUG)
521  unset(_TBB_${_TBB_COMPONENT}_LIB_LINK_DEPENDS)
522  unset(_TBB_${_TBB_COMPONENT}_INC_NAMES)
523  unset(_TBB_${_TBB_COMPONENT}_NAME)
524 endforeach ()
525 
526 unset(_TBB_COMPONENT)
527 unset(_TBB_TARGET_NAME)
528 unset(_TBB_FIND_COMPONENTS)
529 unset(_TBB_FIND_STATUS)
530 unset(_TBB_INC_PATH_SUFFIXES)
531 unset(_TBB_LIB_PATH_SUFFIXES)
532 unset(_TBB_LIB_PATH_DLL)
533 unset(_TBB_LIB_NAME)
534 unset(_TBB_ARCH_PLATFORM)
cmake TBB_FIND_REQUIRED_malloc
Definition: FindTBB.cmake:160
cmake _TBB_TBB_INC_NAMES
Definition: FindTBB.cmake:193
cmake _TBB_TARGET_NAME
Definition: FindTBB.cmake:385
cmake _TBB_MALLOC_LIB_NAMES_RELEASE
Definition: FindTBB.cmake:195
cmake _TBB_INC_PATH_SUFFIXES
Definition: FindTBB.cmake:222
cmake _TBB_MALLOC_PROXY_INC_NAMES
Definition: FindTBB.cmake:201
cmake _TBB_MSVS_VERSION
Definition: FindTBB.cmake:232
cmake TBB_ROOT
Definition: FindTBB.cmake:282
cmake _TBB_MALLOC_PROXY_LIB_NAMES_RELEASE
Definition: FindTBB.cmake:199
cmake TBB_VERSION
Definition: FindTBB.cmake:478
cmake _TBB_FIND_STATUS
Definition: FindTBB.cmake:145
cmake _TBB_MALLOC_INC_NAMES
Definition: FindTBB.cmake:197
cmake _TBB_TBB_LIB_NAMES_RELEASE
Definition: FindTBB.cmake:191
cmake _TBB_TBB_LIB_NAMES_DEBUG
Definition: FindTBB.cmake:192
#define UNIX
Whether the sources are compiled on a Unix-based system.
Definition: config.h:60
cmake TBB_FIND_REQUIRED_malloc_proxy
Definition: FindTBB.cmake:161
cmake _TBB_MALLOC_PROXY_LIB_NAMES_DEBUG
Definition: FindTBB.cmake:200
cmake TBB_FIND_COMPONENTS
Definition: FindTBB.cmake:158
cmake _TBB_MALLOC_LIB_NAMES_DEBUG
Definition: FindTBB.cmake:196
cmake TBB_VERSION_STRING
Definition: FindTBB.cmake:479
cmake _TBB_ARCH_PLATFORM
Definition: FindTBB.cmake:216
cmake TBB_FIND_REQUIRED_tbb
Definition: FindTBB.cmake:159
if(oldcoutbuf)
function get_filename_component(inout ARGN)
Fixes CMake&#39;s get_filename_component() command.