xmake.lua 3.1 KB

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