[pstl] Initial integration with LLVM's CMake
[lldb.git] / pstl / cmake / FindTBB.cmake
1 #===-- FindTBB.cmake -----------------------------------------------------===##
2 #
3 #                     The LLVM Compiler Infrastructure
4 #
5 # This file is dual licensed under the MIT and the University of Illinois Open
6 # Source Licenses. See LICENSE.TXT for details.
7 #
8 #===----------------------------------------------------------------------===##
9
10 include(FindPackageHandleStandardArgs)
11
12 if (NOT TBB_FIND_COMPONENTS)
13     set(TBB_FIND_COMPONENTS tbb tbbmalloc)
14     foreach (_tbb_component ${TBB_FIND_COMPONENTS})
15         set(TBB_FIND_REQUIRED_${_tbb_component} 1)
16     endforeach()
17 endif()
18
19 find_path(_tbb_include_dir tbb/tbb.h)
20 if (_tbb_include_dir)
21     file(READ "${_tbb_include_dir}/tbb/tbb_stddef.h" _tbb_stddef LIMIT 2048)
22     string(REGEX REPLACE ".*#define TBB_VERSION_MAJOR ([0-9]+).*" "\\1" _tbb_ver_major "${_tbb_stddef}")
23     string(REGEX REPLACE ".*#define TBB_VERSION_MINOR ([0-9]+).*" "\\1" _tbb_ver_minor "${_tbb_stddef}")
24     string(REGEX REPLACE ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1" TBB_INTERFACE_VERSION "${_tbb_stddef}")
25
26     set(TBB_VERSION "${_tbb_ver_major}.${_tbb_ver_minor}")
27
28     unset(_tbb_stddef)
29     unset(_tbb_ver_major)
30     unset(_tbb_ver_minor)
31
32     foreach (_tbb_component ${TBB_FIND_COMPONENTS})
33         find_library(_tbb_release_lib ${_tbb_component})
34         if (_tbb_release_lib)
35             set(TBB_${_tbb_component}_FOUND 1)
36
37             add_library(TBB::${_tbb_component} SHARED IMPORTED)
38             list(APPEND TBB_IMPORTED_TARGETS TBB::${_tbb_component})
39
40             set(_tbb_lib_suffix)
41             if (UNIX AND NOT APPLE)
42                 set(_tbb_lib_suffix ".2")
43             endif()
44
45             set_target_properties(TBB::${_tbb_component} PROPERTIES
46                                   IMPORTED_CONFIGURATIONS       "RELEASE"
47                                   IMPORTED_LOCATION_RELEASE     "${_tbb_release_lib}${_tbb_lib_suffix}"
48                                   INTERFACE_INCLUDE_DIRECTORIES "${_tbb_include_dir}")
49
50             find_library(_tbb_debug_lib ${_tbb_component}_debug)
51             if (_tbb_debug_lib)
52                 set_target_properties(TBB::${_tbb_component} PROPERTIES
53                                       IMPORTED_CONFIGURATIONS "RELEASE;DEBUG"
54                                       IMPORTED_LOCATION_DEBUG "${_tbb_debug_lib}${_tbb_lib_suffix}")
55             endif()
56             unset(_tbb_debug_lib CACHE)
57             unset(_tbb_lib_suffix)
58         endif()
59         unset(_tbb_release_lib CACHE)
60     endforeach()
61 endif()
62 unset(_tbb_include_dir CACHE)
63
64 find_package_handle_standard_args(TBB
65                                   REQUIRED_VARS TBB_IMPORTED_TARGETS
66                                   HANDLE_COMPONENTS
67                                   VERSION_VAR TBB_VERSION)