xmake.lua 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package("cpr")
  2. set_homepage("https://docs.libcpr.org/")
  3. set_description("C++ Requests is a simple wrapper around libcurl inspired by the excellent Python Requests project.")
  4. set_license("MIT")
  5. set_urls("https://github.com/libcpr/cpr/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/libcpr/cpr.git")
  7. add_versions("1.6.2", "c45f9c55797380c6ba44060f0c73713fbd7989eeb1147aedb8723aa14f3afaa3")
  8. add_versions("1.7.2", "aa38a414fe2ffc49af13a08b6ab34df825fdd2e7a1213d032d835a779e14176f")
  9. add_versions("1.8.3", "0784d4c2dbb93a0d3009820b7858976424c56578ce23dcd89d06a1d0bf5fd8e2")
  10. add_versions("1.9.4", "2fbb27716c010d8a28e52d5bc8f108e0d073ca3b3f5a48a2696b0231ea5196d5")
  11. add_versions("1.10.2", "044e98079032f7abf69c4c82f90ee2b4e4a7d2f28245498a5201ad6e8d0b1d08")
  12. add_versions("1.10.3", "d7f2574bd9dae8adb0ce6cf1afab119b509c297fffcb4204a1bb3e4e731074f2")
  13. add_versions("1.10.5", "c8590568996cea918d7cf7ec6845d954b9b95ab2c4980b365f582a665dea08d8")
  14. add_configs("ssl", {description = "Enable SSL.", default = false, type = "boolean"})
  15. add_deps("cmake")
  16. if is_plat("mingw", "linux") then
  17. add_syslinks("pthread")
  18. end
  19. add_links("cpr")
  20. on_load(function (package)
  21. if package:config("ssl") then
  22. package:add("deps", "libcurl", {configs = {libssh2 = true, zlib = true}})
  23. package:add("deps", "libssh2")
  24. else
  25. package:add("deps", "libcurl")
  26. end
  27. end)
  28. on_install("linux", "macosx", "windows", "mingw@windows", function (package)
  29. local configs = {"-DCPR_BUILD_TESTS=OFF",
  30. "-DCPR_FORCE_USE_SYSTEM_CURL=ON",
  31. "-DCPR_USE_SYSTEM_CURL=ON"}
  32. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  33. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  34. table.insert(configs, "-DCPR_ENABLE_SSL=" .. (package:config("ssl") and "ON" or "OFF"))
  35. local shflags
  36. if package:config("shared") and package:is_plat("macosx") then
  37. shflags = {"-framework", "CoreFoundation", "-framework", "Security", "-framework", "SystemConfiguration"}
  38. end
  39. local packagedeps = {"libcurl"}
  40. if package:config("ssl") then
  41. table.insert(packagedeps, "libssh2")
  42. end
  43. if package:is_plat("windows") then
  44. -- fix find_package issue on windows
  45. io.replace("CMakeLists.txt", "find_package%(CURL COMPONENTS .-%)", "find_package(CURL)")
  46. end
  47. import("package.tools.cmake").install(package, configs, {shflags = shflags, packagedeps = packagedeps})
  48. end)
  49. on_test(function (package)
  50. assert(package:check_cxxsnippets({test = [[
  51. #include <cassert>
  52. #include <cpr/cpr.h>
  53. static void test() {
  54. cpr::Response r = cpr::Get(cpr::Url{"https://xmake.io"});
  55. assert(r.status_code == 200);
  56. }
  57. ]]}, {configs = {languages = "c++17"}}))
  58. end)