diff --git a/cmake/templates/OpenVINOConfig.cmake.in b/cmake/templates/OpenVINOConfig.cmake.in index 113f7f42660..af7ea5b8010 100644 --- a/cmake/templates/OpenVINOConfig.cmake.in +++ b/cmake/templates/OpenVINOConfig.cmake.in @@ -163,17 +163,15 @@ if((THREADING STREQUAL "TBB" OR THREADING STREQUAL "TBB_AUTO") AND NOT TBB_FOUND pkg_search_module(tbb ${pkg_config_quiet_arg} ${pkg_config_required_arg} - IMPORTED_TARGET GLOBAL + IMPORTED_TARGET tbb) unset(pkg_config_quiet_arg) unset(pkg_config_required_arg) if(tbb_FOUND) if(TARGET PkgConfig::tbb) - add_library(TBB::tbb ALIAS PkgConfig::tbb) set(TBB_VERSION ${tbb_VERSION}) set(TBB_FOUND ${tbb_FOUND}) - set(TBB_IMPORTED_TARGETS TBB::tbb) elseif(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED) message(FATAL_ERROR "cmake v${CMAKE_VERSION} contains bug in function 'pkg_search_module', need to update to at least v3.16.0 version") endif() @@ -263,7 +261,7 @@ if(_OV_ENABLE_INTEL_MYRIAD AND NOT _OV_ENABLE_OPENVINO_BUILD_SHARED) pkg_search_module(libusb ${pkg_config_quiet_arg} ${pkg_config_required_arg} - IMPORTED_TARGET GLOBAL + IMPORTED_TARGET libusb-1.0) unset(pkg_config_quiet_arg) unset(pkg_config_required_arg) @@ -280,7 +278,7 @@ if(NOT TARGET openvino) # IMPORTED_LINK_DEPENDENT_LIBRARIES_** properties if no PUBLIC dependencies for the library if((THREADING STREQUAL "TBB" OR THREADING STREQUAL "TBB_AUTO") AND TBB_FOUND) foreach(type RELEASE DEBUG RELWITHDEBINFO MINSIZEREL) - foreach(tbb_target TBB::tbb TBB::tbbmalloc) + foreach(tbb_target TBB::tbb TBB::tbbmalloc PkgConfig::tbb) if(TARGET ${tbb_target}) set_property(TARGET openvino::runtime APPEND PROPERTY IMPORTED_LINK_DEPENDENT_LIBRARIES_${type} "${tbb_target}") endif() diff --git a/src/cmake/ie_parallel.cmake b/src/cmake/ie_parallel.cmake index a9951e62a23..e426dbac819 100644 --- a/src/cmake/ie_parallel.cmake +++ b/src/cmake/ie_parallel.cmake @@ -2,6 +2,36 @@ # SPDX-License-Identifier: Apache-2.0 # +function(_ov_get_tbb_location tbb_target _tbb_lib_location_var) + if(NOT TBB_FOUND) + return() + endif() + + foreach(property INTERFACE_LINK_LIBRARIES + IMPORTED_LOCATION_RELEASE + IMPORTED_LOCATION_RELWITHDEBINFO + IMPORTED_LOCATION_NONE + IMPORTED_LOCATION) + get_target_property(_tbb_lib_location ${tbb_target} ${property}) + if(_tbb_lib_location) + if(property STREQUAL INTERFACE_LINK_LIBRARIES) + # pkg-config can set multiple libraries as interface, need to filter out + foreach(tbb_lib IN LISTS _tbb_lib_location) + if(tbb_lib MATCHES "${CMAKE_SHARED_LIBRARY_PREFIX}tbb${CMAKE_SHARED_LIBRARY_SUFFIX}") + set(${_tbb_lib_location_var} "${tbb_lib}" PARENT_SCOPE) + return() + endif() + endforeach() + else() + set(${_tbb_lib_location_var} "${_tbb_lib_location}" PARENT_SCOPE) + return() + endif() + endif() + endforeach() + + message(FATAL_ERROR "Failed to detect TBB library location") +endfunction() + macro(ov_find_package_tbb) if(THREADING STREQUAL "TBB" OR THREADING STREQUAL "TBB_AUTO" AND NOT TBB_FOUND) set(_ov_minimal_tbb_version 2017.0) @@ -48,13 +78,22 @@ macro(ov_find_package_tbb) if(tbb_FOUND) # parse version string(REGEX REPLACE "~.*" "" tbb_VERSION_PATCHED "${tbb_VERSION}") - if(tbb_VERSION_PATCHED VERSION_LESS _ov_minimal_tbb_version) + if(tbb_VERSION_PATCHED AND tbb_VERSION_PATCHED VERSION_LESS _ov_minimal_tbb_version) _ov_pkg_config_tbb_unset() message(WARNING "Found TBB ${tbb_VERSION} via ${PKG_CONFIG_EXECUTABLE} while OpenVINO requies ${_ov_minimal_tbb_version} at least") elseif(TARGET PkgConfig::tbb) add_library(TBB::tbb ALIAS PkgConfig::tbb) set(TBB_VERSION ${tbb_VERSION}) set(TBB_FOUND ${tbb_FOUND}) + + # note: for python wheels we need to find and install tbbmalloc as well + _ov_get_tbb_location(PkgConfig::tbb tbb_loc) + string(REPLACE "tbb" "tbbmalloc" tbbmalloc_loc "${tbb_loc}") + if(EXISTS "${tbbmalloc_loc}") + add_library(TBB::tbbmalloc SHARED IMPORTED) + set_target_properties(TBB::tbbmalloc PROPERTIES IMPORTED_LOCATION ${tbbmalloc_loc}) + endif() + message(STATUS "${PKG_CONFIG_EXECUTABLE}: tbb (${tbb_VERSION}) is found at ${tbb_PREFIX}") else() _ov_pkg_config_tbb_unset() @@ -190,7 +229,7 @@ function(set_ie_threading_interface_for TARGET_NAME) if (THREADING STREQUAL "TBB" OR THREADING STREQUAL "TBB_AUTO") if (TBB_FOUND) set(IE_THREAD_DEFINE "IE_THREAD_TBB") - ie_target_link_libraries(${TARGET_NAME} ${LINK_TYPE} ${TBB_IMPORTED_TARGETS}) + ie_target_link_libraries(${TARGET_NAME} ${LINK_TYPE} TBB::tbb) target_compile_definitions(${TARGET_NAME} ${COMPILE_DEF_TYPE} TBB_PREVIEW_WAITING_FOR_WORKERS=1) else () set(THREADING "SEQ" PARENT_SCOPE) diff --git a/src/cmake/install_tbb.cmake b/src/cmake/install_tbb.cmake index 99840fe8d10..94fe71a7cda 100644 --- a/src/cmake/install_tbb.cmake +++ b/src/cmake/install_tbb.cmake @@ -7,26 +7,6 @@ include(cmake/ie_parallel.cmake) # pre-find TBB: need to provide TBB_IMPORTED_TARGETS used for installation ov_find_package_tbb() -function(_ov_get_tbb_location tbb_target _tbb_lib_location_var) - if(NOT TBB_FOUND) - return() - endif() - - foreach(properties INTERFACE_LINK_LIBRARIES - IMPORTED_LOCATION_RELEASE - IMPORTED_LOCATION_RELWITHDEBINFO - IMPORTED_LOCATION_NONE - IMPORTED_LOCATION) - get_target_property(_tbb_lib_location ${tbb_target} ${properties}) - if(_tbb_lib_location) - set(${_tbb_lib_location_var} "${_tbb_lib_location}" PARENT_SCOPE) - return() - endif() - endforeach() - - message(FATAL_ERROR "Failed to detect TBB library location") -endfunction() - # check whether TBB has TBBBind 2.5 with hwloc 2.5 or higher which is required # to detect hybrid cores function(_ov_detect_dynamic_tbbbind_2_5 var) diff --git a/src/plugins/intel_myriad/third_party/XLink/XLink.cmake b/src/plugins/intel_myriad/third_party/XLink/XLink.cmake index 07ba5b8db23..115ba8c74c8 100644 --- a/src/plugins/intel_myriad/third_party/XLink/XLink.cmake +++ b/src/plugins/intel_myriad/third_party/XLink/XLink.cmake @@ -33,7 +33,7 @@ else() find_package(PkgConfig QUIET) if(PkgConfig_FOUND AND NOT ANDROID) pkg_search_module(libusb REQUIRED - IMPORTED_TARGET GLOBAL + IMPORTED_TARGET libusb-1.0) if(libusb_FOUND) set(LIBUSB_LIBRARY "PkgConfig::libusb" CACHE STRING "libusb-1.0 imported target")