From 47acdfd85bfb51e4f86465e89f0e1217e835d3bd Mon Sep 17 00:00:00 2001
From: Joscha Schmiedt <joscha@schmiedt.dev>
Date: Mon, 3 Jun 2024 23:08:59 +0200
Subject: [PATCH] WIP: Migrate to Conan 2 (issue #73)

---
 conanfile.py | 64 ++++++++++++++++++++++++++++++++--------------------
 1 file changed, 40 insertions(+), 24 deletions(-)

diff --git a/conanfile.py b/conanfile.py
index 906ba04..f3fc760 100644
--- a/conanfile.py
+++ b/conanfile.py
@@ -1,4 +1,7 @@
-from conans import ConanFile, CMake, tools
+from conan import ConanFile
+from conan.tools.cmake import CMake, cmake_layout, CMakeDeps, CMakeToolchain
+from conan.tools.files import copy
+from conan.errors import ConanInvalidConfiguration
 
 
 class CaosdbConan(ConanFile):
@@ -20,48 +23,61 @@ class CaosdbConan(ConanFile):
         "fPIC": True,
         "build_acm": False,
     }
-    generators = "cmake"
-    requires = [
-        ("grpc/1.48.0"),
-    ]
-    build_requires = [
-        ("boost/1.78.0"),
-        ("gtest/1.11.0"),
-    ]
+
     exports = ("*.cmake", "*CMakeLists.txt", "*.in",
                "*.h", "*.proto", "*.c", "*.cpp",
                "*.rst", "*.md",
-              )
+               )
     exports_sources = "src", "doc", "include", "test", "cmake", "proto"
 
+    def build_requirements(self):
+        self.tool_requires("protobuf/3.21.12")
+        self.tool_requires("cmake/[>=3.13]")
+        self.tool_requires("boost/1.78.0")
+        self.test_requires("gtest/1.11.0")
+        self.requires("grpc/1.48.4")
+
     def config_options(self):
         if self.settings.os == "Windows":
-            del self.options.fPIC
+            self.options.rm_safe("fPIC")
         self.options["boost"].without_python = True
         self.options["boost"].filesystem_version = "3"
 
-    # def source(self):
-        # self.run("git clone https://gitlab.indiscale.com/caosdb/src/caosdb-cpplib.git")
-        # self.run("cd caosdb-cpplib && git submodule update --init")
+    def generate(self):
+
+        tc = CMakeToolchain(self)
+        # This writes the "conan_toolchain.cmake"
+        tc.generate()
+
+        cmake = CMakeDeps(self)
+        cmake.generate()
+
+        copy(self, pattern="protoc*", dst="build_tools", src="bin")
+        copy(self, pattern="grpc_cpp_plugin*", dst="build_tools", src="bin")
 
-    def imports(self):
-        self.copy("protoc*", "build_tools", "bin")
-        self.copy("grpc_cpp_plugin*", "build_tools", "bin")
+    def layout(self):
+        cmake_layout(self, src_folder=".")
 
     def build(self):
         cmake = CMake(self)
         if self.options.build_acm:
             cmake.definitions["BUILD_ACM"] = "On"
-
-        cmake.configure(source_folder="")
+        cmake.configure()
         cmake.build()
 
     def package(self):
-        self.copy("*.h", dst="include", src="include")
-        self.copy("*.dll", dst="bin", keep_path=False)
-        self.copy("*.so", dst="lib", keep_path=False)
-        self.copy("*.dylib", dst="lib", keep_path=False)
-        self.copy("*.a", dst="lib", keep_path=False)
+        cmake = CMake(self)
+        cmake.install()
+
+        copy(self, pattern="*.h", dst="include", src="include")
+        copy(self, pattern="*.dll", dst="bin", keep_path=False)
+        copy(self, pattern="*.so", dst="lib", keep_path=False)
+        copy(self, pattern="*.dylib", dst="lib", keep_path=False)
+        copy(self, pattern="*.a", dst="lib", keep_path=False)
 
     def package_info(self):
         self.cpp_info.libs = ["caosdb", "ccaosdb"]
+
+    def validate(self):
+        if self.settings.os not in ("Linux", "Windows"):
+            raise ConanInvalidConfiguration(f"{self.settings.os} is currently not supported")
-- 
GitLab