Skip to content

Commit

Permalink
(#17812) [hwloc] new recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-lavrenov authored Jun 15, 2023
1 parent 63a5db3 commit b2d2b62
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 0 deletions.
13 changes: 13 additions & 0 deletions recipes/hwloc/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
sources:
"2.9.1":
sha256: "a440e2299f7451dc10a57ddbfa3f116c2a6c4be1bb97c663edd3b9c7b3b3b4cf"
url: https://download.open-mpi.org/release/hwloc/v2.9/hwloc-2.9.1.tar.gz
"2.9.0":
sha256: "9d7d3450e0a5fea4cb80ca07dc8db939abb7ab62e2a7bb27f9376447658738ec"
url: https://download.open-mpi.org/release/hwloc/v2.9/hwloc-2.9.0.tar.gz
"2.8.0":
sha256: "20b2bd4df436827d8e50f7afeafb6f967259f2fb374ce7330244f8d0ed2dde6f"
url: https://download.open-mpi.org/release/hwloc/v2.8/hwloc-2.8.0.tar.gz
"2.7.2":
sha256: "407d2712b1c9026787461ddb62044fa9b5c6007755ca37652b360d837a75344f"
url: https://download.open-mpi.org/release/hwloc/v2.7/hwloc-2.7.2.tar.gz
114 changes: 114 additions & 0 deletions recipes/hwloc/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
from conan import ConanFile
from conan.tools.apple import is_apple_os, fix_apple_shared_install_name
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import copy, get, rm, rmdir
from conan.tools.gnu import Autotools, AutotoolsToolchain, PkgConfigDeps
from conan.tools.layout import basic_layout
import os

required_conan_version = ">=1.53.0"


class HwlocConan(ConanFile):
name = "hwloc"
description = "Portable Hardware Locality (hwloc)"
topics = ("hardware", "topology")
license = "BSD-3-Clause"
homepage = "https://www.open-mpi.org/projects/hwloc/"
url = "https://github.com/conan-io/conan-center-index"
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_libxml2": [True, False]
}
default_options = {
"shared": False,
"fPIC": True,
"with_libxml2": False
}

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.cppstd")
self.settings.rm_safe("compiler.libcxx")

def requirements(self):
if self.options.with_libxml2:
self.requires("libxml2/2.9.12")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def layout(self):
if self.settings.os == "Windows":
cmake_layout(self, src_folder="src")
else:
basic_layout(self, src_folder="src")

def generate(self):
if self.settings.os == "Windows":
deps = CMakeDeps(self)
deps.generate()
tc = CMakeToolchain(self)
tc.cache_variables["HWLOC_ENABLE_TESTING"] = 'OFF'
tc.cache_variables["HWLOC_SKIP_LSTOPO"] = 'ON'
tc.cache_variables["HWLOC_SKIP_TOOLS"] = 'ON'
tc.cache_variables["HWLOC_SKIP_INCLUDES"] = 'OFF'
tc.cache_variables["HWLOC_WITH_OPENCL"] = 'OFF'
tc.cache_variables["HWLOC_WITH_CUDA"] = 'OFF'
tc.cache_variables["HWLOC_BUILD_SHARED_LIBS"] = self.options.shared
tc.cache_variables["HWLOC_WITH_LIBXML2"] = self.options.with_libxml2
tc.generate()
else:
deps = PkgConfigDeps(self)
deps.generate()
tc = AutotoolsToolchain(self)
if not self.options.with_libxml2:
tc.configure_args.extend(["--disable-libxml2"])
tc.configure_args.extend(["--disable-io", "--disable-cairo"])
tc.generate()

def build(self):
if self.settings.os == "Windows":
cmake = CMake(self)
cmake.configure(build_script_folder=os.path.join("contrib", "windows-cmake"))
cmake.build()
else:
autotools = Autotools(self)
autotools.configure()
autotools.make()

def package(self):
copy(self, "COPYING", self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
if self.settings.os == "Windows":
cmake = CMake(self)
cmake.install()
# remove PDB files
rm(self, "*.pdb", os.path.join(self.package_folder, "bin"))
else:
autotools = Autotools(self)
autotools.install()
fix_apple_shared_install_name(self)
# remove tools
rmdir(self, os.path.join(self.package_folder, "bin"))

rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rm(self, "*.la", os.path.join(self.package_folder, "lib"))
rmdir(self, os.path.join(self.package_folder, "share"))

def package_info(self):
self.cpp_info.set_property("pkg_config_name", "hwloc")
self.cpp_info.libs = ["hwloc"]

if not self.options.shared:
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs = ["m"]
if is_apple_os(self):
self.cpp_info.frameworks = ['IOKit', 'Foundation', 'CoreFoundation']
7 changes: 7 additions & 0 deletions recipes/hwloc/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES C)

find_package(hwloc REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE hwloc::hwloc)
26 changes: 26 additions & 0 deletions recipes/hwloc/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
10 changes: 10 additions & 0 deletions recipes/hwloc/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <hwloc.h>

int main(void) {
hwloc_topology_t topology;

hwloc_topology_init(&topology);
hwloc_topology_destroy(topology);

return 0;
}
9 changes: 9 additions & 0 deletions recipes/hwloc/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
versions:
"2.9.1":
folder: all
"2.9.0":
folder: all
"2.8.0":
folder: all
"2.7.2":
folder: all

0 comments on commit b2d2b62

Please sign in to comment.