xmake.lua 4.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package("minizip")
  2. set_homepage("https://www.zlib.net/")
  3. set_description("Mini zip and unzip based on zlib")
  4. set_license("zlib")
  5. add_urls("https://github.com/madler/zlib/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/madler/zlib.git")
  7. add_versions("v1.2.10", "42cd7b2bdaf1c4570e0877e61f2fdc0bce8019492431d054d3d86925e5058dc5")
  8. add_versions("v1.2.11", "629380c90a77b964d896ed37163f5c3a34f6e6d897311f1df2a7016355c45eff")
  9. add_versions("v1.2.12", "d8688496ea40fb61787500e863cc63c9afcbc524468cedeb478068924eb54932")
  10. add_versions("v1.2.13", "1525952a0a567581792613a9723333d7f8cc20b87a81f920fb8bc7e3f2251428")
  11. add_configs("cmake", {description = "Use cmake build system", default = true, type = "boolean"})
  12. add_configs("bzip2", {description = "Build minizip withj bzip2 support", default = false, type = "boolean"})
  13. if is_plat("wasm") then
  14. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  15. end
  16. add_deps("zlib")
  17. add_includedirs("include", "include/minizip")
  18. if on_check then
  19. on_check("android", function (package)
  20. local ndk = package:toolchain("ndk")
  21. local ndk_sdkver = ndk:config("ndk_sdkver")
  22. assert(ndk_sdkver and tonumber(ndk_sdkver) >= 23, "package(minizip) require ndk api level >= 23")
  23. end)
  24. end
  25. on_load(function (package)
  26. if package:config("cmake") then
  27. package:add("deps", "cmake")
  28. package:add("resources", "*", "cmake", "https://github.com/madler/zlib.git", "61a56bcbb0561e5c9a9a93af51d43e6a495b468f") -- 2025.02.01
  29. end
  30. if package:config("bzip2") then
  31. package:add("deps", "bzip2")
  32. package:add("defines", "HAVE_BZIP2=1")
  33. end
  34. end)
  35. on_install(function (package)
  36. os.cd(path.join("contrib/minizip"))
  37. local ndk_sdkver = package:toolchain("ndk"):config("ndk_sdkver")
  38. if ndk_sdkver and tonumber(ndk_sdkver) < 24 then
  39. io.replace("ioapi.c", "ftello", "ftell", {plain = true})
  40. io.replace("ioapi.c", "fseeko", "fseek", {plain = true})
  41. end
  42. if package:config("cmake") then
  43. local dir = path.join(package:resourcedir("cmake"), "contrib/minizip")
  44. os.vcp(path.join(dir, "CMakeLists.txt"), os.curdir())
  45. os.vcp(path.join(dir, "minizipConfig.cmake.in"), os.curdir())
  46. os.vcp(path.join(dir, "minizip.pc.in"), os.curdir())
  47. os.vcp(path.join(dir, "minizip.pc.txt"), os.curdir())
  48. io.replace("CMakeLists.txt", "return()", "", {plain = true})
  49. io.replace("CMakeLists.txt", "find_package(ZLIB REQUIRED CONFIG)", "find_package(ZLIB REQUIRED)", {plain = true})
  50. io.replace("CMakeLists.txt", "ZLIB::ZLIBSTATIC", "ZLIB::ZLIB", {plain = true})
  51. if package:version() and package:version():le("1.2.13") then
  52. io.replace("CMakeLists.txt", "ints.h", "", {plain = true})
  53. io.replace("CMakeLists.txt", "skipset.h", "", {plain = true})
  54. end
  55. local configs = {"-DMINIZIP_BUILD_TESTING=OFF", "-DCMAKE_INSTALL_INCLUDEDIR=include/minizip"}
  56. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  57. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  58. table.insert(configs, "-DMINIZIP_BUILD_SHARED=" .. (package:config("shared") and "ON" or "OFF"))
  59. table.insert(configs, "-DMINIZIP_BUILD_STATIC=" .. (not package:config("shared") and "ON" or "OFF"))
  60. table.insert(configs, "-DMINIZIP_ENABLE_BZIP2=" .. (package:config("bzip2") and "ON" or "OFF"))
  61. import("package.tools.cmake").install(package, configs)
  62. else
  63. local configs = {}
  64. configs.bzip2 = package:config("bzip2")
  65. os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
  66. import("package.tools.xmake", {anonymous = true}).install(package, configs)
  67. local config_version_file = path.join(package:installdir("lib"), "cmake", "minizip", "minizipConfigVersion.cmake")
  68. if xmake:version():lt("3.0.4") and package:is_plat("cross") and package:check_sizeof("void*") == "4" and os.exists(config_version_file) then
  69. io.replace(config_version_file, [[if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "8" STREQUAL "")]], [[if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "4" STREQUAL "")]], {plain = true})
  70. io.replace(config_version_file, [[if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "8")]], [[if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "4")]], {plain = true})
  71. io.replace(config_version_file, [[math(EXPR installedBits "8 * 8")]], [[math(EXPR installedBits "4 * 8")]], {plain = true})
  72. end
  73. end
  74. end)
  75. on_test(function (package)
  76. assert(package:has_cfuncs("inflate", {includes = "zip.h"}))
  77. end)