xmake.lua 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package("pcre")
  2. set_homepage("https://www.pcre.org/")
  3. set_description("A Perl Compatible Regular Expressions Library")
  4. set_license("BSD-3-Clause")
  5. set_urls("https://github.com/xmake-mirror/pcre/releases/download/$(version)/pcre-$(version).tar.bz2")
  6. add_versions("8.45", "4dae6fdcd2bb0bb6c37b5f97c33c2be954da743985369cddac3546e3218bffb8")
  7. if is_plat("windows") then
  8. add_deps("cmake")
  9. end
  10. add_deps("zlib")
  11. add_configs("jit", {description = "Enable jit.", default = true, type = "boolean"})
  12. add_configs("bitwidth", {description = "Set the code unit width.", default = "8", values = {"8", "16", "32"}})
  13. on_load("windows", "mingw", function (package)
  14. if not package:config("shared") then
  15. package:add("defines", "PCRE_STATIC")
  16. end
  17. end)
  18. on_install("windows", function (package)
  19. local configs = {"-DPCRE_BUILD_TESTS=OFF"}
  20. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  21. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  22. table.insert(configs, "-DPCRE_SUPPORT_JIT=" .. (package:config("jit") and "ON" or "OFF"))
  23. local bitwidth = package:config("bitwidth") or "8"
  24. if bitwidth ~= "8" then
  25. table.insert(configs, "-DPCRE_BUILD_PCRE8=OFF")
  26. table.insert(configs, "-DPCRE_BUILD_PCRE" .. bitwidth .. "=ON")
  27. end
  28. if package:debug() then
  29. table.insert(configs, "-DPCRE_DEBUG=ON")
  30. end
  31. import("package.tools.cmake").install(package, configs)
  32. end)
  33. on_install("macosx", "linux", "mingw", "cross", function (package)
  34. local configs = {}
  35. table.insert(configs, "--enable-shared=" .. (package:config("shared") and "yes" or "no"))
  36. table.insert(configs, "--enable-static=" .. (package:config("shared") and "no" or "yes"))
  37. if package:config("jit") then
  38. table.insert(configs, "--enable-jit")
  39. end
  40. local bitwidth = package:config("bitwidth") or "8"
  41. if bitwidth ~= "8" then
  42. table.insert(configs, "--disable-pcre8")
  43. table.insert(configs, "--enable-pcre" .. bitwidth)
  44. end
  45. if package:debug() then
  46. table.insert(configs, "--enable-debug")
  47. end
  48. import("package.tools.autoconf").install(package, configs)
  49. end)
  50. on_test(function (package)
  51. local bitwidth = package:config("bitwidth") or "8"
  52. local testfunc = string.format("pcre%s_compile", bitwidth ~= "8" and bitwidth or "")
  53. assert(package:has_cfuncs(testfunc, {includes = "pcre.h"}))
  54. end)