Skip to content

Commit

Permalink
(#22016) reflect-cpp: new recipe
Browse files Browse the repository at this point in the history
* Add reflect-cpp, locally tested

* Update to 0.5.0
Specify gcc 11.4 as minimum specifically

* Change to 0.6.0

* Change options from get_safe to direct check
  • Loading branch information
RazielXYZ authored Jan 6, 2024
1 parent 0e4c7f1 commit 2caea7e
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 0 deletions.
4 changes: 4 additions & 0 deletions recipes/reflect-cpp/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"0.6.0":
url: "https://github.com/getml/reflect-cpp/archive/v0.6.0.tar.gz"
sha256: "D8231B91989397A67E841B56A0673FDCDF969DBE956D54BB629F14100B030664"
92 changes: 92 additions & 0 deletions recipes/reflect-cpp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.files import get, copy, export_conandata_patches, apply_conandata_patches
from conan.tools.build import check_min_cppstd
from conan.tools.scm import Version
from conan.tools.layout import basic_layout
import os

required_conan_version = ">=1.51.1"

class ReflectCppConan(ConanFile):
name = "reflect-cpp"
description = "C++-20 library for fast serialization, deserialization and validation using reflection"
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/getml/reflect-cpp"
topics = ("reflection", "serialization", "memory", "json", "xml", "flatbuffers", "header-only")
package_type = "header-library"
settings = "os", "arch", "compiler", "build_type"
options = {
"with_json" : [True, False],
"with_xml" : [True, False],
"with_flatbuffers" : [True, False],
"with_yaml": [True, False],
}
default_options = {
"with_json" : False,
"with_xml" : False,
"with_flatbuffers" : False,
"with_yaml" : False,
}

@property
def _min_cppstd(self):
return 20

@property
def _compilers_minimum_version(self):
return {
"Visual Studio": "17",
"msvc": "193",
"gcc": "11.4",
"clang": "16",
"apple-clang": "15",
}

def export_sources(self):
export_conandata_patches(self)

def layout(self):
basic_layout(self, src_folder="src")

def requirements(self):
if self.options.with_json:
self.requires("yyjson/0.8.0", transitive_headers=True)
if self.options.with_xml:
self.requires("pugixml/1.14", transitive_headers=True)
if self.options.with_flatbuffers:
self.requires("flatbuffers/23.5.26", transitive_headers=True)
if self.options.with_yaml:
self.requires("yaml-cpp/0.8.0", transitive_headers=True)

def package_id(self):
self.info.clear()

def validate(self):
if self.settings.get_safe("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 build(self):
apply_conandata_patches(self)

def package(self):
copy(self, pattern="LICENSE*", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
copy(
self,
pattern="*.hpp",
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 = []
8 changes: 8 additions & 0 deletions recipes/reflect-cpp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.12)
project(test_package LANGUAGES CXX)

find_package(reflect-cpp REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE reflect-cpp::reflect-cpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
26 changes: 26 additions & 0 deletions recipes/reflect-cpp/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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 requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

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")
15 changes: 15 additions & 0 deletions recipes/reflect-cpp/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <string>
#include <rfl.hpp>

struct TestStruct {
int x;
std::string name;
};

int main(void) {
for (const auto& f : rfl::fields<TestStruct>()) {
(void) f.name();
(void) f.type();
}
return 0;
}
9 changes: 9 additions & 0 deletions recipes/reflect-cpp/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.12)

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/)
18 changes: 18 additions & 0 deletions recipes/reflect-cpp/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions recipes/reflect-cpp/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"0.6.0":
folder: all

0 comments on commit 2caea7e

Please sign in to comment.