2
0

xmake.lua 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package("xerces-c")
  2. set_homepage("https://xerces.apache.org/xerces-c/")
  3. set_description("Xerces-C++ is a validating XML parser written in a portable subset of C++.")
  4. set_license("Apache-2.0")
  5. add_urls("https://archive.apache.org/dist/xerces/c/3/sources/xerces-c-$(version).zip")
  6. add_versions("3.2.5", "4aa0f7ed265a45d253f900fa145cc8cae10414d085695f1de03a2ec141a3358b")
  7. add_versions("3.2.4", "563a668b331ca5d1fc08ed52e5f62a13508b47557f88a068ad1db6f68e1f2eb2")
  8. add_configs("xmlch_type", {description = "XMLCh type (UTF-16 character type)", default = "char16_t", type = "string", values = {"char16_t", "uint16_t", "wchar_t"}})
  9. add_configs("mutex_manager", {description = "Thread support", default = "standard", type = "string", values = {"standard", "posix", "windows", "nothreads"}})
  10. local is_system_transcoder_supported = is_plat("linux", "windows", "mingw", "macosx")
  11. add_configs("transcoder", {description = "Transcoder (used to convert between internal UTF-16 and other encodings)", default = is_system_transcoder_supported and "system_transcoder" or "iconv", type = "string", values = {"system_transcoder", "iconv", "icu"}})
  12. add_configs("message_loader", {description = "Message Loader (used to access diagnostics messages)", default = "inmemory", type = "string", values = {"inmemory", "icu", "iconv"}})
  13. add_configs("network_accessor", {description = "Net Accessor (used to access network resources)", default = "off", type = "string", values = {"off", "curl", "sockets", "cfurl", "winsock"}})
  14. add_deps("cmake")
  15. if is_plat("android") then
  16. -- for NDK version less than 26
  17. add_patches(">=3.2.4",
  18. path.join(os.scriptdir(), "patches", "patch-android.diff"),
  19. "f58fa2c89e1d4a17d5af193df3e3e5918986b71beb6ce055e9edd1546c20318a")
  20. end
  21. on_check("android|armeabi-v7a", function (package)
  22. import("core.tool.toolchain")
  23. local ndk = toolchain.load("ndk", {plat = package:plat(), arch = package:arch()})
  24. local ndk_sdkver = ndk:config("ndk_sdkver")
  25. assert(ndk_sdkver and tonumber(ndk_sdkver) >= 26, "package(xerces-c): need ndk api level >= 26 for android armeabi-v7a")
  26. end)
  27. on_check(function (package)
  28. if package:config("xmlch_type") == "wchar_t" then
  29. assert(package:is_plat("windows"), "Windows only")
  30. end
  31. if package:config("mutex_manager") == "windows" then
  32. assert(package:is_plat("windows"), "Windows only")
  33. elseif package:config("mutex_manager") == "posix" then
  34. assert((not package:is_plat("windows")) or package:is_plat("cygwin"), "UNIX and Cygwin only")
  35. end
  36. end)
  37. on_load(function (package)
  38. if package:config("transcoder") == "system_transcoder" then
  39. if package:is_plat("linux") then
  40. package:add("deps", "libiconv", {system = true})
  41. elseif package:is_plat("windows", "mingw") then
  42. package:add("syslinks", "advapi32")
  43. elseif package:is_plat("macosx") then
  44. package:add("frameworks", "CoreFoundation", "CoreServices")
  45. else
  46. raise("`system_transcoder` only support GNU iconv library, macOS APIs and Windows APIs!")
  47. end
  48. elseif package:config("transcoder") == "iconv" then
  49. package:add("deps", "libiconv", {system = false})
  50. elseif package:config("transcoder") == "icu" then
  51. package:add("deps", "icu4c")
  52. end
  53. if package:config("message_loader") == "iconv" then
  54. package:add("deps", "libiconv")
  55. elseif package:config("message_loader") == "icu" then
  56. package:add("deps", "icu4c")
  57. end
  58. if package:config("network_accessor") == "curl" then
  59. assert(not package:is_plat("windows"), "UNIX only")
  60. package:add("deps", "libcurl")
  61. elseif package:config("network_accessor") == "sockets" then
  62. assert(not package:is_plat("windows"), "UNIX only")
  63. elseif package:config("network_accessor") == "cfurl" then
  64. assert(package:is_plat("macosx"), "macOS only")
  65. package:add("frameworks", "CoreServices")
  66. elseif package:config("network_accessor") == "winsock" then
  67. assert(package:is_plat("windows", "cygwin", "mingw"), "Windows, Cygwin, MingGW only")
  68. package:add("syslinks", "advapi32")
  69. end
  70. end)
  71. on_install("windows", "macosx", "linux", "android", function (package)
  72. local configs = {
  73. "-Dxmlch-type=" .. package:config("xmlch_type"),
  74. "-Dmutex-manager=" .. package:config("mutex_manager"),
  75. "-Dmessage-loader=" .. package:config("message_loader")
  76. }
  77. if package:config("mutex_manager") == "nothreads" then
  78. table.insert(configs, "-Dthreads:BOOL=OFF")
  79. end
  80. if package:config("transcoder") == "system_transcoder" then
  81. if package:is_plat("linux") then
  82. table.insert(configs, "-Dtranscoder=gnuiconv")
  83. elseif package:is_plat("windows", "mingw") then
  84. table.insert(configs, "-Dtranscoder=windows")
  85. elseif package:is_plat("macosx") then
  86. table.insert(configs, "-Dtranscoder=macosunicodeconverter")
  87. end
  88. elseif package:config("transcoder") == "iconv" then
  89. table.insert(configs, "-Dtranscoder=iconv")
  90. elseif package:config("transcoder") == "icu" then
  91. table.insert(configs, "-Dtranscoder=icu")
  92. end
  93. if package:config("network_accessor") == "off" then
  94. table.insert(configs, "-Dnetwork:BOOL=OFF")
  95. else
  96. table.insert(configs, "-Dnetwork-accessor=" .. package:config("network_accessor"))
  97. end
  98. local packagedeps = {}
  99. if package:config("transcoder") == "iconv" or package:config("message_loader") == "iconv" then
  100. table.insert(packagedeps, "libiconv")
  101. end
  102. if package:config("transcoder") == "icu" or package:config("message_loader") == "icu" then
  103. table.insert(packagedeps, "icu4c")
  104. io.replace(
  105. "cmake/FindICU.cmake",
  106. "add_library(${_ICU_imported_target} UNKNOWN IMPORTED)",
  107. [[
  108. add_library(${_ICU_imported_target} UNKNOWN IMPORTED)
  109. target_compile_features(${_ICU_imported_target} INTERFACE cxx_std_17)
  110. ]],
  111. {plain = true})
  112. end
  113. if package:config("network_accessor") == "curl" then
  114. table.insert(packagedeps, "libcurl")
  115. end
  116. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  117. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  118. if package:config("pic") ~= false then
  119. table.insert(configs, "-DCMAKE_POSITION_INDEPENDENT_CODE=ON")
  120. end
  121. import("package.tools.cmake").install(package, configs, {packagedeps = packagedeps})
  122. end)
  123. on_test(function (package)
  124. assert(package:check_cxxsnippets({test = [[
  125. using namespace xercesc;
  126. void test() {
  127. try {
  128. XMLPlatformUtils::Initialize();
  129. }
  130. catch (const XMLException& toCatch) {
  131. return;
  132. }
  133. XMLPlatformUtils::Terminate();
  134. }
  135. ]]}, {configs = {languages = "c++17"}, includes = "xercesc/util/PlatformUtils.hpp"}))
  136. end)