xmake.lua 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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.2.1", "3c163891446e529604b590f9ad097b2e98b5ef7e4d3ddcf1cf98b62ca668f23e")
  7. add_versions("v8.1.0", "9da0d23453e8e242cf3b2bc5d6fb70b1517b8a70520065fcbad6be787e86638e")
  8. add_versions("v3.0.0", "02931556e69f8d075edb5896127099e70a093c104a994a57b4d72c85b48d25b0")
  9. on_load(function (package)
  10. if package:version():ge("9.2.1") then
  11. package:add("deps", "cmake")
  12. end
  13. end)
  14. on_install(function (package)
  15. io.replace("include/llhttp.h", "__wasm__", "__GNUC__", {plain = true})
  16. io.replace("include/llhttp.h", "_WIN32", "_MSC_VER", {plain = true})
  17. if not package:config("shared") then
  18. io.replace("include/llhttp.h", "__declspec(dllexport)", "", {plain = true})
  19. end
  20. local xmake_configs = {}
  21. if package:version():ge("9.2.1") then
  22. -- Get cmake config file
  23. local configs = {}
  24. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  25. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  26. table.insert(configs, "-DBUILD_STATIC_LIBS=" .. (package:config("shared") and "OFF" or "ON"))
  27. import("package.tools.cmake").install(package, configs)
  28. else
  29. xmake_configs.export_symbol = true
  30. end
  31. os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
  32. import("package.tools.xmake").install(package, xmake_configs)
  33. if package:config("shared") then
  34. io.replace(package:installdir("include/llhttp.h"), "__declspec(dllexport)", "__declspec(dllimport)", {plain = true})
  35. end
  36. end)
  37. on_test(function (package)
  38. assert(package:has_cfuncs("llhttp_init", {includes = "llhttp.h"}))
  39. end)