|
| 1 | +from conan import ConanFile |
| 2 | +from conan.errors import ConanInvalidConfiguration |
| 3 | +from conan.tools.build.cppstd import check_min_cppstd |
| 4 | +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout |
| 5 | +from conan.tools.files import copy |
| 6 | +from conan.tools.scm import Version |
| 7 | +import os |
| 8 | + |
| 9 | +required_conan_version = ">=2.0" |
| 10 | + |
| 11 | +class SparrowIPCRecipe(ConanFile): |
| 12 | + name = "sparrow-ipc" |
| 13 | + description = "C++20 library for memory-mapped serialization of Apache Arrow data." |
| 14 | + license = "BSD-3-Clause" |
| 15 | + author = "QuantStack" |
| 16 | + url = "https://github.com/QuantStack/sparrow-ipc" |
| 17 | + homepage = "https://github.com/QuantStack/sparrow-ipc" |
| 18 | + topics = ("arrow", "apache arrow", "columnar format", "dataframe", "ipc", "serialization", "deserialization", "flatbuffers") |
| 19 | + package_type = "library" |
| 20 | + settings = "os", "arch", "compiler", "build_type" |
| 21 | + exports_sources = "include/*", "src/*", "cmake/*", "CMakeLists.txt", "LICENSE" |
| 22 | + options = { |
| 23 | + "shared": [True, False], |
| 24 | + "fPIC": [True, False], |
| 25 | + "build_tests": [True, False], |
| 26 | + } |
| 27 | + default_options = { |
| 28 | + "shared": False, |
| 29 | + "fPIC": True, |
| 30 | + "build_tests": False, |
| 31 | + } |
| 32 | + |
| 33 | + _flatbuffers_version = "24.12.23" |
| 34 | + |
| 35 | + def config_options(self): |
| 36 | + if self.settings.os == "Windows": |
| 37 | + del self.options.fPIC |
| 38 | + |
| 39 | + def configure(self): |
| 40 | + if self.options.shared: |
| 41 | + self.options.rm_safe("fPIC") |
| 42 | + |
| 43 | + def requirements(self): |
| 44 | + self.requires("sparrow/1.0.0") |
| 45 | + self.requires(f"flatbuffers/{self._flatbuffers_version}") |
| 46 | + if self.options.get_safe("build_tests"): |
| 47 | + self.test_requires("doctest/2.4.12") |
| 48 | + |
| 49 | + def build_requirements(self): |
| 50 | + self.tool_requires("cmake/[>=3.28.1 <4.2.0]") |
| 51 | + self.tool_requires(f"flatbuffers/{self._flatbuffers_version}") |
| 52 | + |
| 53 | + @property |
| 54 | + def _min_cppstd(self): |
| 55 | + return 20 |
| 56 | + |
| 57 | + @property |
| 58 | + def _compilers_minimum_version(self): |
| 59 | + return { |
| 60 | + "apple-clang": "16", |
| 61 | + "clang": "18", |
| 62 | + "gcc": "12", |
| 63 | + "msvc": "194" |
| 64 | + } |
| 65 | + |
| 66 | + def validate(self): |
| 67 | + if self.settings.compiler.get_safe("cppstd"): |
| 68 | + check_min_cppstd(self, self._min_cppstd) |
| 69 | + |
| 70 | + minimum_version = self._compilers_minimum_version.get( |
| 71 | + str(self.settings.compiler), False) |
| 72 | + if minimum_version and Version(self.settings.compiler.version) < minimum_version: |
| 73 | + raise ConanInvalidConfiguration( |
| 74 | + f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support." |
| 75 | + ) |
| 76 | + |
| 77 | + def layout(self): |
| 78 | + cmake_layout(self, src_folder=".") |
| 79 | + |
| 80 | + def generate(self): |
| 81 | + deps = CMakeDeps(self) |
| 82 | + deps.generate() |
| 83 | + |
| 84 | + tc = CMakeToolchain(self) |
| 85 | + tc.variables["SPARROW_IPC_BUILD_SHARED"] = self.options.shared |
| 86 | + tc.variables["SPARROW_IPC_BUILD_TESTS"] = self.options.build_tests |
| 87 | + tc.generate() |
| 88 | + |
| 89 | + def build(self): |
| 90 | + cmake = CMake(self) |
| 91 | + cmake.configure() |
| 92 | + cmake.build() |
| 93 | + |
| 94 | + def package(self): |
| 95 | + copy(self, "LICENSE", |
| 96 | + dst=os.path.join(self.package_folder, "licenses"), |
| 97 | + src=self.source_folder) |
| 98 | + cmake = CMake(self) |
| 99 | + cmake.install() |
| 100 | + |
| 101 | + def package_info(self): |
| 102 | + self.cpp_info.libs = ["sparrow-ipc"] |
| 103 | + self.cpp_info.set_property("cmake_file_name", "sparrow-ipc") |
| 104 | + self.cpp_info.set_property("cmake_target_name", "sparrow-ipc::sparrow-ipc") |
0 commit comments