Repository: conan-io/conan-center-index

Issue:
[request] scip/8.0.3
### Package Details
  * Package Name/Version: **scip/8.0.3**
  * Website: **https://www.scipopt.org/**
  * Source code: **https://github.com/scipopt/scip**

### Description Of The Library / Tool
Mixed Integer Linear Programming Solver

SCIP changed it license to an open-source license: Apache-2. version 8.0.3 is first version under the new license. SCIP is a very powerful non-commercial MIP solver.


Discussion:

Resolving patch:
diff --git a/recipes/scip/all/conanfile.py b/recipes/scip/all/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/scip/all/conanfile.py
@@ -0,0 +1,146 @@
+from conan import ConanFile
+from conan.tools.apple import fix_apple_shared_install_name
+from conan.tools.build import check_min_cppstd
+from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
+from conan.errors import ConanInvalidConfiguration
+from conan.tools.files import copy, get
+from conan.tools.microsoft import check_min_vs, is_msvc
+from conan.tools.scm import Version
+from os.path import join
+
+required_conan_version = ">=1.53.0"
+
+
+class SCIPConan(ConanFile):
+    name = "scip"
+    description = "SCIP mixed integer (nonlinear) programming solver"
+    license = "Apache-2.0"
+    url = "https://github.com/conan-io/conan-center-index"
+    homepage = "https://scipopt.org/"
+    topics = ("mip", "solver", "linear", "programming")
+    settings = "os", "arch", "compiler", "build_type"
+    package_type = "library"
+    options = {
+        "shared": [True, False],
+        "fPIC": [True, False],
+        "with_gmp": [True, False],
+        "with_tpi": [False, "omp", "tny"],
+        "with_sym": [False, "bliss"],
+    }
+    default_options = {
+        "shared": False,
+        "fPIC": True,
+        "with_gmp": True,
+        "with_tpi": False,
+        "with_sym": "bliss",
+    }
+
+    @property
+    def _min_cppstd(self):
+        return 14
+
+    @property
+    def _compilers_minimum_version(self):
+        return {
+            "gcc": "5",
+            "clang": "4",
+            "apple-clang": "7",
+        }
+
+    def validate(self):
+        if self.settings.compiler.cppstd:
+            check_min_cppstd(self, self._min_cppstd)
+        check_min_vs(self, 191)
+        if not is_msvc(self):
+            minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
+            if minimum_version and Version(self.settings.compiler.version) < minimum_version:
+                raise ConanInvalidConfiguration(
+                    f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
+                )
+        if is_msvc(self) and self.options.shared:
+            raise ConanInvalidConfiguration(f"{self.ref} can not be built as shared on Visual Studio and msvc.")
+        if self.options.shared and self.options.with_sym == "bliss":
+            raise ConanInvalidConfiguration("Bliss is not supported in shared mode.")
+        comp = self.settings.compiler
+        if self.options.with_sym == "bliss" and comp == 'clang' and comp.libcxx and comp.libcxx == 'libc++':
+            raise ConanInvalidConfiguration("Bliss does not support libc++.")
+        if self.dependencies["soplex"].options.with_gmp and not self.options.with_gmp:
+            raise ConanInvalidConfiguration("The options 'with_gmp' should be aligned with 'soplex:with_gmp' too.")
+
+    def source(self):
+        get(self, **self.conan_data["sources"][self.version], strip_root=True)
+
+    def config_options(self):
+        if self.settings.os == "Windows":
+            del self.options.fPIC
+
+    def requirements(self):
+        if self.options.with_gmp:
+            self.requires("gmp/6.2.1")
+        if self.options.with_sym == "bliss":
+            self.requires("bliss/0.77")
+        self.requires("soplex/6.0.3")
+        self.requires("zlib/1.2.13")
+
+    def configure(self):
+        self.options["soplex"].with_gmp = self.options.with_gmp
+        if self.options.shared:
+            self.options.rm_safe("fPIC")
+
+    def layout(self):
+        cmake_layout(self, src_folder="src")
+
+    @staticmethod
+    def _to_cmake(*arrays):
+        return ";".join(item.replace("\\", "/") for sublist in arrays for item in sublist)
+
+    def generate(self):
+        tc = CMakeToolchain(self)
+        tc.variables["SHARED"] = self.options.shared
+        tc.variables["READLINE"] = False  # required for interactive stuff
+        tc.variables["GMP"] = self.options.with_gmp
+        tc.variables["TPI"] = self.options.with_tpi or "none"
+        tc.variables["LPS"] = "spx"
+        tc.variables["SYM"] = self.options.with_sym or "none"
+        tc.variables["SOPLEX_INCLUDE_DIRS"] = self._to_cmake(self.dependencies["soplex"].cpp_info.includedirs)
+        if self.options.shared:
+            # CMakeLists accesses different variables for SoPlex depending on the SHARED option
+            tc.variables["SOPLEX_PIC_LIBRARIES"] = "soplex"
+        if self.dependencies["soplex"].options.with_boost:
+            # INFO: docu states BOOST_ROOT, yet that does not exist in CMakeLists
+            tc.variables["SOPLEX_INCLUDE_DIRS"] = self._to_cmake(
+                self.dependencies["soplex"].cpp_info.includedirs,
+                self.dependencies["boost"].cpp_info.includedirs
+            )
+        tc.variables["PAPILO"] = False  # LGPL
+        tc.variables["ZIMPL"] = False  # LPGL
+        tc.variables["IPOPT"] = False  # no such coin package on conan center yet
+        tc.generate()
+        deps = CMakeDeps(self)
+        deps.set_property("sopex", "cmake_file_name", "SOPEX")
+        deps.set_property("gmp", "cmake_file_name", "GMP")
+        deps.generate()
+
+    def build(self):
+        cmake = CMake(self)
+        cmake.configure()
+        cmake.build(target="libscip")
+
+    def package(self):
+        copy(self, pattern="LICENSE", src=self.source_folder, dst=join(self.package_folder, "licenses"))
+        # cmake install is not used as this requires the command line tools to be built, which we do not do
+        copy(self, pattern="*.h", src=join(self.source_folder, "src"), dst=join(self.package_folder, "include"))
+        copy(self, pattern="*.h", src=join(self.build_folder, "scip"), dst=join(self.package_folder, "include", "scip"))
+        if self.options.shared:
+            copy(self, pattern="*.so*", src=join(self.build_folder, "lib"), dst=join(self.package_folder, "lib"))
+            copy(self, pattern="*.dylib*", src=join(self.build_folder, "lib"), dst=join(self.package_folder, "lib"))
+        else:
+            copy(self, pattern="*.a", src=join(self.build_folder, "lib"), dst=join(self.package_folder, "lib"))
+            copy(self, pattern="*.lib", src=join(self.build_folder, "lib"), dst=join(self.package_folder, "lib"), keep_path=False)
+            copy(self, pattern="*.lib", src=self.build_folder, dst=join(self.package_folder, "lib"), keep_path=False)
+        fix_apple_shared_install_name(self)
+
+    def package_info(self):
+        self.cpp_info.libs = ["libscip" if is_msvc(self) else "scip"]
+        if self.options.with_tpi == "omp":
+            self.cpp_info.system_libs.append("-fopenmp")


