84e25399f8036406c0037e73f28165d5e8763063
[platform/upstream/tbb.git] / cmake / templates / TBBConfig.cmake.in
1 # Copyright (c) 2017-2019 Intel Corporation
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # It defines the following variables:
16 #     TBB_tbb_FOUND
17 #     TBB_tbbmalloc_FOUND
18 #     TBB_tbbmalloc_proxy_FOUND
19 #     TBB_IMPORTED_TARGETS
20 #
21 # TBBConfigVersion.cmake defines TBB_VERSION
22 #
23 # Initialize to default values
24 if (NOT TBB_tbb_FOUND)
25     set(TBB_tbb_FOUND 0)
26 endif()
27 if (NOT TBB_tbbmalloc_FOUND)
28     set(TBB_tbbmalloc_FOUND 0)
29 endif()
30 if (NOT TBB_tbbmalloc_proxy_FOUND)
31     set(TBB_tbbmalloc_proxy_FOUND 0)
32 endif()
33 if (NOT TBB_IMPORTED_TARGETS)
34     set(TBB_IMPORTED_TARGETS "")
35 endif()
36
37 if (NOT TBB_FIND_COMPONENTS)
38     set(TBB_FIND_COMPONENTS "tbb;tbbmalloc;tbbmalloc_proxy")
39     foreach (_tbb_component ${TBB_FIND_COMPONENTS})
40         set(TBB_FIND_REQUIRED_${_tbb_component} 1)
41     endforeach()
42 endif()
43
44 # Add components with internal dependencies: tbbmalloc_proxy -> tbbmalloc
45 list(FIND TBB_FIND_COMPONENTS tbbmalloc_proxy _tbbmalloc_proxy_ix)
46 if (NOT _tbbmalloc_proxy_ix EQUAL -1)
47     list(FIND TBB_FIND_COMPONENTS tbbmalloc _tbbmalloc_ix)
48     if (_tbbmalloc_ix EQUAL -1)
49         list(APPEND TBB_FIND_COMPONENTS tbbmalloc)
50         set(TBB_FIND_REQUIRED_tbbmalloc ${TBB_FIND_REQUIRED_tbbmalloc_proxy})
51     endif()
52     unset(_tbbmalloc_ix)
53 endif()
54 unset(_tbbmalloc_proxy_ix)
55
56 foreach (_tbb_component ${TBB_FIND_COMPONENTS})
57     set(_tbb_release_lib "${CMAKE_CURRENT_LIST_DIR}/@TBB_LIB_REL_PATH@/@TBB_LIB_PREFIX@${_tbb_component}.@TBB_LIB_EXT@")
58     set(_tbb_debug_lib "${CMAKE_CURRENT_LIST_DIR}/@TBB_LIB_REL_PATH@/@TBB_LIB_PREFIX@${_tbb_component}_debug.@TBB_LIB_EXT@")
59
60     if (EXISTS "${_tbb_release_lib}" OR EXISTS "${_tbb_debug_lib}")
61         if (NOT TARGET TBB::${_tbb_component})
62             add_library(TBB::${_tbb_component} SHARED IMPORTED)
63             set_target_properties(TBB::${_tbb_component} PROPERTIES
64                                   INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_LIST_DIR}/@TBB_INC_REL_PATH@")
65
66             if (EXISTS "${_tbb_release_lib}")
67                 set_target_properties(TBB::${_tbb_component} PROPERTIES
68                                       IMPORTED_LOCATION_RELEASE "${_tbb_release_lib}"@TBB_IMPLIB_RELEASE@)
69                 set_property(TARGET TBB::${_tbb_component} APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
70             endif()
71
72             if (EXISTS "${_tbb_debug_lib}")
73                 set_target_properties(TBB::${_tbb_component} PROPERTIES
74                                       IMPORTED_LOCATION_DEBUG "${_tbb_debug_lib}"@TBB_IMPLIB_DEBUG@)
75                 set_property(TARGET TBB::${_tbb_component} APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
76             endif()
77
78             # Add internal dependencies for imported targets: TBB::tbbmalloc_proxy -> TBB::tbbmalloc
79             if (_tbb_component STREQUAL tbbmalloc_proxy)
80                 set_target_properties(TBB::tbbmalloc_proxy PROPERTIES INTERFACE_LINK_LIBRARIES TBB::tbbmalloc)
81             endif()
82             list(APPEND TBB_IMPORTED_TARGETS TBB::${_tbb_component})
83         else()
84             message(STATUS "Using previously found TBB::${_tbb_component}")
85         endif()
86         set(TBB_${_tbb_component}_FOUND 1)
87     elseif (TBB_FIND_REQUIRED AND TBB_FIND_REQUIRED_${_tbb_component})
88         message(STATUS "Missed required Intel TBB component: ${_tbb_component}")
89         message(STATUS "  one or both of:\n   ${_tbb_release_lib}\n    ${_tbb_debug_lib}\n   files must exist.")
90         set(TBB_FOUND FALSE)
91         set(TBB_${_tbb_component}_FOUND 0)
92     endif()
93 endforeach()
94 unset(_tbb_release_lib)
95 unset(_tbb_debug_lib)