Skip to content

Commit

Permalink
[onetbb] added hwloc / tbbbind support
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-lavrenov committed Jun 15, 2023
1 parent b2d2b62 commit 4cae3c4
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions recipes/onetbb/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from conan.errors import ConanInvalidConfiguration
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, export_conandata_patches, copy, get, load, rmdir
from conan.tools.gnu import PkgConfigDeps
from conan.tools.scm import Version
import os
import re
Expand All @@ -26,22 +27,31 @@ class OneTBBConan(ConanFile):
"fPIC": [True, False],
"tbbmalloc": [True, False],
"tbbproxy": [True, False],
"tbbbind": [True, False],
"interprocedural_optimization": [True, False],
}
default_options = {
"shared": True,
"fPIC": True,
"tbbmalloc": True,
"tbbproxy": True,
"tbbbind": True,
"interprocedural_optimization": True,
}

@property
def _tbb_hwloc_version(self):
# TBB expects different variables depending on the version
return "2_5" if Version(self.version) >= "2021.4.0" else "2_4"

def export_sources(self):
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
if self.settings.os == "Macos" or Version(self.version) < "2021.1.0":
del self.options.tbbbind
if Version(self.version) < "2021.6.0" or self.settings.os == "Android":
del self.options.interprocedural_optimization
if Version(self.version) < "2021.2.0":
Expand All @@ -53,8 +63,16 @@ def configure(self):
self.options.rm_safe("fPIC")
else:
del self.options.tbbproxy
del self.options.tbbbind
if not self.options.tbbmalloc:
self.options.rm_safe("tbbproxy")
if self.options.get_safe("tbbbind"):
# on Windows TBB cmake variables expect DLL
self.options["hwloc"].shared = True

def requirements(self):
if self.options.get_safe("tbbbind"):
self.requires("hwloc/2.9.1")

def layout(self):
cmake_layout(self, src_folder="src")
Expand All @@ -81,6 +99,8 @@ def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
pkg_config_deps = PkgConfigDeps(self)
pkg_config_deps.generate()
toolchain = CMakeToolchain(self)
toolchain.variables["TBB_TEST"] = False
toolchain.variables["TBB_STRICT"] = False
Expand All @@ -90,6 +110,16 @@ def generate(self):
toolchain.variables["TBB_ENABLE_IPO"] = self.options.interprocedural_optimization
if Version(self.version) >= "2021.6.0" and self.options.get_safe("tbbproxy"):
toolchain.variables["TBBMALLOC_PROXY_BUILD"] = self.options.tbbproxy
if Version(self.version) >= "2021.4.0":
toolchain.variables["TBB_DISABLE_HWLOC_AUTOMATIC_SEARCH"] = not self.options.get_safe("tbbbind", False)
if self.options.get_safe("tbbbind", False) and Version(self.version) >= "2021.1.1":
# better to specify hwloc manually for oneTBB, because it cannot find it automatically in all cases (e.g. cross-compilation)
hwloc_package_folder = self.dependencies["hwloc"].package_folder.replace("\\", "/")
hwloc_lib_name = "hwloc.lib" if self.settings.os == "Windows" else "libhwloc.so"
toolchain.variables[f"CMAKE_HWLOC_{self._tbb_hwloc_version}_LIBRARY_PATH"] = os.path.join(hwloc_package_folder, "lib", hwloc_lib_name)
toolchain.variables[f"CMAKE_HWLOC_{self._tbb_hwloc_version}_INCLUDE_PATH"] = os.path.join(hwloc_package_folder, "include")
if self.settings.os == "Windows":
toolchain.variables[f"CMAKE_HWLOC_{self._tbb_hwloc_version}_DLL_PATH"] = os.path.join(hwloc_package_folder, "bin", "hwloc.dll")
toolchain.generate()

def build(self):
Expand Down Expand Up @@ -154,6 +184,13 @@ def lib_name(name):
if self.settings.os in ["Linux", "FreeBSD"]:
tbbproxy.system_libs = ["m", "dl", "pthread"]

# tbbbind
if self.options.get_safe("tbbbind", False):
tbbtbind = self.cpp_info.components["tbbtbind"]

tbbtbind.set_property("cmake_target_name", "TBB::tbbbind")
tbbtbind.libs = [lib_name("tbbmalloc")]

# TODO: to remove in conan v2 once cmake_find_package* & pkg_config generators removed
self.cpp_info.names["cmake_find_package"] = "TBB"
self.cpp_info.names["cmake_find_package_multi"] = "TBB"
Expand Down

0 comments on commit 4cae3c4

Please sign in to comment.