(#14546) zpp_bits: add recipe

* zpp_bits: add recipe

* add test_v1_package CMakeLists

* fix compiler version check

* fix variable name

* fix copy pattern for headers
This commit is contained in:
toge
2022-12-13 02:05:52 +09:00
committed by GitHub
parent 80a05d39b9
commit 92af359335
8 changed files with 163 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
sources:
"4.1.2":
url: "https://github.com/eyalz800/zpp_bits/archive/refs/tags/v4.4.12.tar.gz"
sha256: "0060c36d394ab1fb340120a7d14e45657a72419fd1745426e75d820980fa095a"

View File

@@ -0,0 +1,72 @@
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 is_msvc, check_min_vs
import os
required_conan_version = ">=1.52.0"
class ZppBitsConan(ConanFile):
name = "zpp_bits"
description = "A lightweight C++20 serialization and RPC library"
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/eyalz800/zpp_bits"
topics = ("serialization", "rpc", "header-only")
settings = "os", "arch", "compiler", "build_type"
no_copy_source = True
@property
def _min_cppstd(self):
return 20
@property
def _compilers_minimum_version(self):
return {
"gcc": "11",
"clang": "12",
"apple-clang": "13.1",
}
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, 193)
if not is_msvc(self):
def loose_lt_semver(v1, v2):
lv1 = [int(v) for v in v1.split(".")]
lv2 = [int(v) for v in v2.split(".")]
min_length = min(len(lv1), len(lv2))
return lv1[:min_length] < lv2[:min_length]
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and loose_lt_semver(str(self.settings.compiler.version), minimum_version):
raise ConanInvalidConfiguration(
f"{self.name} {self.version} 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="zpp_bits.h",
dst=os.path.join(self.package_folder, "include"),
src=self.source_folder,
)
def package_info(self):
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []

View File

@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.12)
project(test_package LANGUAGES CXX)
find_package(zpp_bits REQUIRED CONFIG)
add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE zpp_bits::zpp_bits)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)

View File

@@ -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")

View File

@@ -0,0 +1,24 @@
#include <string>
#include <iostream>
#include "zpp_bits.h"
struct person {
std::string name;
int age{};
};
int main(void) {
auto [data, in, out] = zpp::bits::data_in_out();
out(person{"Person1", 25}, person{"Person2", 35});
person p1, p2;
in(p1, p2);
std::cout << p1.name << " : " << p1.age << "\n";
std::cout << p2.name << " : " << p2.age << "\n";
return 0;
}

View File

@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)

View File

@@ -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)

View File

@@ -0,0 +1,3 @@
versions:
"4.1.2":
folder: all