xmake.lua 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. package("icu4c")
  2. set_homepage("http://site.icu-project.org/")
  3. set_description("C/C++ libraries for Unicode and globalization.")
  4. add_urls("https://github.com/unicode-org/icu/releases/download/release-$(version)-src.tgz", {version = function (version)
  5. return (version:gsub("%.", "-")) .. "/icu4c-" .. (version:gsub("%.", "_"))
  6. end})
  7. add_versions("75.1", "cb968df3e4d2e87e8b11c49a5d01c787bd13b9545280fc6642f826527618caef")
  8. add_versions("73.2", "818a80712ed3caacd9b652305e01afc7fa167e6f2e94996da44b90c2ab604ce1")
  9. add_versions("73.1", "a457431de164b4aa7eca00ed134d00dfbf88a77c6986a10ae7774fc076bb8c45")
  10. add_versions("72.1", "a2d2d38217092a7ed56635e34467f92f976b370e20182ad325edea6681a71d68")
  11. add_versions("71.1", "67a7e6e51f61faf1306b6935333e13b2c48abd8da6d2f46ce6adca24b1e21ebf")
  12. add_versions("70.1", "8d205428c17bf13bb535300669ed28b338a157b1c01ae66d31d0d3e2d47c3fd5")
  13. add_versions("69.1", "4cba7b7acd1d3c42c44bb0c14be6637098c7faf2b330ce876bc5f3b915d09745")
  14. add_versions("68.2", "c79193dee3907a2199b8296a93b52c5cb74332c26f3d167269487680d479d625")
  15. add_versions("68.1", "a9f2e3d8b4434b8e53878b4308bd1e6ee51c9c7042e2b1a376abefb6fbb29f2d")
  16. add_versions("64.2", "627d5d8478e6d96fc8c90fed4851239079a561a6a8b9e48b0892f24e82d31d6c")
  17. add_patches("69.1", path.join(os.scriptdir(), "patches", "69.1", "replace-py-3.patch"), "ae27a55b0e79a8420024d6d349a7bae850e1dd403a8e1131e711c405ddb099b9")
  18. add_patches("70.1", path.join(os.scriptdir(), "patches", "70.1", "replace-py-3.patch"), "6469739da001721122b62af513370ed62901caf43af127de3f27ea2128830e35")
  19. if is_plat("mingw") then
  20. add_patches(">=69.1", path.join(os.scriptdir(), "patches", "72.1", "mingw.patch"), "9ddbe7f691224ccf69f8c0218f788f0a39ab8f1375cc9aad2cc92664ffcf46a5")
  21. end
  22. if is_plat("mingw") and is_subhost("msys") then
  23. add_extsources("pacman::icu")
  24. elseif is_plat("linux") then
  25. add_extsources("pacman::icu", "apt::libicu-dev")
  26. elseif is_plat("macosx") then
  27. add_extsources("brew::icu4c")
  28. end
  29. add_configs("tools", {description = "Build tools.", default = false, type = "boolean"})
  30. if is_plat("windows") then
  31. add_configs("shared", {description = "Build shared library.", default = true, type = "boolean", readonly = true})
  32. end
  33. if is_plat("linux") then
  34. add_syslinks("dl")
  35. end
  36. on_load(function (package)
  37. if package:is_plat("windows") then
  38. if package:config("tools") then
  39. package:add("deps", "python 3.x", {kind = "binary"})
  40. end
  41. if package:has_runtime("MTd", "MDd") then
  42. wprint("MTd/MDd runtime force to use debug package")
  43. package:config_set("debug", true)
  44. end
  45. end
  46. local libsuffix = package:is_debug() and package:is_plat("mingw", "windows") and "d" or ""
  47. package:add("links", "icutu" .. libsuffix, "icuio" .. libsuffix)
  48. if package:is_plat("mingw", "windows") then
  49. package:add("links", "icuin" .. libsuffix, "icuuc" .. libsuffix, "icudt" .. libsuffix)
  50. else
  51. package:add("links", "icui18n" .. libsuffix, "icuuc" .. libsuffix, "icudata" .. libsuffix)
  52. end
  53. end)
  54. on_install("windows", function (package)
  55. import("package.tools.msbuild")
  56. local projectfiles = os.files("source/**.vcxproj")
  57. local sln = path.join("source", "allinone", "allinone.sln")
  58. table.join2(projectfiles, sln, os.files("source/**.props"))
  59. if package:is_cross() then
  60. -- icu build requires native tools
  61. local configs = {
  62. sln,
  63. "/p:Configuration=Release",
  64. "/target:pkgdata,genrb"
  65. }
  66. local arch_prev = package:arch()
  67. package:arch_set(os.arch())
  68. msbuild.build(package, configs, {upgrade = projectfiles})
  69. package:arch_set(arch_prev)
  70. end
  71. if package:has_runtime("MT", "MTd") then
  72. local files = {
  73. "source/common/common.vcxproj",
  74. "source/i18n/i18n.vcxproj",
  75. "source/extra/uconv/uconv.vcxproj",
  76. "source/io/io.vcxproj",
  77. "source/stubdata/stubdata.vcxproj",
  78. }
  79. for _, vcxproj in ipairs(files) do
  80. io.replace(vcxproj, "MultiThreadedDLL", "MultiThreaded", {plain = true})
  81. io.replace(vcxproj, "MultiThreadedDebugDLL", "MultiThreadedDebug", {plain = true})
  82. end
  83. end
  84. local configs = {
  85. sln,
  86. "/p:SkipUWP=True",
  87. "/p:_IsNativeEnvironment=true",
  88. }
  89. if not package:config("tools") then
  90. table.insert(configs, "/target:common,i18n,uconv,io,stubdata")
  91. end
  92. msbuild.build(package, configs, {upgrade = projectfiles})
  93. local suffix = package:is_arch("arm.*") and "ARM" or ""
  94. if package:is_arch(".*64") then
  95. suffix = suffix .. "64"
  96. end
  97. os.vcp("include", package:installdir())
  98. os.vcp("bin" .. suffix .. "/*", package:installdir("bin"))
  99. os.vcp("lib" .. suffix .. "/*", package:installdir("lib"))
  100. package:addenv("PATH", "bin")
  101. end)
  102. on_install("macosx", "linux", "mingw@msys", function (package)
  103. import("package.tools.autoconf")
  104. os.cd("source")
  105. local configs = {"--disable-samples", "--disable-tests"}
  106. if package:debug() then
  107. table.insert(configs, "--enable-debug")
  108. table.insert(configs, "--disable-release")
  109. end
  110. if package:config("shared") then
  111. table.insert(configs, "--enable-shared")
  112. table.insert(configs, "--disable-static")
  113. else
  114. table.insert(configs, "--disable-shared")
  115. table.insert(configs, "--enable-static")
  116. end
  117. if package:is_plat("mingw") then
  118. table.insert(configs, "--with-data-packaging=dll")
  119. end
  120. local envs = {}
  121. local cxxflags = "-std=gnu++17"
  122. if package:is_plat("linux") and package:config("pic") ~= false then
  123. envs = autoconf.buildenvs(package, {cxflags = "-fPIC", cxxflags = cxxflags})
  124. else
  125. envs = autoconf.buildenvs(package, {cxxflags = cxxflags})
  126. end
  127. -- suppress ar errors when passing --toolchain=clang
  128. envs.ARFLAGS = nil
  129. autoconf.install(package, configs, {envs = envs})
  130. package:addenv("PATH", "bin")
  131. end)
  132. on_test(function (package)
  133. assert(package:has_cfuncs("ucnv_convert", {includes = "unicode/ucnv.h"}))
  134. end)