|
| 1 | +#=============================================================================== |
| 2 | +# Copyright 2017-2020 Intel Corporation |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +#=============================================================================== |
| 16 | + |
| 17 | +# TBB_FOUND should not be set explicitly. It is defined automatically by CMake. |
| 18 | +# Handling of TBB_VERSION is in TBBConfigVersion.cmake. |
| 19 | + |
| 20 | +if (NOT TBB_FIND_COMPONENTS) |
| 21 | + set(TBB_FIND_COMPONENTS "tbb;tbbmalloc;tbbmalloc_proxy") |
| 22 | + foreach (_tbb_component ${TBB_FIND_COMPONENTS}) |
| 23 | + set(TBB_FIND_REQUIRED_${_tbb_component} 1) |
| 24 | + endforeach() |
| 25 | +endif() |
| 26 | + |
| 27 | +# Add components with internal dependencies: tbbmalloc_proxy -> tbbmalloc |
| 28 | +list(FIND TBB_FIND_COMPONENTS tbbmalloc_proxy _tbbmalloc_proxy_ix) |
| 29 | +if (NOT _tbbmalloc_proxy_ix EQUAL -1) |
| 30 | + list(FIND TBB_FIND_COMPONENTS tbbmalloc _tbbmalloc_ix) |
| 31 | + if (_tbbmalloc_ix EQUAL -1) |
| 32 | + list(APPEND TBB_FIND_COMPONENTS tbbmalloc) |
| 33 | + set(TBB_FIND_REQUIRED_tbbmalloc ${TBB_FIND_REQUIRED_tbbmalloc_proxy}) |
| 34 | + endif() |
| 35 | +endif() |
| 36 | + |
| 37 | +if (NOT TBBROOT) |
| 38 | + if(DEFINED ENV{TBBROOT}) |
| 39 | + set (TBBROOT $ENV{TBBROOT}) |
| 40 | + endif() |
| 41 | +endif() |
| 42 | + |
| 43 | +set(_tbb_root ${TBBROOT}) |
| 44 | + |
| 45 | +set(_tbb_x32_subdir ia32) |
| 46 | +set(_tbb_x64_subdir intel64) |
| 47 | + |
| 48 | +if (CMAKE_SIZEOF_VOID_P EQUAL 8) |
| 49 | + set(_tbb_arch_subdir ${_tbb_x64_subdir}) |
| 50 | +else() |
| 51 | + set(_tbb_arch_subdir ${_tbb_x32_subdir}) |
| 52 | +endif() |
| 53 | + |
| 54 | +if (CMAKE_CXX_COMPILER_LOADED) |
| 55 | + set(_tbb_compiler_id ${CMAKE_CXX_COMPILER_ID}) |
| 56 | + set(_tbb_compiler_ver ${CMAKE_CXX_COMPILER_VERSION}) |
| 57 | +elseif (CMAKE_C_COMPILER_LOADED) |
| 58 | + set(_tbb_compiler_id ${CMAKE_C_COMPILER_ID}) |
| 59 | + set(_tbb_compiler_ver ${CMAKE_C_COMPILER_VERSION}) |
| 60 | +endif() |
| 61 | + |
| 62 | +# For non-GCC compilers try to find version of system GCC to choose right compiler subdirectory. |
| 63 | +if (NOT _tbb_compiler_id STREQUAL "GNU") |
| 64 | + execute_process(COMMAND gcc --version OUTPUT_VARIABLE _tbb_gcc_ver_output ERROR_QUIET) |
| 65 | + string(REGEX REPLACE ".*gcc.*([0-9]+\\.[0-9]+)\\.[0-9]+.*" "\\1" _tbb_compiler_ver "${_tbb_gcc_ver_output}") |
| 66 | + if (NOT _tbb_compiler_ver) |
| 67 | + message(FATAL_ERROR "This Intel TBB package is intended to be used only environment with available 'gcc'") |
| 68 | + endif() |
| 69 | + unset(_tbb_gcc_ver_output) |
| 70 | +endif() |
| 71 | + |
| 72 | +if (EXISTS "${_tbb_root}/lib/${_tbb_arch_subdir}") |
| 73 | + set(_tbb_lib ${_tbb_root}/lib/${_tbb_arch_subdir}) |
| 74 | + set(_tbb_inc ${_tbb_root}/include) |
| 75 | + |
| 76 | + file(GLOB _tbb_gcc_versions_available RELATIVE ${_tbb_lib} ${_tbb_lib}/*) |
| 77 | + # shall we check _tbb_gcc_versions_available is not empty? |
| 78 | + foreach (_tbb_gcc_version ${_tbb_gcc_versions_available}) |
| 79 | + string(SUBSTRING ${_tbb_gcc_version} 3 -1 _tbb_gcc_version_number) |
| 80 | + if (NOT _tbb_compiler_ver VERSION_LESS _tbb_gcc_version_number) |
| 81 | + set(_tbb_compiler_subdir ${_tbb_gcc_version}) |
| 82 | + endif() |
| 83 | + endforeach() |
| 84 | +else() |
| 85 | + if (TBBROOT) |
| 86 | + set(__tbb_hint_path "${TBBROOT}") |
| 87 | + else() |
| 88 | + set(__tbb_hint_path "/non/existing/path") |
| 89 | + endif() |
| 90 | + |
| 91 | + # try to find TBB in the system |
| 92 | + find_library(_tbb_lib NAMES tbb |
| 93 | + HINTS "${__tbb_hint_path}" |
| 94 | + PATH_SUFFIXES lib lib64) |
| 95 | + find_path(_tbb_inc NAMES tbb.h |
| 96 | + HINTS "${__tbb_hint_path}" |
| 97 | + PATH_SUFFIXES include tbb include/tbb) |
| 98 | + unset(__tbb_hint_path) |
| 99 | + |
| 100 | + if (NOT _tbb_lib OR NOT _tbb_inc) |
| 101 | + message("FATAL_ERROR" "Cannot find TBB") |
| 102 | + endif() |
| 103 | + |
| 104 | + get_filename_component(_tbb_lib "${_tbb_lib}" PATH) |
| 105 | + get_filename_component(_tbb_inc "${_tbb_inc}" PATH) |
| 106 | + |
| 107 | + set(_tbb_arch_subdir "") |
| 108 | + set(_tbb_compiler_subdir "") |
| 109 | +endif() |
| 110 | + |
| 111 | +unset(_tbb_gcc_version_number) |
| 112 | +unset(_tbb_compiler_id) |
| 113 | +unset(_tbb_compiler_ver) |
| 114 | + |
| 115 | +# Now we check that all the needed component are present |
| 116 | +get_filename_component(_tbb_lib_path "${_tbb_lib}/${_tbb_compiler_subdir}" ABSOLUTE) |
| 117 | + |
| 118 | +if (TBB_FOUND) |
| 119 | + return() |
| 120 | +endif() |
| 121 | + |
| 122 | +# detect version |
| 123 | +find_file(_tbb_def_header tbb_stddef.h HINTS "${_tbb_root}/include/tbb") |
| 124 | + |
| 125 | +if (_tbb_def_header) |
| 126 | + file(READ "${_tbb_def_header}" _tbb_def_content) |
| 127 | + string(REGEX MATCH "TBB_VERSION_MAJOR[ ]*[0-9]*" _tbb_version_major ${_tbb_def_content}) |
| 128 | + string(REGEX MATCH "[0-9][0-9]*" _tbb_version_major ${_tbb_version_major}) |
| 129 | + |
| 130 | + string(REGEX MATCH "TBB_VERSION_MINOR[ ]*[0-9]" _tbb_version_minor ${_tbb_def_content}) |
| 131 | + string(REGEX MATCH "[0-9][0-9]*" _tbb_version_minor ${_tbb_version_minor}) |
| 132 | + |
| 133 | + set(TBB_VERSION "${_tbb_version_major}.${_tbb_version_minor}") |
| 134 | +else() |
| 135 | + set(TBB_VERSION "") |
| 136 | +endif() |
| 137 | + |
| 138 | +foreach (_tbb_soversion 2 12) |
| 139 | +foreach (_tbb_component ${TBB_FIND_COMPONENTS}) |
| 140 | + set(_tbb_release_lib |
| 141 | + "${_tbb_lib_path}/lib${_tbb_component}.so.${_tbb_soversion}") |
| 142 | + set(_tbb_debug_lib |
| 143 | + "${_tbb_lib_path}/lib${_tbb_component}_debug.so.${_tbb_soversion}") |
| 144 | + |
| 145 | + # oneDNN change: check library existence (BUILD_MODE related only, not both) |
| 146 | + string(TOUPPER "${CMAKE_BUILD_TYPE}" UPPERCASE_CMAKE_BUILD_TYPE) |
| 147 | + if (UPPERCASE_CMAKE_BUILD_TYPE STREQUAL "DEBUG") |
| 148 | + if (EXISTS "${_tbb_debug_lib}") |
| 149 | + set(_lib_exists TRUE) |
| 150 | + elseif (EXISTS "${_tbb_release_lib}") |
| 151 | + message(FATAL_ERROR |
| 152 | + "Intel TBB release library is found here: ${_tbb_release_lib}. " |
| 153 | + "But the debug library |
| 154 | + (lib${_tbb_component}_debug.so.${_tbb_soversion}) is missing.") |
| 155 | + endif() |
| 156 | + else() |
| 157 | + if (EXISTS "${_tbb_release_lib}") |
| 158 | + set(_lib_exists TRUE) |
| 159 | + endif() |
| 160 | + endif() |
| 161 | + |
| 162 | + if (_lib_exists) |
| 163 | + if (NOT TARGET TBB::${_tbb_component}) |
| 164 | + add_library(TBB::${_tbb_component} SHARED IMPORTED) |
| 165 | + set_target_properties(TBB::${_tbb_component} PROPERTIES |
| 166 | + IMPORTED_CONFIGURATIONS "RELEASE;DEBUG" |
| 167 | + IMPORTED_LOCATION_RELEASE "${_tbb_release_lib}" |
| 168 | + IMPORTED_LOCATION_DEBUG "${_tbb_debug_lib}" |
| 169 | + INTERFACE_INCLUDE_DIRECTORIES "${_tbb_inc}") |
| 170 | + |
| 171 | + # Add internal dependencies for imported targets: TBB::tbbmalloc_proxy -> TBB::tbbmalloc |
| 172 | + if (_tbb_component STREQUAL tbbmalloc_proxy) |
| 173 | + set_target_properties(TBB::tbbmalloc_proxy PROPERTIES INTERFACE_LINK_LIBRARIES TBB::tbbmalloc) |
| 174 | + endif() |
| 175 | + |
| 176 | + list(APPEND TBB_IMPORTED_TARGETS TBB::${_tbb_component}) |
| 177 | + set(TBB_${_tbb_component}_FOUND 1) |
| 178 | + endif() |
| 179 | + break() |
| 180 | + endif() |
| 181 | +endforeach() |
| 182 | +endforeach() |
| 183 | + |
| 184 | +if (NOT _lib_exists AND TBB_FIND_REQUIRED AND TBB_FIND_REQUIRED_${_tbb_component}) |
| 185 | + message(FATAL_ERROR "Missed required Intel TBB component: ${_tbb_component}") |
| 186 | +endif() |
| 187 | + |
| 188 | +unset(_tbb_x32_subdir) |
| 189 | +unset(_tbb_x64_subdir) |
| 190 | +unset(_tbb_arch_subdir) |
| 191 | +unset(_tbb_compiler_subdir) |
| 192 | +unset(_tbbmalloc_proxy_ix) |
| 193 | +unset(_tbbmalloc_ix) |
| 194 | +unset(_tbb_lib_path) |
| 195 | +unset(_tbb_release_lib) |
| 196 | +unset(_tbb_debug_lib) |
0 commit comments