More accurate hwloc finding in case of dynamic tbbbind (#16488)

This commit is contained in:
Ilya Lavrenov 2023-03-24 22:42:20 +04:00 committed by GitHub
parent 81b4666632
commit 18df64c135
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,10 @@
# SPDX-License-Identifier: Apache-2.0
#
if(NOT ANDROID)
find_package(PkgConfig QUIET)
endif()
function(_ov_get_tbb_location tbb_target _tbb_lib_location_var)
if(NOT TBB_FOUND)
return()
@ -63,9 +67,7 @@ macro(ov_find_package_tbb)
unset(TBB_DIR)
# try tbb.pc from system
if(NOT ANDROID AND ENABLE_SYSTEM_TBB)
find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
if(ENABLE_SYSTEM_TBB AND PkgConfig_FOUND)
macro(_ov_pkg_config_tbb_unset)
# unset since it affects OpenVINOConfig.cmake.in
unset(tbb_FOUND)
@ -107,7 +109,6 @@ macro(ov_find_package_tbb)
endif()
endif()
endif()
endif()
if(NOT TBB_FOUND)
# system TBB failed to be found
@ -124,7 +125,7 @@ macro(ov_find_package_tbb)
endif()
# try to find one more time
find_package(TBB QUIET COMPONENTS tbb tbbmalloc
find_package(TBB ${_ov_minimal_tbb_version} QUIET COMPONENTS tbb tbbmalloc
# TBB_DIR can be provided by ov_download_tbb
HINTS ${TBB_DIR}
${_tbb_paths}
@ -143,9 +144,27 @@ macro(ov_find_package_tbb)
endforeach()
if(WIN32 AND TARGET TBB::tbbbind_2_5)
# Add HWLOC::hwloc_2_5 target to check via Apivalidator
get_target_property(TBB_location TBB::tbb IMPORTED_LOCATION_RELEASE)
get_filename_component(TBB_dir "${TBB_location}" DIRECTORY)
# some package managers provide hwloc.pc file within installation package
# let's try it first
if(PkgConfig_FOUND)
pkg_search_module(HWLOC QUIET
IMPORTED_TARGET GLOBAL
hwloc)
endif()
if(TARGET PkgConfig::HWLOC)
# dependency is satisfied
else()
# Add HWLOC::hwloc_2_5 target to check via ApiValidator
get_target_property(imported_configs TBB::tbbbind_2_5 IMPORTED_CONFIGURATIONS)
foreach(imported_config RELEASE RELWITHDEBINFO DEBUG)
if(imported_config IN_LIST imported_configs)
get_target_property(TBBbind_location TBB::tbbbind_2_5 IMPORTED_LOCATION_${imported_config})
get_filename_component(TBB_dir "${TBBbind_location}" DIRECTORY)
break()
endif()
endforeach()
set(hwloc_dll_name "${CMAKE_SHARED_LIBRARY_PREFIX}hwloc${CMAKE_SHARED_LIBRARY_SUFFIX}")
find_file(HWLOC_DLL NAMES ${hwloc_dll_name} PATHS "${TBB_dir}" DOC "Path to hwloc.dll")
@ -155,8 +174,8 @@ macro(ov_find_package_tbb)
add_library(HWLOC::hwloc_2_5 SHARED IMPORTED)
set_property(TARGET HWLOC::hwloc_2_5 APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(HWLOC::hwloc_2_5 PROPERTIES
IMPORTED_LOCATION_RELEASE "${HWLOC_DLL}")
set_target_properties(HWLOC::hwloc_2_5 PROPERTIES IMPORTED_LOCATION_RELEASE "${HWLOC_DLL}")
endif()
endif()
endif()