xmake.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package("cpp20-http-client")
  2. set_homepage("https://github.com/avocadoboi/cpp20-http-client")
  3. set_description("An HTTP(S) client library for C++20.")
  4. set_license("MIT")
  5. add_urls("https://github.com/avocadoboi/cpp20-http-client.git")
  6. add_versions("2023.08.11", "bb011a055a1813a4fb2a0b67db0ffa455221aaf8")
  7. add_versions("2025.07.24", "2c0efb938486c3edb81705c4abe6486457d9d88f")
  8. if is_plat("windows") then
  9. add_syslinks("ws2_32", "crypt32")
  10. else
  11. add_deps("openssl")
  12. end
  13. if on_check then
  14. on_check(function (package)
  15. assert(package:check_cxxsnippets({test = [[
  16. #include <format>
  17. void test() {
  18. auto f = std::format("Hello, {}!", "world");
  19. }
  20. ]]}, {configs = {languages = "c++20"}}), "package(cpp20-http-client) requires c++20")
  21. end)
  22. end
  23. on_install("windows", "linux", "macosx", "bsd", "android", "cross", function (package)
  24. if package:is_plat("bsd") then
  25. io.replace("source/cpp20_http_client.cpp", [[# include <netinet/tcp.h>]], [[# include <netinet/tcp.h>
  26. # include <netinet/in.h>]], {plain = true})
  27. end
  28. io.writefile("xmake.lua", [[
  29. add_rules("mode.debug", "mode.release")
  30. if not is_plat("windows") then
  31. add_requires("openssl")
  32. end
  33. set_languages("c++20")
  34. target("cpp20-http-client")
  35. set_kind("$(kind)")
  36. add_files("source/**.cpp")
  37. add_includedirs("include")
  38. add_headerfiles("include/**.hpp")
  39. if is_plat("windows") then
  40. add_cxxflags("/utf-8")
  41. add_syslinks("ws2_32", "crypt32")
  42. if is_kind("shared") then
  43. add_rules("utils.symbols.export_all", {export_classes = true})
  44. end
  45. else
  46. add_packages("openssl")
  47. end
  48. ]])
  49. import("package.tools.xmake").install(package, configs)
  50. end)
  51. on_test(function (package)
  52. assert(package:check_cxxsnippets({test = [[
  53. #include <cpp20_http_client.hpp>
  54. void test() {
  55. auto const response = http_client::get("https://www.google.com")
  56. .add_header({.name="HeaderName", .value="header value"})
  57. .send();
  58. }
  59. ]]}, {configs = {languages = "c++20"}}))
  60. end)