xmake.lua 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package("llhttp")
  2. set_homepage("https://github.com/nodejs/llhttp")
  3. set_description("Port of http_parser to llparse")
  4. set_license("MIT")
  5. add_urls("https://github.com/nodejs/llhttp/archive/refs/tags/release/$(version).tar.gz")
  6. add_versions("v9.3.0", "1a2b45cb8dda7082b307d336607023aa65549d6f060da1d246b1313da22b685a")
  7. add_versions("v9.2.1", "3c163891446e529604b590f9ad097b2e98b5ef7e4d3ddcf1cf98b62ca668f23e")
  8. add_versions("v8.1.0", "9da0d23453e8e242cf3b2bc5d6fb70b1517b8a70520065fcbad6be787e86638e")
  9. add_versions("v3.0.0", "02931556e69f8d075edb5896127099e70a093c104a994a57b4d72c85b48d25b0")
  10. on_load(function (package)
  11. if package:version():ge("9.2.1") then
  12. package:add("deps", "cmake")
  13. end
  14. end)
  15. on_install(function (package)
  16. io.replace("include/llhttp.h", "__wasm__", "__GNUC__", {plain = true})
  17. io.replace("include/llhttp.h", "_WIN32", "_MSC_VER", {plain = true})
  18. if not package:config("shared") then
  19. io.replace("include/llhttp.h", "__declspec(dllexport)", "", {plain = true})
  20. end
  21. local xmake_configs = {}
  22. if package:version():ge("9.2.1") then
  23. -- Get cmake config file
  24. local configs = {}
  25. local opt = {}
  26. if package:is_plat("cross") then
  27. opt.cflags = {"-flax-vector-conversions"}
  28. end
  29. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  30. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  31. table.insert(configs, "-DBUILD_STATIC_LIBS=" .. (package:config("shared") and "OFF" or "ON"))
  32. import("package.tools.cmake").install(package, configs, opt)
  33. else
  34. xmake_configs.export_symbol = true
  35. end
  36. os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
  37. import("package.tools.xmake").install(package, xmake_configs)
  38. if package:config("shared") then
  39. io.replace(package:installdir("include/llhttp.h"), "__declspec(dllexport)", "__declspec(dllimport)", {plain = true})
  40. end
  41. end)
  42. on_test(function (package)
  43. assert(package:has_cfuncs("llhttp_init", {includes = "llhttp.h"}))
  44. end)