Repository: conan-io/conan-center-index

Issue:
[request] libboxes/0.1.1
### Package Name/Version

libboxes/0.1.1

### Webpage

https://gitlab.com/twdev_projects/boxes

### Source code

https://gitlab.com/twdev_projects/boxes

### Description of the library/tool

Boxes is a set of frequently used containers built on top of STL.


Discussion:

Resolving patch:
diff --git a/recipes/libboxes/all/conanfile.py b/recipes/libboxes/all/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/libboxes/all/conanfile.py
@@ -0,0 +1,95 @@
+from conan import ConanFile
+from conan.errors import ConanInvalidConfiguration
+from conan.tools.build import check_min_cppstd
+from conan.tools.files import copy, export_conandata_patches, get, rmdir
+from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
+from conan.tools.scm import Version
+import os
+
+class libboxesRecipe(ConanFile):
+    name = "libboxes"
+    description = "Boxes is a set of frequently used containers built on top of STL"
+
+    license = "BSD-3-Clause"
+    url = "https://github.com/conan-io/conan-center-index"
+    homepage = "https://gitlab.com/twdev_projects/boxes"
+
+    topics = ("container", "utility")
+    package_type = "library"
+    settings = "os", "arch", "compiler", "build_type"
+    options = {"shared": [True, False], "fPIC": [True, False]}
+    default_options = {"shared": False, "fPIC": True}
+
+    @property
+    def _min_cppstd(self):
+        return 20
+
+    @property
+    def _compilers_minimum_version(self):
+        return {
+            "apple-clang": "13",
+            "clang": "14",
+            "gcc": "11",
+        }
+
+    def export_sources(self):
+        export_conandata_patches(self)
+
+    def config_options(self):
+        if self.settings.os == "Windows":
+            del self.options.fPIC
+
+    def configure(self):
+        if self.options.shared:
+            self.options.rm_safe("fPIC")
+
+    def layout(self):
+        cmake_layout(self, src_folder="src")
+
+    def requirements(self):
+        self.requires("xxhash/0.8.2", transitive_headers=True)
+
+    def validate(self):
+        if self.settings.os == "Windows":
+            raise ConanInvalidConfiguration("libboxes does not support Windows yet")
+
+        if self.settings.compiler.cppstd:
+            check_min_cppstd(self, self._min_cppstd)
+
+        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."
+            )
+
+    def source(self):
+        get(self, **self.conan_data["sources"][self.version], strip_root=True)
+
+    def generate(self):
+        tc = CMakeToolchain(self)
+        tc.cache_variables["BUILD_SHARED_LIBS"] = self.options.shared
+        tc.cache_variables["BUILD_EXAMPLES"] = "OFF"
+        tc.generate()
+
+        tc = CMakeDeps(self)
+        tc.generate()
+
+    def build(self):
+        cmake = CMake(self)
+        cmake.configure()
+        cmake.build()
+
+    def package(self):
+        copy(self, "LICENSE.md", self.source_folder, os.path.join(self.package_folder, "licenses"))
+        cmake = CMake(self)
+        cmake.install()
+        rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
+        rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
+
+    def package_info(self):
+        self.cpp_info.set_property("cmake_file_name", "libboxes")
+        self.cpp_info.set_property("cmake_target_name", "libboxes::libboxes")
+        self.cpp_info.set_property("pkg_config_name", "libboxes")
+
+        if self.settings.os in ["Linux", "Android", "FreeBSD", "SunOS", "AIX"]:
+            self.cpp_info.system_libs.append("m")


Test patch:
diff --git a/recipes/libboxes/all/test_package/CMakeLists.txt b/recipes/libboxes/all/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/libboxes/all/test_package/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.15)
+project(PackageTest CXX)
+
+find_package(libboxes CONFIG REQUIRED)
+
+
+
+add_executable(example src/example.cpp)
+target_link_libraries(example libboxes::libboxes)
+target_compile_features(example PRIVATE cxx_std_20)
diff --git a/recipes/libboxes/all/test_package/conanfile.py b/recipes/libboxes/all/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/libboxes/all/test_package/conanfile.py
@@ -0,0 +1,26 @@
+import os
+
+from conan import ConanFile
+from conan.tools.cmake import CMake, cmake_layout
+from conan.tools.build import can_run
+
+
+class libboxesTestConan(ConanFile):
+    settings = "os", "compiler", "build_type", "arch"
+    generators = "CMakeDeps", "CMakeToolchain"
+
+    def requirements(self):
+        self.requires(self.tested_reference_str)
+
+    def build(self):
+        cmake = CMake(self)
+        cmake.configure()
+        cmake.build()
+
+    def layout(self):
+        cmake_layout(self)
+
+    def test(self):
+        if can_run(self):
+            cmd = os.path.join(self.cpp.build.bindir, "example")
+            self.run(cmd, env="conanrun")
diff --git a/recipes/libboxes/all/test_package/src/example.cpp b/recipes/libboxes/all/test_package/src/example.cpp
new file mode 100644
--- /dev/null
+++ b/recipes/libboxes/all/test_package/src/example.cpp
@@ -0,0 +1,16 @@
+#include <boxes/boxes.hpp>
+
+#include <iostream>
+
+int main() {
+  boxes::RingBuffer<int, 8> buf;
+  buf.push_back(123);
+
+  if (buf.size() == 1 && buf.front() == 123) {
+    std::cout << "libboxes::RingBuffer works!" << std::endl;
+  } else {
+    std::cout << "libboxes::RingBuffer is broken!" << std::endl;
+  }
+
+  return 0;
+}