diff --git a/recipes/alpaca/all/conandata.yml b/recipes/alpaca/all/conandata.yml new file mode 100644 index 0000000000000..4be0a369c7f9a --- /dev/null +++ b/recipes/alpaca/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "0.2.1": + url: "https://github.com/p-ranav/alpaca/archive/refs/tags/v0.2.1.tar.gz" + sha256: "05d49a2dc9c6a9e07c0cbc4e26caec273a8666270c82d7c3f0ede4f3a9258f4e" diff --git a/recipes/alpaca/all/conanfile.py b/recipes/alpaca/all/conanfile.py new file mode 100644 index 0000000000000..a7227d4427d29 --- /dev/null +++ b/recipes/alpaca/all/conanfile.py @@ -0,0 +1,69 @@ +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.build import check_min_cppstd +from conan.tools.files import get, copy +from conan.tools.layout import basic_layout +from conan.tools.microsoft import check_min_vs, is_msvc +from conan.tools.scm import Version +import os + + +required_conan_version = ">=1.52.0" + + +class AlpacaConan(ConanFile): + name = "alpaca" + description = "Serialization library written in C++17 - Pack C++ structs into a compact byte-array without any macros or boilerplate code" + license = "MIT" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://github.com/p-ranav/alpaca" + topics = ("reflection", "checksum", "serialization", "header-only") + settings = "os", "arch", "compiler", "build_type" + no_copy_source = True + + @property + def _min_cppstd(self): + return 17 + + @property + def _compilers_minimum_version(self): + return { + "gcc": "8", + "clang": "7", + "apple-clang": "12", + } + + def layout(self): + basic_layout(self, src_folder="src") + + def package_id(self): + self.info.clear() + + def validate(self): + if self.settings.compiler.get_safe("cppstd"): + check_min_cppstd(self, self._min_cppstd) + check_min_vs(self, 192) + 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." + ) + + def source(self): + get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True) + + def package(self): + copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) + copy( + self, + pattern="*.h", + dst=os.path.join(self.package_folder, "include"), + src=os.path.join(self.source_folder, "include"), + ) + + def package_info(self): + self.cpp_info.bindirs = [] + self.cpp_info.libdirs = [] + + self.cpp_info.set_property("pkg_config_name", "alpaca") diff --git a/recipes/alpaca/all/test_package/CMakeLists.txt b/recipes/alpaca/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..790a5eaae638a --- /dev/null +++ b/recipes/alpaca/all/test_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.8) +project(test_package LANGUAGES CXX) + +find_package(alpaca REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} PRIVATE alpaca::alpaca) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) diff --git a/recipes/alpaca/all/test_package/conanfile.py b/recipes/alpaca/all/test_package/conanfile.py new file mode 100644 index 0000000000000..e845ae751a301 --- /dev/null +++ b/recipes/alpaca/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_layout, CMake +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" + test_type = "explicit" + + def layout(self): + cmake_layout(self) + + def requirements(self): + self.requires(self.tested_reference_str) + + 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/alpaca/all/test_package/test_package.cpp b/recipes/alpaca/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..0134e1d6e0d2d --- /dev/null +++ b/recipes/alpaca/all/test_package/test_package.cpp @@ -0,0 +1,35 @@ +#include + +struct Config { + std::string device; + std::pair resolution; + std::array K_matrix; + std::vector distortion_coeffients; + std::map> parameters; +}; + +int main() { + // Construct the object + Config c{"/dev/video0", {640, 480}, + {223.28249888247538, 0.0, 152.30570853111396, + 0.0, 223.8756535707556, 124.5606000035353, + 0.0, 0.0, 1.0}, + {-0.44158343539568284, 0.23861463831967872, 0.0016338407443826572, + 0.0034950038632981604, -0.05239245892096022}, + {{"start_server", bool{true}}, + {"max_depth", uint16_t{5}}, + {"model_path", std::string{"foo/bar.pt"}}}}; + + // Serialize + std::vector bytes; + auto bytes_written = alpaca::serialize(c, bytes); + + // Deserialize + std::error_code ec; + auto object = alpaca::deserialize(bytes, ec); + if (ec) { + return 1; + } + return 0; +} + diff --git a/recipes/alpaca/all/test_v1_package/CMakeLists.txt b/recipes/alpaca/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..0aeb3e1d92584 --- /dev/null +++ b/recipes/alpaca/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.8) +project(test_package LANGUAGES C) # if the project is pure C +project(test_package LANGUAGES CXX) # if the project uses c++ + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/ + ${CMAKE_CURRENT_BINARY_DIR}/test_package/) diff --git a/recipes/alpaca/all/test_v1_package/conanfile.py b/recipes/alpaca/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..5a05af3c2dfd2 --- /dev/null +++ b/recipes/alpaca/all/test_v1_package/conanfile.py @@ -0,0 +1,18 @@ +from conans import ConanFile, CMake +from conan.tools.build import cross_building +import os + + +class TestPackageV1Conan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "cmake", "cmake_find_package_multi" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not cross_building(self): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True) diff --git a/recipes/alpaca/config.yml b/recipes/alpaca/config.yml new file mode 100644 index 0000000000000..f975c1e3261f7 --- /dev/null +++ b/recipes/alpaca/config.yml @@ -0,0 +1,3 @@ +versions: + "0.2.1": + folder: all