diff --git a/recipes/reflect-cpp/all/conandata.yml b/recipes/reflect-cpp/all/conandata.yml index ad65b35cf4e50..cb9c3acfa130e 100644 --- a/recipes/reflect-cpp/all/conandata.yml +++ b/recipes/reflect-cpp/all/conandata.yml @@ -1,13 +1,4 @@ sources: - "0.11.1": - url: "https://github.com/getml/reflect-cpp/archive/v0.11.1.tar.gz" - sha256: "e45f112fb3f14507a4aa53b99ae2d4ab6a4e7b2d5f04dd06fec00bf7faa7bbdc" - "0.11.0": - url: "https://github.com/getml/reflect-cpp/archive/v0.11.0.tar.gz" - sha256: "85f66939608acacf66dc782529af0c5a36b7d695c55b310b10c49700251b6221" - "0.10.0": - url: "https://github.com/getml/reflect-cpp/archive/v0.10.0.tar.gz" - sha256: "d2c8876d993ddc8c57c5804e767786bdb46a2bdf1a6cd81f4b14f57b1552dfd7" - "0.6.0": - url: "https://github.com/getml/reflect-cpp/archive/v0.6.0.tar.gz" - sha256: "D8231B91989397A67E841B56A0673FDCDF969DBE956D54BB629F14100B030664" + "0.16.0": + url: "https://github.com/getml/reflect-cpp/archive/refs/tags/v0.16.0.tar.gz" + sha256: "a84d94dbd353d788926d6e54507b44c046863f7bc4ecb35afe0338374a68a77d" diff --git a/recipes/reflect-cpp/all/conanfile.py b/recipes/reflect-cpp/all/conanfile.py index 30e94da61ba89..86e30443a2c97 100644 --- a/recipes/reflect-cpp/all/conanfile.py +++ b/recipes/reflect-cpp/all/conanfile.py @@ -1,12 +1,15 @@ from conan import ConanFile -from conan.errors import ConanInvalidConfiguration -from conan.tools.files import get, copy +from conan.tools.files import get, copy, rmdir, replace_in_file +from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps +from conan.tools.env import VirtualBuildEnv from conan.tools.build import check_min_cppstd from conan.tools.scm import Version -from conan.tools.layout import basic_layout +from conan.errors import ConanInvalidConfiguration + import os -required_conan_version = ">=1.51.1" +required_conan_version = ">=2.0.9" + class ReflectCppConan(ConanFile): name = "reflect-cpp" @@ -14,82 +17,129 @@ class ReflectCppConan(ConanFile): 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", "yaml", "toml", "msgpack", "header-only") - package_type = "header-library" + topics = ( + "reflection", + "serialization", + "memory", + "cbor", + "flatbuffers", + "json", + "msgpack", + "toml", + "xml", + "yaml", + ) + package_type = "library" settings = "os", "arch", "compiler", "build_type" - options = { - "with_json" : [True, False], - "with_xml" : [True, False], - "with_flatbuffers" : [True, False], - "with_yaml": [True, False], - "with_msgpack": [True, False], - } - default_options = { - "with_json" : False, - "with_xml" : False, - "with_flatbuffers" : False, - "with_yaml" : False, - "with_msgpack": False, - } - - @property - def _min_cppstd(self): - return 20 @property def _compilers_minimum_version(self): + # TODO: MSVC 19.38 is required, but ConanCenterIndex CI has update 6 installed. + # Update msvc to 193 when having the CI updated to the latest update. return { - "Visual Studio": "17", - "msvc": "193", - "gcc": "11.4", - "clang": "16", + "msvc": "194", + "gcc": "11", + "clang": "13", "apple-clang": "15", } - def layout(self): - basic_layout(self, src_folder="src") + options = { + "shared": [True, False], + "fPIC": [True, False], + "with_cbor": [True, False], + "with_flatbuffers": [True, False], + "with_msgpack": [True, False], + "with_toml": [True, False], + "with_ubjson": [True, False], + "with_xml": [True, False], + "with_yaml": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + "with_cbor": False, + "with_flatbuffers": False, + "with_msgpack": False, + "with_toml": False, + "with_ubjson": False, + "with_xml": False, + "with_yaml": False, + } + implements = ["auto_shared_fpic"] def requirements(self): - if self.options.with_json: - self.requires("yyjson/0.8.0", transitive_headers=True) + self.requires("ctre/3.9.0", transitive_headers=True) + # INFO: include/rfl/json/Writer.hpp includes yyjson.h + # INFO: Transitive lib needed to avoid undefined reference to symbol 'yyjson_mut_doc_new' + self.requires("yyjson/0.10.0", transitive_headers=True, transitive_libs=True) + if self.options.with_cbor: + self.requires("tinycbor/0.6.0", transitive_headers=True) + if self.options.with_flatbuffers: + self.requires("flatbuffers/24.3.25", transitive_headers=True) + if self.options.with_msgpack: + self.requires("msgpack-c/6.0.0", transitive_headers=True) + if self.options.with_toml: + self.requires("tomlplusplus/3.4.0", transitive_headers=True) + if self.options.with_ubjson: + self.requires("jsoncons/0.176.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) - if self.options.with_msgpack: - self.requires("msgpack-c/6.0.0", transitive_headers=True) - - if Version(self.version) >= "0.11.1": - self.requires("ctre/3.9.0", transitive_headers=True) - def package_id(self): - self.info.clear() + def build_requirements(self): + self.tool_requires("cmake/[>=3.23 <4]") def validate(self): - if self.settings.get_safe("compiler.cppstd"): - check_min_cppstd(self, self._min_cppstd) + check_min_cppstd(self, 20) 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." - ) + raise ConanInvalidConfiguration(f"{self.ref} requires C++20 features, which your compiler does not fully support.") + + def layout(self): + cmake_layout(self, src_folder="src") def source(self): get(self, **self.conan_data["sources"][self.version], strip_root=True) + # INFO: Let Conan handle the C++ standard used via settings.compiler.cppstd + replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), "set(CMAKE_CXX_STANDARD 20)", "") + + def generate(self): + env = VirtualBuildEnv(self) + env.generate() + deps = CMakeDeps(self) + if self.options.with_flatbuffers: + deps.set_property("flatbuffers", "cmake_target_name", "flatbuffers::flatbuffers") + deps.generate() + tc = CMakeToolchain(self) + tc.cache_variables["REFLECTCPP_BUILD_SHARED"] = self.options.shared + tc.cache_variables["REFLECTCPP_USE_BUNDLED_DEPENDENCIES"] = False + tc.cache_variables["REFLECTCPP_USE_VCPKG"] = False + tc.cache_variables["REFLECTCPP_CBOR"] = self.options.with_cbor + tc.cache_variables["REFLECTCPP_FLEXBUFFERS"] = self.options.with_flatbuffers + tc.cache_variables["REFLECTCPP_MSGPACK"] = self.options.with_msgpack + tc.cache_variables["REFLECTCPP_TOML"] = self.options.with_toml + tc.cache_variables["REFLECTCPP_XML"] = self.options.with_xml + tc.cache_variables["REFLECTCPP_YAML"] = self.options.with_yaml + tc.generate() + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() 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"), + pattern="LICENSE", + dst=os.path.join(self.package_folder, "licenses"), + src=self.source_folder, ) + cmake = CMake(self) + cmake.install() + rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) def package_info(self): - self.cpp_info.bindirs = [] - self.cpp_info.libdirs = [] - if Version(self.version) >= "0.11.1": - self.cpp_info.defines.append("REFLECTCPP_NO_BUNDLED_DEPENDENCIES") + self.cpp_info.libs = ["reflectcpp"] + self.cpp_info.set_property("cmake_target_name", "reflectcpp::reflectcpp") + self.cpp_info.set_property("cmake_file_name", "reflectcpp") diff --git a/recipes/reflect-cpp/all/test_package/CMakeLists.txt b/recipes/reflect-cpp/all/test_package/CMakeLists.txt index 767315c296e76..74f3b52f1538e 100644 --- a/recipes/reflect-cpp/all/test_package/CMakeLists.txt +++ b/recipes/reflect-cpp/all/test_package/CMakeLists.txt @@ -1,12 +1,9 @@ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.15) project(test_package LANGUAGES CXX) -find_package(reflect-cpp REQUIRED CONFIG) +find_package(reflectcpp REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.cpp) -target_link_libraries(${PROJECT_NAME} PRIVATE reflect-cpp::reflect-cpp) +target_link_libraries(${PROJECT_NAME} reflectcpp::reflectcpp) target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20) -if(CONAN_TEST_WITH_MSGPACK) - target_compile_definitions(${PROJECT_NAME} PRIVATE CONAN_TEST_WITH_MSGPACK) -endif() diff --git a/recipes/reflect-cpp/all/test_package/conanfile.py b/recipes/reflect-cpp/all/test_package/conanfile.py index c0ce5c17be896..a66d61a9b1e97 100644 --- a/recipes/reflect-cpp/all/test_package/conanfile.py +++ b/recipes/reflect-cpp/all/test_package/conanfile.py @@ -14,11 +14,9 @@ def requirements(self): def layout(self): cmake_layout(self) - + def generate(self): tc = CMakeToolchain(self) - if self.dependencies[self.tested_reference_str].options.with_msgpack: - tc.cache_variables["CONAN_TEST_WITH_MSGPACK"] = True tc.generate() def build(self): diff --git a/recipes/reflect-cpp/all/test_package/test_package.cpp b/recipes/reflect-cpp/all/test_package/test_package.cpp index ed7b54690e256..1c46040d570e8 100644 --- a/recipes/reflect-cpp/all/test_package/test_package.cpp +++ b/recipes/reflect-cpp/all/test_package/test_package.cpp @@ -1,29 +1,15 @@ -#include +#include #include -#include - -#if defined(CONAN_TEST_WITH_MSGPACK) - #include -#endif +#include -struct TestStruct { - int x; - std::string name; -}; +#include "rfl.hpp" +#include "rfl/Generic.hpp" +#include "rfl/json.hpp" int main(void) { - for (const auto& f : rfl::fields()) { - (void) f.name(); - (void) f.type(); - } - -#if defined(CONAN_TEST_WITH_MSGPACK) - const auto test = TestStruct{.x = 15, .name = "test_package"}; - std::cout << "msgpack test: "; - rfl::msgpack::write(test, std::cout) << std::endl; -#endif - - std::cout << "reflect-cpp test successful\n"; - - return 0; + auto person = rfl::Generic::Object(); + person["first_name"] = "John"; + person["last_name"] = "Doe"; + rfl::json::write(person, std::cout) << std::endl; + return EXIT_SUCCESS; } diff --git a/recipes/reflect-cpp/config.yml b/recipes/reflect-cpp/config.yml index 1fd3a60496588..e5e40881d5003 100644 --- a/recipes/reflect-cpp/config.yml +++ b/recipes/reflect-cpp/config.yml @@ -1,9 +1,3 @@ versions: - "0.11.1": - folder: all - "0.11.0": - folder: all - "0.10.0": - folder: all - "0.6.0": + "0.16.0": folder: all