Browse Source

rapidjson: add cmake support (#6878)

star9029 6 months ago
parent
commit
f69e2a3a05
1 changed files with 22 additions and 4 deletions
  1. 22 4
      packages/r/rapidjson/xmake.lua

+ 22 - 4
packages/r/rapidjson/xmake.lua

@@ -4,8 +4,8 @@ package("rapidjson")
     set_description("RapidJSON is a JSON parser and generator for C++.")
     set_license("MIT")
 
-    set_urls("https://github.com/Tencent/rapidjson/archive/$(version).zip",
-             "https://github.com/Tencent/rapidjson.git")
+    set_urls("https://github.com/Tencent/rapidjson/archive/refs/tags/$(version).zip",
+             "https://github.com/Tencent/rapidjson.git", {submodules = false})
 
     add_versions("2025.02.05", "24b5e7a8b27f42fa16b96fc70aade9106cf7102f")
     add_versions("2024.08.16", "7c73dd7de7c4f14379b781418c6e947ad464c818")
@@ -15,12 +15,30 @@ package("rapidjson")
     -- This commit is used in arrow 7.0.0 https://github.com/apache/arrow/blob/release-7.0.0/cpp/thirdparty/versions.txt#L80
     add_versions("v1.1.0-arrow", "1a803826f1197b5e30703afe4b9c0e7dd48074f5")
 
-    on_install(function (package)
+    add_configs("cmake", {description = "Use cmake build system", default = true, type = "boolean"})
+
+    on_load(function (package)
+        if package:config("cmake") then
+            package:add("deps", "cmake")
+        end
+
         if package:is_plat("windows") and package:is_arch("arm.*") then
             package:add("defines", "RAPIDJSON_ENDIAN=RAPIDJSON_LITTLEENDIAN")
         end
+    end)
 
-        os.cp(path.join("include", "*"), package:installdir("include"))
+    on_install(function (package)
+        if package:config("cmake") then
+            local configs = {
+                "-DRAPIDJSON_BUILD_DOC=OFF",
+                "-DRAPIDJSON_BUILD_EXAMPLES=OFF",
+                "-DRAPIDJSON_BUILD_TESTS=OFF",
+            }
+            table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
+            import("package.tools.cmake").install(package, configs)
+        else
+            os.cp("include/*", package:installdir("include"))
+        end
     end)
 
     on_test(function (package)