Initial PSTL commit
[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 # Firstly search for TBB in config mode (i.e. search for TBBConfig.cmake).
13 find_package(TBB QUIET CONFIG)
14 if (TBB_FOUND)
15     find_package_handle_standard_args(TBB
16                                       REQUIRED_VARS TBB_IMPORTED_TARGETS
17                                       HANDLE_COMPONENTS
18                                       VERSION_VAR TBB_VERSION
19                                       CONFIG_MODE)
20     return()
21 endif()
22
23 if (NOT TBB_FIND_COMPONENTS)
24     set(TBB_FIND_COMPONENTS tbb tbbmalloc)
25     foreach (_tbb_component ${TBB_FIND_COMPONENTS})
26         set(TBB_FIND_REQUIRED_${_tbb_component} 1)
27     endforeach()
28 endif()
29
30 find_path(_tbb_include_dir tbb/tbb.h)
31 if (_tbb_include_dir)
32     file(READ "${_tbb_include_dir}/tbb/tbb_stddef.h" _tbb_stddef LIMIT 2048)
33     string(REGEX REPLACE ".*#define TBB_VERSION_MAJOR ([0-9]+).*" "\\1" _tbb_ver_major "${_tbb_stddef}")
34     string(REGEX REPLACE ".*#define TBB_VERSION_MINOR ([0-9]+).*" "\\1" _tbb_ver_minor "${_tbb_stddef}")
35     string(REGEX REPLACE ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1" TBB_INTERFACE_VERSION "${_tbb_stddef}")
36
37     set(TBB_VERSION "${_tbb_ver_major}.${_tbb_ver_minor}")
38
39     unset(_tbb_stddef)
40     unset(_tbb_ver_major)
41     unset(_tbb_ver_minor)
42
43     foreach (_tbb_component ${TBB_FIND_COMPONENTS})
44         find_library(_tbb_release_lib ${_tbb_component})
45         if (_tbb_release_lib)
46             set(TBB_${_tbb_component}_FOUND 1)
47
48             add_library(TBB::${_tbb_component} SHARED IMPORTED)
49             list(APPEND TBB_IMPORTED_TARGETS TBB::${_tbb_component})
50
51             set(_tbb_lib_suffix)
52             if (UNIX AND NOT APPLE)
53                 set(_tbb_lib_suffix ".2")
54             endif()
55
56             set_target_properties(TBB::${_tbb_component} PROPERTIES
57                                   IMPORTED_CONFIGURATIONS       "RELEASE"
58                                   IMPORTED_LOCATION_RELEASE     "${_tbb_release_lib}${_tbb_lib_suffix}"
59                                   INTERFACE_INCLUDE_DIRECTORIES "${_tbb_include_dir}")
60
61             find_library(_tbb_debug_lib ${_tbb_component}_debug)
62             if (_tbb_debug_lib)
63                 set_target_properties(TBB::${_tbb_component} PROPERTIES
64                                       IMPORTED_CONFIGURATIONS "RELEASE;DEBUG"
65                                       IMPORTED_LOCATION_DEBUG "${_tbb_debug_lib}${_tbb_lib_suffix}")
66             endif()
67             unset(_tbb_debug_lib CACHE)
68             unset(_tbb_lib_suffix)
69         endif()
70         unset(_tbb_release_lib CACHE)
71     endforeach()
72 endif()
73 unset(_tbb_include_dir CACHE)
74
75 find_package_handle_standard_args(TBB
76                                   REQUIRED_VARS TBB_IMPORTED_TARGETS
77                                   HANDLE_COMPONENTS
78                                   VERSION_VAR TBB_VERSION)