xmake.lua 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package("pcre2")
  2. set_homepage("https://www.pcre.org/")
  3. set_description("A Perl Compatible Regular Expressions Library")
  4. set_urls("https://github.com/PhilipHazel/pcre2/releases/download/pcre2-$(version)/pcre2-$(version).tar.gz")
  5. add_versions("10.42", "c33b418e3b936ee3153de2c61cc638e7e4fe3156022a5c77d0711bcbb9d64f1f")
  6. add_versions("10.40", "ded42661cab30ada2e72ebff9e725e745b4b16ce831993635136f2ef86177724")
  7. add_versions("10.39", "0781bd2536ef5279b1943471fdcdbd9961a2845e1d2c9ad849b9bd98ba1a9bd4")
  8. add_deps("cmake")
  9. if not is_plat("iphoneos") then
  10. add_configs("jit", {description = "Enable jit.", default = not is_plat("wasm"), type = "boolean"})
  11. end
  12. add_configs("bitwidth", {description = "Set the code unit width.", default = "8", values = {"8", "16", "32"}})
  13. on_load(function (package)
  14. local bitwidth = package:config("bitwidth") or "8"
  15. local suffix = ""
  16. if package:is_plat("windows") and package:debug() then
  17. suffix = "d"
  18. end
  19. package:add("links", "pcre2-posix" .. suffix)
  20. package:add("links", "pcre2-" .. bitwidth .. suffix)
  21. package:add("defines", "PCRE2_CODE_UNIT_WIDTH=" .. bitwidth)
  22. if not package:config("shared") then
  23. package:add("defines", "PCRE2_STATIC")
  24. end
  25. end)
  26. on_install(function (package)
  27. if package:version():lt("10.21") then
  28. io.replace("CMakeLists.txt", [[SET(CMAKE_C_FLAGS -I${PROJECT_SOURCE_DIR}/src)]], [[SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I${PROJECT_SOURCE_DIR}/src")]], {plain = true})
  29. end
  30. io.replace("CMakeLists.txt", "OUTPUT_NAME pcre2%-(%w-)%-static", "OUTPUT_NAME pcre2-%1")
  31. local configs = {"-DPCRE2_BUILD_TESTS=OFF", "-DPCRE2_BUILD_PCRE2GREP=OFF"}
  32. table.insert(configs, "-DBUILD_STATIC_LIBS=" .. (package:config("shared") and "OFF" or "ON"))
  33. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  34. table.insert(configs, "-DPCRE2_SUPPORT_JIT=" .. (package:config("jit") and "ON" or "OFF"))
  35. table.insert(configs, "-DPCRE2_STATIC_PIC=" .. (package:config("pic") and "ON" or "OFF"))
  36. local bitwidth = package:config("bitwidth") or "8"
  37. if bitwidth ~= "8" then
  38. table.insert(configs, "-DPCRE2_BUILD_PCRE2_8=OFF")
  39. table.insert(configs, "-DPCRE2_BUILD_PCRE2_" .. bitwidth .. "=ON")
  40. end
  41. if package:debug() then
  42. table.insert(configs, "-DPCRE2_DEBUG=ON")
  43. end
  44. if package:is_plat("windows") then
  45. table.insert(configs, "-DPCRE2_STATIC_RUNTIME=" .. (package:config("vs_runtime"):startswith("MT") and "ON" or "OFF"))
  46. end
  47. import("package.tools.cmake").install(package, configs)
  48. end)
  49. on_test(function (package)
  50. assert(package:has_cfuncs("pcre2_compile", {includes = "pcre2.h"}))
  51. end)