Test patch:
diff --git a/recipes/scip/all/test_package/CMakeLists.txt b/recipes/scip/all/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/scip/all/test_package/CMakeLists.txt
@@ -0,0 +1,7 @@
+cmake_minimum_required(VERSION 3.8)
+project(test_package CXX)
+set(CMAKE_CXX_STANDARD 14)
+
+find_package(scip REQUIRED CONFIG)
+add_executable(${PROJECT_NAME} test_package.cpp)
+target_link_libraries(${PROJECT_NAME} PRIVATE scip::scip)
diff --git a/recipes/scip/all/test_package/conanfile.py b/recipes/scip/all/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/scip/all/test_package/conanfile.py
@@ -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 requirements(self):
+        self.requires(self.tested_reference_str)
+
+    def layout(self):
+        cmake_layout(self)
+
+    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")
diff --git a/recipes/scip/all/test_package/test_package.cpp b/recipes/scip/all/test_package/test_package.cpp
new file mode 100644
--- /dev/null
+++ b/recipes/scip/all/test_package/test_package.cpp
@@ -0,0 +1,12 @@
+#include <cstdlib>
+
+#include "scip/scip.h"
+
+
+int main() {
+      SCIP* scip;
+      SCIPcreate(&scip);
+      SCIPprintVersion(scip, NULL);
+      SCIPinfoMessage(scip, NULL, "\n");
+      return EXIT_SUCCESS;
+}