Skip to content

Commit 5fa50ad

Browse files
authored
(#14251) libnuma: conan v2 support
1 parent ba0aea3 commit 5fa50ad

File tree

6 files changed

+77
-54
lines changed

6 files changed

+77
-54
lines changed

recipes/libnuma/all/conandata.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ sources:
33
url: "https://github.com/numactl/numactl/releases/download/v2.0.14/numactl-2.0.14.tar.gz"
44
sha256: "826bd148c1b6231e1284e42a4db510207747484b112aee25ed6b1078756bcff6"
55
patches:
6-
"2.0.14":
6+
"2.0.14":
77
- patch_file: "patches/symver.patch"
8-
base_path: "source_subfolder"

recipes/libnuma/all/conanfile.py

Lines changed: 33 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1+
from conan import ConanFile
2+
from conan.errors import ConanInvalidConfiguration
3+
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir
4+
from conan.tools.gnu import Autotools, AutotoolsToolchain
5+
from conan.tools.layout import basic_layout
16
import os
27

3-
from conans import ConanFile, AutoToolsBuildEnvironment, tools
4-
from conans.errors import ConanInvalidConfiguration
8+
required_conan_version = ">=1.53.0"
59

6-
required_conan_version = ">=1.29.1"
710

811
class LibnumaConan(ConanFile):
912
name = "libnuma"
1013
description = "NUMA support for Linux."
1114
license = "LGPL-2.1-or-later"
12-
topics = ("conan", "numa")
15+
topics = ("numa")
1316
homepage = "https://github.com/numactl/numactl"
1417
url = "https://github.com/conan-io/conan-center-index"
18+
1519
settings = "os", "arch", "compiler", "build_type"
1620
options = {
1721
"shared": [True, False],
@@ -21,60 +25,47 @@ class LibnumaConan(ConanFile):
2125
"shared": False,
2226
"fPIC": True,
2327
}
24-
exports_sources = "patches/**"
25-
26-
_autotools = None
2728

28-
@property
29-
def _source_subfolder(self):
30-
return "source_subfolder"
29+
def export_sources(self):
30+
export_conandata_patches(self)
3131

3232
def configure(self):
33-
if self.settings.os != "Linux":
34-
raise ConanInvalidConfiguration("{} is only supported on Linux".format(self.name))
35-
del self.settings.compiler.libcxx
36-
del self.settings.compiler.cppstd
3733
if self.options.shared:
3834
del self.options.fPIC
35+
self.settings.rm_safe("compiler.cppstd")
36+
self.settings.rm_safe("compiler.libcxx")
3937

40-
def _patch_sources(self):
41-
for patch in self.conan_data.get("patches",{}).get(self.version, []):
42-
tools.patch(**patch)
43-
44-
def source(self):
45-
tools.get(**self.conan_data["sources"][self.version])
46-
os.rename("numactl-" + self.version, self._source_subfolder)
38+
def layout(self):
39+
basic_layout(self, src_folder="src")
4740

48-
def _configure_autotools(self):
49-
if self._autotools:
50-
return self._autotools
41+
def validate(self):
42+
if self.info.settings.os != "Linux":
43+
raise ConanInvalidConfiguration("libnuma is only supported on Linux")
5144

52-
self._autotools = AutoToolsBuildEnvironment(self)
53-
54-
args = []
55-
if self.options.shared:
56-
args.extend(["--disable-static", "--enable-shared"])
57-
else:
58-
args.extend(["--disable-shared", "--enable-static"])
45+
def source(self):
46+
get(self, **self.conan_data["sources"][self.version],
47+
destination=self.source_folder, strip_root=True)
5948

60-
self._autotools.configure(args=args, configure_dir=self._source_subfolder)
61-
return self._autotools
49+
def generate(self):
50+
tc = AutotoolsToolchain(self)
51+
tc.generate()
6252

6353
def build(self):
64-
self._patch_sources()
65-
autotools = self._configure_autotools()
54+
apply_conandata_patches(self)
55+
autotools = Autotools(self)
56+
autotools.configure()
6657
autotools.make()
6758

6859
def package(self):
69-
self.copy("LICENSE.LGPL2.1", dst="licenses", src=self._source_subfolder)
70-
autotools = self._configure_autotools()
60+
copy(self, "LICENSE.LGPL2.1", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
61+
autotools = Autotools(self)
7162
autotools.install()
72-
tools.rmdir(os.path.join(self.package_folder, "bin"))
73-
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
74-
tools.rmdir(os.path.join(self.package_folder, "share"))
75-
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la")
63+
rmdir(self, os.path.join(self.package_folder, "bin"))
64+
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
65+
rmdir(self, os.path.join(self.package_folder, "share"))
66+
rm(self, "*.la", os.path.join(self.package_folder, "lib"))
7667

7768
def package_info(self):
69+
self.cpp_info.set_property("pkg_config_name", "numa")
7870
self.cpp_info.libs = ["numa"]
79-
self.cpp_info.names["pkg_config"] = "numa"
8071
self.cpp_info.system_libs = ["dl", "pthread"]
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
cmake_minimum_required(VERSION 3.1)
2-
project(test_package)
2+
project(test_package LANGUAGES C)
33

4-
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5-
conan_basic_setup()
4+
find_package(libnuma REQUIRED CONFIG)
65

76
add_executable(${PROJECT_NAME} test_package.c)
8-
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
7+
target_link_libraries(${PROJECT_NAME} PRIVATE libnuma::libnuma)
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1+
from conan import ConanFile
2+
from conan.tools.build import can_run
3+
from conan.tools.cmake import CMake, cmake_layout
14
import os
25

3-
from conans import ConanFile, CMake, tools
46

57
class TestPackageConan(ConanFile):
6-
settings = "os", "compiler", "build_type", "arch"
7-
generators = "cmake", "cmake_find_package"
8+
settings = "os", "arch", "compiler", "build_type"
9+
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
10+
test_type = "explicit"
11+
12+
def layout(self):
13+
cmake_layout(self)
14+
15+
def requirements(self):
16+
self.requires(self.tested_reference_str)
817

918
def build(self):
1019
cmake = CMake(self)
1120
cmake.configure()
1221
cmake.build()
1322

1423
def test(self):
15-
if not tools.cross_building(self.settings):
16-
bin_path = os.path.join("bin", "test_package")
17-
self.run(bin_path, run_environment=True)
24+
if can_run(self):
25+
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
26+
self.run(bin_path, env="conanrun")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
project(test_package)
3+
4+
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5+
conan_basic_setup(TARGETS)
6+
7+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
8+
${CMAKE_CURRENT_BINARY_DIR}/test_package)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from conans import ConanFile, CMake, tools
2+
import os
3+
4+
5+
class TestPackageConan(ConanFile):
6+
settings = "os", "arch", "compiler", "build_type"
7+
generators = "cmake", "cmake_find_package_multi"
8+
9+
def build(self):
10+
cmake = CMake(self)
11+
cmake.configure()
12+
cmake.build()
13+
14+
def test(self):
15+
if not tools.cross_building(self):
16+
bin_path = os.path.join("bin", "test_package")
17+
self.run(bin_path, run_environment=True)

0 commit comments

Comments
 (0)