Repository: conan-io/conan-center-index

Issue:
[request] <METIS>/<5.1.0>
### Package Details
  * Package Name/Version: **METIS/5.1.0**
  * Website: **http://glaros.dtc.umn.edu/gkhome/metis/metis/overview**
  * Source code: **http://glaros.dtc.umn.edu/gkhome/metis/metis/download**


### Description Of The Library / Tool

From their home page:

> METIS is a set of serial programs for partitioning graphs, partitioning finite element meshes, and producing fill reducing orderings for sparse matrices.

There are two relevant projects to have a Conan METIS package [here](https://github.com/scibuilder/metis) and [here](https://github.com/tuncb/conan-metis).


Discussion:

Resolving patch:
diff --git a/recipes/metis/all/conanfile.py b/recipes/metis/all/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/metis/all/conanfile.py
@@ -0,0 +1,101 @@
+from conans import ConanFile, CMake, tools
+from conan.tools.files import apply_conandata_patches
+import os
+
+required_conan_version = ">=1.43.0"
+
+
+class METISConan(ConanFile):
+    name = "metis"
+    license = "Apache-2.0"
+    url = "https://github.com/conan-io/conan-center-index"
+    homepage = "https://github.com/KarypisLab/METIS"
+    description = "set of serial programs for partitioning graphs," \
+                  " partitioning finite element meshes, and producing" \
+                  " fill reducing orderings for sparse matrices"
+    topics = ("karypislab", "graph", "partitioning-algorithms")
+    settings = "os", "arch", "compiler", "build_type"
+    options = {
+        "shared": [True, False],
+        "fPIC": [True, False],
+    }
+    default_options = {
+        "shared": False,
+        "fPIC": True,
+    }
+    generators = "cmake", "cmake_find_package"
+    _cmake = None
+
+    @property
+    def _source_subfolder(self):
+        return "source_subfolder"
+
+    @property
+    def _build_subfolder(self):
+        return "build_subfolder"
+
+    @property
+    def _is_msvc(self):
+        return str(self.settings.compiler) in ["Visual Studio", "msvc"]
+
+    @property
+    def _is_mingw(self):
+        return self.settings.os == "Windows" and self.settings.compiler == "gcc"
+
+    def export_sources(self):
+        self.copy("CMakeLists.txt")
+        for patch in self.conan_data.get("patches", {}).get(self.version, []):
+            self.copy(patch["patch_file"])
+
+    def config_options(self):
+        if self.settings.os == "Windows":
+            del self.options.fPIC
+
+    def configure(self):
+        if self.options.shared:
+            del self.options.fPIC
+        del self.settings.compiler.libcxx
+        del self.settings.compiler.cppstd
+
+    def requirements(self):
+        self.requires("gklib/5.1.1")
+
+    def source(self):
+        tools.get(**self.conan_data["sources"][self.version],
+                  destination=self._source_subfolder, strip_root=True)
+
+    def _patch_sources(self):
+        apply_conandata_patches(self)
+
+    def _configure_cmake(self):
+        if not self._cmake:
+            self._cmake = CMake(self)
+            self._cmake.definitions["CMAKE_POLICY_DEFAULT_CMP0042"] = "NEW"
+            self._cmake.definitions["SHARED"] = self.options.shared
+            self._cmake.definitions["METIS_INSTALL"] = True
+            self._cmake.definitions["ASSERT"] = self.settings.build_type == "Debug"
+            self._cmake.definitions["ASSERT2"] = self.settings.build_type == "Debug"
+            self._cmake.definitions["METIS_IDX64"] = True
+            self._cmake.definitions["METIS_REAL64"] = True
+            self._cmake.configure(build_folder=self._build_subfolder)
+        return self._cmake
+
+    def build(self):
+        self._patch_sources()
+        cmake = self._configure_cmake()
+        cmake.build()
+
+    def package(self):
+        cmake = self._configure_cmake()
+        cmake.install()
+        self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
+
+    def package_info(self):
+        self.cpp_info.libs = ["metis"]
+        self.cpp_info.requires.append("gklib::gklib")
+        if self.settings.os in ["Linux", "FreeBSD"]:
+            self.cpp_info.system_libs.append("m")
+        if self._is_msvc or self._is_mingw:
+            self.cpp_info.defines.append("USE_GKREGEX")
+        if self._is_msvc:
+            self.cpp_info.defines.append("__thread=__declspec(thread)")


Test patch:
diff --git a/recipes/metis/all/test_package/CMakeLists.txt b/recipes/metis/all/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/metis/all/test_package/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.15)
+project(test_package CXX)
+
+include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+conan_basic_setup(TARGETS)
+
+find_package(metis REQUIRED CONFIG)
+
+add_executable(${PROJECT_NAME} test.cpp)
+target_link_libraries(${PROJECT_NAME} metis::metis)
diff --git a/recipes/metis/all/test_package/conanfile.py b/recipes/metis/all/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/metis/all/test_package/conanfile.py
@@ -0,0 +1,24 @@
+from conans import ConanFile, CMake, tools
+import os
+
+
+class TestPackageConan(ConanFile):
+    settings = "os", "compiler", "build_type", "arch"
+    generators = "cmake", "cmake_find_package_multi"
+
+    def build_requirements(self):
+        if self.settings.os == "Macos" and self.settings.arch == "armv8":
+            # Attempting to use @rpath without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being
+            # set. This could be because you are using a Mac OS X version less than 10.5
+            # or because CMake's platform configuration is corrupt.
+            self.build_requires("cmake/3.20.1")
+
+    def build(self):
+        cmake = CMake(self)
+        cmake.configure()
+        cmake.build()
+
+    def test(self):
+        if not tools.cross_building(self):
+            bin_path = os.path.join("bin", "test_package")
+            self.run(bin_path, run_environment=True)
diff --git a/recipes/metis/all/test_package/test.cpp b/recipes/metis/all/test_package/test.cpp
new file mode 100644
--- /dev/null
+++ b/recipes/metis/all/test_package/test.cpp
@@ -0,0 +1,37 @@
+#include <metis.h>
+
+#include <cstddef>
+#include <iostream> 
+
+int main(){
+
+    idx_t nVertices = 6;
+    idx_t nEdges    = 7;
+    idx_t nWeights  = 1;
+    idx_t nParts    = 2;
+
+    idx_t objval;
+    idx_t part[6];
+
+    // Indexes of starting points in adjacent array
+    idx_t xadj[6+1] = {0,2,5,7,9,12,14};
+
+    // Adjacent vertices in consecutive index order
+    idx_t adjncy[2 * 7] = {1,3,0,4,2,1,5,0,4,3,1,5,4,2};
+
+    // Weights of vertices
+    // if all weights are equal then can be set to NULL
+    idx_t vwgt[6 * 1];
+
+    int ret = METIS_PartGraphKway(&nVertices,& nWeights, xadj, adjncy,
+                                  NULL, NULL, NULL, &nParts, NULL,
+                                  NULL, NULL, &objval, part);
+
+    std::cout << ret << std::endl;
+
+    for(unsigned part_i = 0; part_i < nVertices; part_i++){
+        std::cout << part_i << " " << part[part_i] << std::endl;
+    }
+
+    return 0;
+}