Forráskód Böngészése

prepend miniz (#6143)

* prepend

* test both

* return old ver

* fixup

* fixup

* fixup

* add config cmake

* use xmake build for <2.2.0 version

* improve port xmake.lua

---------

Co-authored-by: star9029 <[email protected]>
Saikari 7 hónapja
szülő
commit
53bb788bf6
2 módosított fájl, 72 hozzáadás és 7 törlés
  1. 43 0
      packages/m/miniz/port/xmake.lua
  2. 29 7
      packages/m/miniz/xmake.lua

+ 43 - 0
packages/m/miniz/port/xmake.lua

@@ -0,0 +1,43 @@
+option("ver", {default = "2.1.0"})
+
+add_rules("mode.debug", "mode.release")
+
+local export_file = "miniz_export.h"
+
+target("miniz")
+    set_kind("$(kind)")
+    add_files("miniz.c", "miniz_zip.c", "miniz_tinfl.c", "miniz_tdef.c")
+    add_headerfiles("miniz.h", "miniz_common.h", "miniz_zip.h", "miniz_tinfl.h", "miniz_tdef.h", {prefixdir = "miniz"})
+
+    on_load(function (target)
+        import("core.base.semver")
+        import("core.project.rule")
+
+        local version = import("core.base.semver").new(get_config("ver"))
+        target:set("version", version, {soname = true})
+        if version:lt("2.2.0") then
+            if target:is_plat("windows") and target:is_shared() then
+                local rule = rule.rule("utils.symbols.export_all")
+                target:rule_add(rule)
+                target:extraconf_set("rules", "utils.symbols.export_all")
+            end
+        else
+            local string = "#define MINIZ_EXPORT"
+            if target:is_plat("windows") and target:is_shared() then
+                string = string .. " __declspec(dllexport)"
+            end
+    
+            io.writefile(export_file, string)
+            target:add("headerfiles", export_file, {prefixdir = "miniz"})
+        end
+    end)
+
+    after_build(function (target)
+        if target:is_plat("windows") then
+            if target:is_shared() then
+                io.writefile(export_file, "#define MINIZ_EXPORT __declspec(dllimport)")
+            elseif target:is_static() then
+                io.writefile(export_file, "#define MINIZ_EXPORT")
+            end
+        end
+    end)

+ 29 - 7
packages/m/miniz/xmake.lua

@@ -1,5 +1,4 @@
 package("miniz")
-
     set_homepage("https://github.com/richgel999/miniz/")
     set_description("miniz: Single C source file zlib-replacement library")
     set_license("MIT")
@@ -8,16 +7,39 @@ package("miniz")
              "https://github.com/richgel999/miniz.git")
 
     add_versions("3.0.2", "c4b4c25a4eb81883448ff8924e6dba95c800094a198dc9ce66a292ac2ef8e018")
+    add_versions("2.2.0", "bd1136d0a1554520dcb527a239655777148d90fd2d51cf02c36540afc552e6ec")
+    add_versions("2.1.0", "95f9b23c92219ad2670389a23a4ed5723b7329c82c3d933b7047673ecdfc1fea")
+
+    add_configs("cmake", {description = "Use cmake buildsystem", default = true, type = "boolean"})
+
+    add_includedirs("include", "include/miniz")
 
-    add_deps("cmake")
+    on_load(function (package)
+        local version = package:version()
+        if version and version:lt("2.2.0") then
+            package:config_set("cmake", false)
+        end
+
+        if package:config("cmake") then
+            package:add("deps", "cmake")
+            if not package:config("shared") then
+                package:add("defines", "MINIZ_STATIC_DEFINE")
+            end
+        end
+    end)
 
     on_install(function (package)
-        local configs = {"-DCMAKE_POLICY_DEFAULT_CMP0057=NEW", "-DBUILD_EXAMPLES=OFF", "-DBUILD_TESTS=OFF", "-DINSTALL_PROJECT=ON"}
-        table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
-        table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
-        import("package.tools.cmake").install(package, configs)
+        if package:config("cmake") then
+            local configs = {"-DCMAKE_POLICY_DEFAULT_CMP0057=NEW", "-DBUILD_EXAMPLES=OFF", "-DBUILD_TESTS=OFF", "-DINSTALL_PROJECT=ON"}
+            table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
+            table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
+            import("package.tools.cmake").install(package, configs)
+        else
+            os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
+            import("package.tools.xmake").install(package, {ver = package:version()})
+        end
     end)
 
     on_test(function (package)
-        assert(package:has_cfuncs("mz_compress", {includes = "miniz/miniz.h"}))
+        assert(package:has_cfuncs("mz_compress", {includes = "miniz.h"}))
     end)