diff --git a/recipes/reflect-cpp/all/conandata.yml b/recipes/reflect-cpp/all/conandata.yml new file mode 100644 index 0000000000000..e8f0dda436088 --- /dev/null +++ b/recipes/reflect-cpp/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "0.6.0": + url: "https://github.com/getml/reflect-cpp/archive/v0.6.0.tar.gz" + sha256: "D8231B91989397A67E841B56A0673FDCDF969DBE956D54BB629F14100B030664" diff --git a/recipes/reflect-cpp/all/conanfile.py b/recipes/reflect-cpp/all/conanfile.py new file mode 100644 index 0000000000000..4952fc02f03a6 --- /dev/null +++ b/recipes/reflect-cpp/all/conanfile.py @@ -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 = [] diff --git a/recipes/reflect-cpp/all/test_package/CMakeLists.txt b/recipes/reflect-cpp/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..66b58d7b20ff5 --- /dev/null +++ b/recipes/reflect-cpp/all/test_package/CMakeLists.txt @@ -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) diff --git a/recipes/reflect-cpp/all/test_package/conanfile.py b/recipes/reflect-cpp/all/test_package/conanfile.py new file mode 100644 index 0000000000000..a9fb96656f203 --- /dev/null +++ b/recipes/reflect-cpp/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 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") diff --git a/recipes/reflect-cpp/all/test_package/test_package.cpp b/recipes/reflect-cpp/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..04e4309cba5ea --- /dev/null +++ b/recipes/reflect-cpp/all/test_package/test_package.cpp @@ -0,0 +1,15 @@ +#include +#include + +struct TestStruct { + int x; + std::string name; +}; + +int main(void) { + for (const auto& f : rfl::fields()) { + (void) f.name(); + (void) f.type(); + } + return 0; +} diff --git a/recipes/reflect-cpp/all/test_v1_package/CMakeLists.txt b/recipes/reflect-cpp/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..9652e22fc19d5 --- /dev/null +++ b/recipes/reflect-cpp/all/test_v1_package/CMakeLists.txt @@ -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/) diff --git a/recipes/reflect-cpp/all/test_v1_package/conanfile.py b/recipes/reflect-cpp/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..5a05af3c2dfd2 --- /dev/null +++ b/recipes/reflect-cpp/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/reflect-cpp/config.yml b/recipes/reflect-cpp/config.yml new file mode 100644 index 0000000000000..7d9ba9dbc8ac9 --- /dev/null +++ b/recipes/reflect-cpp/config.yml @@ -0,0 +1,3 @@ +versions: + "0.6.0": + folder: all