1 #===-- FindTBB.cmake -----------------------------------------------------===##
3 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 # See https://llvm.org/LICENSE.txt for license information.
5 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 #===----------------------------------------------------------------------===##
9 include(FindPackageHandleStandardArgs)
11 if (NOT TBB_FIND_COMPONENTS)
12 set(TBB_FIND_COMPONENTS tbb tbbmalloc)
13 foreach (_tbb_component ${TBB_FIND_COMPONENTS})
14 set(TBB_FIND_REQUIRED_${_tbb_component} 1)
18 find_path(_tbb_include_dir tbb/tbb.h)
20 file(READ "${_tbb_include_dir}/tbb/tbb_stddef.h" _tbb_stddef LIMIT 2048)
21 string(REGEX REPLACE ".*#define TBB_VERSION_MAJOR ([0-9]+).*" "\\1" _tbb_ver_major "${_tbb_stddef}")
22 string(REGEX REPLACE ".*#define TBB_VERSION_MINOR ([0-9]+).*" "\\1" _tbb_ver_minor "${_tbb_stddef}")
23 string(REGEX REPLACE ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1" TBB_INTERFACE_VERSION "${_tbb_stddef}")
25 set(TBB_VERSION "${_tbb_ver_major}.${_tbb_ver_minor}")
31 foreach (_tbb_component ${TBB_FIND_COMPONENTS})
32 find_library(_tbb_release_lib ${_tbb_component})
34 set(TBB_${_tbb_component}_FOUND 1)
36 add_library(TBB::${_tbb_component} SHARED IMPORTED)
37 list(APPEND TBB_IMPORTED_TARGETS TBB::${_tbb_component})
40 if (UNIX AND NOT APPLE)
41 set(_tbb_lib_suffix ".2")
44 set_target_properties(TBB::${_tbb_component} PROPERTIES
45 IMPORTED_CONFIGURATIONS "RELEASE"
46 IMPORTED_LOCATION_RELEASE "${_tbb_release_lib}${_tbb_lib_suffix}"
47 INTERFACE_INCLUDE_DIRECTORIES "${_tbb_include_dir}")
49 find_library(_tbb_debug_lib ${_tbb_component}_debug)
51 set_target_properties(TBB::${_tbb_component} PROPERTIES
52 IMPORTED_CONFIGURATIONS "RELEASE;DEBUG"
53 IMPORTED_LOCATION_DEBUG "${_tbb_debug_lib}${_tbb_lib_suffix}")
55 unset(_tbb_debug_lib CACHE)
56 unset(_tbb_lib_suffix)
58 unset(_tbb_release_lib CACHE)
61 unset(_tbb_include_dir CACHE)
63 find_package_handle_standard_args(TBB
64 REQUIRED_VARS TBB_IMPORTED_TARGETS
66 VERSION_VAR TBB_VERSION)