Browse Source

swxjson: add new package (#7347)

* swxjson: add new package

* fixup

* `set_languages("c++11")`
Saikari 6 months ago
parent
commit
d644f16a2b
2 changed files with 67 additions and 0 deletions
  1. 31 0
      packages/s/swxjson/patches/fix.diff
  2. 36 0
      packages/s/swxjson/xmake.lua

+ 31 - 0
packages/s/swxjson/patches/fix.diff

@@ -0,0 +1,31 @@
+diff --git a/src/swxJson.h b/src/swxJson.h
+index 0a32c22..c4cbe64 100644
+--- a/src/swxJson.h
++++ b/src/swxJson.h
+@@ -17,6 +17,11 @@
+ #include <queue>
+ #include "swxJsonUtils.h"
+ 
++#ifdef _MSC_VER
++#define strcasecmp _stricmp
++#define strncasecmp _strnicmp
++#endif
++
+ namespace swxJson {
+ /*******************************************************************
+   Exception
+diff --git a/src/swxJsonUtils.h b/src/swxJsonUtils.h
+index bc32a38..23cfbec 100644
+--- a/src/swxJsonUtils.h
++++ b/src/swxJsonUtils.h
+@@ -2,7 +2,9 @@
+ #define SWX_JSON_UTILS_H
+ 
+ #include <exception>
+-#include <strings.h>
++#include <cstdint>
++#include <memory.h>
++#define bzero(b,len) (memset((b), '\0', (len)), (void) 0)
+ 
+ namespace swxJson {
+ 

+ 36 - 0
packages/s/swxjson/xmake.lua

@@ -0,0 +1,36 @@
+package("swxjson")
+    set_homepage("https://github.com/swxlion/swxJson")
+    set_description("A easy to use & convenient JSON library for C++11.")
+    set_license("MIT")
+
+    add_urls("https://github.com/swxlion/swxJson/archive/refs/tags/$(version).tar.gz",
+             "https://github.com/swxlion/swxJson.git")
+
+    add_versions("v1.0.9", "672c9362a13a53628469e2d7bb5cc6c976e1fa52c730ae95945c9509b0263f01")
+    add_patches("v1.0.9", "patches/fix.diff", "99eb96c1b51ad2a216289d6011ddc980cb7f55be941e4f531584c12ace712738")
+
+    on_install(function (package)
+        io.writefile("xmake.lua", [[
+            add_rules("mode.release", "mode.debug")
+            target("swxjson")
+                set_languages("c++11")
+                set_kind("$(kind)")
+                add_files("src/*.cpp")
+                add_headerfiles("src/(*.h)")
+                if is_plat("windows") and is_kind("shared") then
+                    add_rules("utils.symbols.export_all", {export_classes = true})
+                end
+        ]])
+        import("package.tools.xmake").install(package)
+    end)
+
+    on_test(function (package)
+        assert(package:check_cxxsnippets({test = [[
+            #include <swxJson.h>
+            using namespace swxJson;
+            void test() {
+                const std::string dictDemo = R"({"strDict":{"123":"aa", "456":"bb", "789":"cc"}, "intDict":{"aa":1, "bb":2, "cc":3, "dd":4, "ee":5}})";
+                JsonPtr json = Json::parse(dictDemo.c_str());
+            }
+        ]]}, {configs = {languages = "c++11"}}))
+    end)