Browse Source

add reflect-cpp package (#4202)

* add reflect-cpp package

* Update xmake.lua

update reflect-cpp package

* Update xmake.lua

* fix xmake.lua

* switch to 0.10.0

* add patch

* set yyjson as the default dependency & add  on_check

* fix on_check

* fix on_check

* fix on_check finally

* fix on_check QAQ

* Update xmake.lua

---------

Co-authored-by: star9029 <[email protected]>
Sean 1 year ago
parent
commit
4db755ebf2
2 changed files with 140 additions and 0 deletions
  1. 41 0
      packages/r/reflect-cpp/patches/0.10.0/cmake.patch
  2. 99 0
      packages/r/reflect-cpp/xmake.lua

+ 41 - 0
packages/r/reflect-cpp/patches/0.10.0/cmake.patch

@@ -0,0 +1,41 @@
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index cc26bcb..f1c1dcc 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -27,15 +27,11 @@ project(reflectcpp)
+ 
+ set(CMAKE_CXX_STANDARD 20)
+ 
+-if (REFLECTCPP_BUILD_SHARED)
+-    add_library(reflectcpp SHARED src/yyjson.c)
+-else ()
+-    add_library(reflectcpp STATIC src/yyjson.c)
+-endif ()
++add_library(reflectcpp INTERFACE)
+ 
+-target_compile_features(reflectcpp PUBLIC cxx_std_20)
++target_compile_features(reflectcpp INTERFACE cxx_std_20)
+ 
+-target_include_directories(reflectcpp PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include> )
++target_include_directories(reflectcpp INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include> )
+ 
+ if (REFLECTCPP_BSON)
+     find_package(bson-1.0 CONFIG REQUIRED)
+@@ -82,7 +78,7 @@ if (REFLECTCPP_YAML)
+     target_link_libraries(reflectcpp INTERFACE yaml-cpp::yaml-cpp)
+ endif ()
+ 
+-target_compile_options(reflectcpp PRIVATE -Wall)
++
+ 
+ if (REFLECTCPP_BUILD_TESTS)
+     if (MSVC)
+@@ -109,7 +105,7 @@ install(
+ file(GLOB_RECURSE RFL_HEADERS RELATIVE ${CMAKE_CURRENT_LIST_DIR} "${CMAKE_CURRENT_LIST_DIR}/include/*" )
+ 
+ target_sources(reflectcpp
+-    PUBLIC
++    INTERFACE
+     FILE_SET reflectcpp_headers    
+     TYPE HEADERS
+     BASE_DIRS $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>

+ 99 - 0
packages/r/reflect-cpp/xmake.lua

@@ -0,0 +1,99 @@
+package("reflect-cpp")
+    set_kind("library", {headeronly = true})
+    set_homepage("https://github.com/getml/reflect-cpp")
+    set_description("A C++20 library for fast serialization, deserialization and validation using reflection. Supports JSON, BSON, CBOR, flexbuffers, msgpack, TOML, XML, YAML / msgpack.org[C++20]")
+    set_license("MIT")
+
+    add_urls("https://github.com/getml/reflect-cpp/archive/refs/tags/$(version).tar.gz",
+             "https://github.com/getml/reflect-cpp.git")
+
+    add_versions("v0.10.0", "d2c8876d993ddc8c57c5804e767786bdb46a2bdf1a6cd81f4b14f57b1552dfd7")
+
+    add_patches("0.10.0", "patches/0.10.0/cmake.patch", "b8929c0a13bd4045cbdeea0127e08a784e2dc8c43209ca9f056fff4a3ab5c4d3")
+
+    add_configs("bson", {description = "Enable Bson Support.", default = false, type = "boolean", readonly = true})
+    add_configs("yyjson", {description = "Enable yyjson Support.", default = true, type = "boolean"})
+    add_configs("cbor", {description = "Enable Cbor Support.", default = false, type = "boolean"})
+    add_configs("flatbuffers", {description = "Enable Flexbuffers Support.", default = false, type = "boolean"})
+    add_configs("msgpack", {description = "Enable Msgpack Support.", default = false, type = "boolean"})
+    add_configs("xml", {description = "Enable Xml Support.", default = false, type = "boolean"})
+    add_configs("toml", {description = "Enable Toml Support.", default = false, type = "boolean"})
+    add_configs("yaml", {description = "Enable Yaml Support.", default = false, type = "boolean"})
+
+    add_deps("cmake")
+
+    on_check(function (package)
+        if package:is_plat("windows") then
+            import("core.tool.toolchain")
+
+            local msvc = toolchain.load("msvc", {plat = package:plat(), arch = package:arch()})
+            if msvc then
+                local vs = msvc:config("vs")
+                assert(vs and tonumber(vs) >= 2022, "package(reflect-cpp): need vs >= 2022")
+            end
+        else
+            assert(package:check_cxxsnippets({test = [[
+                #include <ranges>
+                #include <source_location>
+                #include <iostream>
+                void test() {
+                    constexpr std::string_view message = "Hello, C++20!";
+                    for (char c : std::views::filter(message, [](char c) { return std::islower(c); }))
+                        std::cout << std::source_location::current().line() << ": " << c << '\n';
+                }
+            ]]}, {configs = {languages = "c++20"}}), "package(reflect-cpp) Require at least C++20.")
+        end
+    end)
+
+    on_load(function (package)
+        if package:config("yyjson") then
+            package:add("deps", "yyjson")
+        end
+
+        if package:config("cbor") then
+            package:add("deps", "tinycbor")
+        end
+
+        if package:config("flatbuffers") then
+            package:add("deps", "flatbuffers")
+        end
+
+        if package:config("msgpack") then
+            package:add("deps", "msgpack-c")
+        end
+
+        if package:config("xml") then
+            package:add("deps", "pugixml")
+        end
+
+        if package:config("toml") then
+            package:add("deps", "tomlcpp")
+        end
+
+        if package:config("yaml") then
+            package:add("deps", "yaml-cpp")
+        end
+    end)
+
+    on_install(function (package)
+        import("package.tools.cmake").install(package)
+    end)
+
+    on_test(function (package)
+        assert(package:check_cxxsnippets({test = [[
+            #include <rfl/json.hpp>
+            #include <rfl.hpp>
+            struct Person {
+                std::string first_name;
+                std::string last_name;
+                int age;
+            };
+            const auto homer = Person{.first_name = "Homer",
+                                      .last_name = "Simpson",
+                                      .age = 45};
+            void test() {
+                const std::string json_string = rfl::json::write(homer);
+                auto homer2 = rfl::json::read<Person>(json_string).value();
+            }   
+        ]]}, {configs = {languages = "c++20"}}))
+    end)