Fix PR41465 - Use __builtin_mul_overflow instead of hand-rolled check.
[lldb.git] / pstl / cmake / FindTBB.cmake
1 #===-- FindTBB.cmake -----------------------------------------------------===##
2 #
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
6 #
7 #===----------------------------------------------------------------------===##
8
9 include(FindPackageHandleStandardArgs)
10
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)
15     endforeach()
16 endif()
17
18 find_path(_tbb_include_dir tbb/tbb.h)
19 if (_tbb_include_dir)
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}")
24
25     set(TBB_VERSION "${_tbb_ver_major}.${_tbb_ver_minor}")
26
27     unset(_tbb_stddef)
28     unset(_tbb_ver_major)
29     unset(_tbb_ver_minor)
30
31     foreach (_tbb_component ${TBB_FIND_COMPONENTS})
32         find_library(_tbb_release_lib ${_tbb_component})
33         if (_tbb_release_lib)
34             set(TBB_${_tbb_component}_FOUND 1)
35
36             add_library(TBB::${_tbb_component} SHARED IMPORTED)
37             list(APPEND TBB_IMPORTED_TARGETS TBB::${_tbb_component})
38
39             set(_tbb_lib_suffix)
40             if (UNIX AND NOT APPLE)
41                 set(_tbb_lib_suffix ".2")
42             endif()
43
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}")
48
49             find_library(_tbb_debug_lib ${_tbb_component}_debug)
50             if (_tbb_debug_lib)
51                 set_target_properties(TBB::${_tbb_component} PROPERTIES
52                                       IMPORTED_CONFIGURATIONS "RELEASE;DEBUG"
53                                       IMPORTED_LOCATION_DEBUG "${_tbb_debug_lib}${_tbb_lib_suffix}")
54             endif()
55             unset(_tbb_debug_lib CACHE)
56             unset(_tbb_lib_suffix)
57         endif()
58         unset(_tbb_release_lib CACHE)
59     endforeach()
60 endif()
61 unset(_tbb_include_dir CACHE)
62
63 find_package_handle_standard_args(TBB
64                                   REQUIRED_VARS TBB_IMPORTED_TARGETS
65                                   HANDLE_COMPONENTS
66                                   VERSION_VAR TBB_VERSION)