Repository: conan-io/conan-center-index

Issue:
[request] libnuma/2.0.13
### Package Details
  * Package Name/Version: **numa/2.0.13**
  * Source code: **https://github.com/numactl/numactl**


### Description Of The Library / Tool

The libnuma library offers a simple programming interface to the NUMA (Non Uniform Memory Access) policy supported by the Linux kernel.

- This package is an optional requirement for Facebook Rocksdb (#410)
- It contains an executable, but I think it can be excluded from the package. Out proposal is use the library only.



Discussion:

Resolving patch:
diff --git a/recipes/libnuma/all/conanfile.py b/recipes/libnuma/all/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/libnuma/all/conanfile.py
@@ -0,0 +1,80 @@
+import os
+
+from conans import ConanFile, AutoToolsBuildEnvironment, tools
+from conans.errors import ConanInvalidConfiguration
+
+required_conan_version = ">=1.29.1"
+
+class LibnumaConan(ConanFile):
+    name = "libnuma"
+    description = "NUMA support for Linux."
+    license = "LGPL-2.1-or-later"
+    topics = ("conan", "numa")
+    homepage = "https://github.com/numactl/numactl"
+    url = "https://github.com/conan-io/conan-center-index"
+    settings = "os", "arch", "compiler", "build_type"
+    options = {
+        "shared": [True, False],
+        "fPIC": [True, False],
+    }
+    default_options = {
+        "shared": False,
+        "fPIC": True,
+    }
+    exports_sources = "patches/**"
+
+    _autotools = None
+
+    @property
+    def _source_subfolder(self):
+        return "source_subfolder"
+
+    def configure(self):
+        if self.settings.os != "Linux":
+            raise ConanInvalidConfiguration("{} is only supported on Linux".format(self.name))
+        del self.settings.compiler.libcxx
+        del self.settings.compiler.cppstd
+        if self.options.shared:
+            del self.options.fPIC
+
+    def _patch_sources(self):
+        for patch in self.conan_data.get("patches",{}).get(self.version, []):
+            tools.patch(**patch)
+
+    def source(self):
+        tools.get(**self.conan_data["sources"][self.version])
+        os.rename("numactl-" + self.version, self._source_subfolder)
+
+    def _configure_autotools(self):
+        if self._autotools:
+            return self._autotools
+
+        self._autotools = AutoToolsBuildEnvironment(self)
+
+        args = []
+        if self.options.shared:
+            args.extend(["--disable-static", "--enable-shared"])
+        else:
+            args.extend(["--disable-shared", "--enable-static"])
+
+        self._autotools.configure(args=args, configure_dir=self._source_subfolder)
+        return self._autotools
+
+    def build(self):
+        self._patch_sources()
+        autotools = self._configure_autotools()
+        autotools.make()
+
+    def package(self):
+        self.copy("LICENSE.LGPL2.1", dst="licenses", src=self._source_subfolder)
+        autotools = self._configure_autotools()
+        autotools.install()
+        tools.rmdir(os.path.join(self.package_folder, "bin"))
+        tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
+        tools.rmdir(os.path.join(self.package_folder, "share"))
+        tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la")
+
+    def package_info(self):
+        self.cpp_info.libs = ["numa"]
+        self.cpp_info.names["pkg_config"] = "numa"
+        self.cpp_info.system_libs = ["dl", "pthread"]


Test patch:
diff --git a/recipes/libnuma/all/test_package/CMakeLists.txt b/recipes/libnuma/all/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/libnuma/all/test_package/CMakeLists.txt
@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.1)
+project(test_package)
+
+include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+conan_basic_setup()
+
+add_executable(${PROJECT_NAME} test_package.c)
+target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
diff --git a/recipes/libnuma/all/test_package/conanfile.py b/recipes/libnuma/all/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/libnuma/all/test_package/conanfile.py
@@ -0,0 +1,17 @@
+import os
+
+from conans import ConanFile, CMake, tools
+
+class TestPackageConan(ConanFile):
+    settings = "os", "compiler", "build_type", "arch"
+    generators = "cmake", "cmake_find_package"
+
+    def build(self):
+        cmake = CMake(self)
+        cmake.configure()
+        cmake.build()
+
+    def test(self):
+        if not tools.cross_building(self.settings):
+            bin_path = os.path.join("bin", "test_package")
+            self.run(bin_path, run_environment=True)
diff --git a/recipes/libnuma/all/test_package/test_package.c b/recipes/libnuma/all/test_package/test_package.c
new file mode 100644
--- /dev/null
+++ b/recipes/libnuma/all/test_package/test_package.c
@@ -0,0 +1,5 @@
+#include <numa.h>
+
+int main() {
+  (void)numa_available();
+}