xmake.lua 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. package("dpp")
  2. set_homepage("https://github.com/brainboxdotcc/DPP")
  3. set_description("D++ Extremely Lightweight C++ Discord Library")
  4. set_license("Apache-2.0")
  5. add_urls("https://github.com/brainboxdotcc/DPP/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/brainboxdotcc/DPP.git")
  7. add_versions("v10.0.31", "3e392868c0dc3d0f13a00cfa190a925a20bde62bea58fd87d4acf14de11062bf")
  8. add_versions("v10.0.30", "fb7019770bd5c5f0539523536250da387ee1fa9c92e59c0bcff6c9adaf3d77e8")
  9. add_versions("v10.0.29", "a37e91fbdabee20cb0313700588db4077abf0ebabafe386457d999d22d2d0682")
  10. add_versions("v10.0.28", "aa0c16a1583f649f28ec7739c941e9f2bf9c891c0b87ef8278420618f8bacd46")
  11. add_versions("v10.0.27", "525a5c10a5fdd69996f48826ea1c37a3f08ba934c95e4cb9738afd209a2ecdb7")
  12. add_versions("v10.0.26", "038e95c3ef8228957bf2a84d4ff73ca1dd95ecb2cf7478ca57137d5d99f7e709")
  13. add_versions("v10.0.25", "bd39d24e01748ff4cc34ad7ca0faaa0f53542efd8843d4bcc75566a11f0f248b")
  14. add_versions("v10.0.24", "e5d561b864a7397caeb5616d388ebbd79a8f21077f3b13ac6ccd7e29c746daa9")
  15. add_versions("v10.0.23", "8f9db61c3586a492ada378235300c509e3bc2fc090cef32de0a8241741038df0")
  16. add_versions("v10.0.22", "f8da36a9e24012fdff55a988e41d2015235b9e564b3151a1e5158fa1c7e05648")
  17. add_versions("v10.0.21", "8ef2bb75f16b80d742a99c3a18ab5a2a57bce74238518af9b9aca670c2d7034b")
  18. add_versions("v10.0.20", "c4a7481c714c27d9c1411c668212e433fa5f6631a933676269c866295bd4ef73")
  19. add_versions("v10.0.19", "1126d927540715f7405d5bc33bd7ae54314431c7b1545bb5e886addfc547cf51")
  20. add_versions("v10.0.18", "0d976673852a5d8e71833d5f6a5b9767ffaf6b6a053d8420fa921adfcb80ab64")
  21. add_versions("v10.0.17", "7596dcc5602f756709f57d38c7f5b4c743cedb3d808416011ef0ab279cd5391e")
  22. add_versions("v10.0.16", "dc99af06d9c2fdeefde534d99c00cbda4c96bac7d02ee68bcbbc2b47848bb28e")
  23. add_versions("v10.0.15", "5370e7fa3e76ed78b87dc4d9c01cc5a5f1a5789ebf1d3d0e8deff05cb665c539")
  24. add_patches("v10.0.15", path.join(os.scriptdir(), "patches", "v10.0.14", "static_export.patch"), "2a5d47e09438e17b67d9fd73a943653ab8d1739f118f102ed44ae8d34c19da07")
  25. add_versions("v10.0.14", "5eb4cf3b4f4ba200d5f0d57929a1b96cc79e2398004afccc9d9c63aee865ca9d")
  26. add_patches("v10.0.14", path.join(os.scriptdir(), "patches", "v10.0.10", "permission_include.patch"), "4fdf8e406c7f610453090253bf1640e42c47a06968f65a4a21d01104a2d04fd4")
  27. add_patches("v10.0.14", path.join(os.scriptdir(), "patches", "v10.0.13", "cstring_include.patch"), "fd3af16877d46ba572f2aa33d80d36b44892a886fb3987953ac2e5fbd14263b9")
  28. add_patches("v10.0.14", path.join(os.scriptdir(), "patches", "v10.0.14", "static_export.patch"), "2a5d47e09438e17b67d9fd73a943653ab8d1739f118f102ed44ae8d34c19da07")
  29. add_versions("v10.0.13", "35dc9f5dc265d70047df67b13ae45f7345ed3f3b842b114fd89cacb3c83428ed")
  30. add_patches("v10.0.13", path.join(os.scriptdir(), "patches", "v10.0.8", "static_export.patch"), "d18487580faa9af21862bcff30ddfa5d5ab5cda6aa5f779bcc1787a96ca66447")
  31. add_patches("v10.0.13", path.join(os.scriptdir(), "patches", "v10.0.10", "permission_include.patch"), "4fdf8e406c7f610453090253bf1640e42c47a06968f65a4a21d01104a2d04fd4")
  32. add_patches("v10.0.13", path.join(os.scriptdir(), "patches", "v10.0.13", "cstring_include.patch"), "fd3af16877d46ba572f2aa33d80d36b44892a886fb3987953ac2e5fbd14263b9")
  33. add_versions("v10.0.12", "a986fcd0e6d491b0df6522fe2c85bff1e16f5513bcc3abee1b774ff25e03ee1b")
  34. add_patches("v10.0.12", path.join(os.scriptdir(), "patches", "v10.0.8", "static_export.patch"), "d18487580faa9af21862bcff30ddfa5d5ab5cda6aa5f779bcc1787a96ca66447")
  35. add_patches("v10.0.12", path.join(os.scriptdir(), "patches", "v10.0.10", "permission_include.patch"), "4fdf8e406c7f610453090253bf1640e42c47a06968f65a4a21d01104a2d04fd4")
  36. add_patches("v10.0.12", path.join(os.scriptdir(), "patches", "v10.0.12", "mutex_include.patch"), "0fc8ee9d6bca65d591ce473aa1136fc30209e27746e91d4088cf3198564b715d")
  37. add_versions("v10.0.11", "33463292f3030eabf70ab54ff09475945b4d87a9c6e428c712015cba93a1ed96")
  38. add_patches("v10.0.11", path.join(os.scriptdir(), "patches", "v10.0.8", "static_export.patch"), "d18487580faa9af21862bcff30ddfa5d5ab5cda6aa5f779bcc1787a96ca66447")
  39. add_patches("v10.0.11", path.join(os.scriptdir(), "patches", "v10.0.10", "permission_include.patch"), "4fdf8e406c7f610453090253bf1640e42c47a06968f65a4a21d01104a2d04fd4")
  40. add_versions("v10.0.10", "2a1c26f606298e5b683d1e140219c434e61c4b22e8510fa2a2d5f7b6758dff95")
  41. add_patches("v10.0.10", path.join(os.scriptdir(), "patches", "v10.0.8", "static_export.patch"), "d18487580faa9af21862bcff30ddfa5d5ab5cda6aa5f779bcc1787a96ca66447")
  42. add_patches("v10.0.10", path.join(os.scriptdir(), "patches", "v10.0.10", "permission_include.patch"), "4fdf8e406c7f610453090253bf1640e42c47a06968f65a4a21d01104a2d04fd4")
  43. add_versions("v10.0.8", "7a16d31841fc67fabcafbc33abb1a6b2ac472202df7e8c48542f77e089de08e3")
  44. add_patches("v10.0.8", path.join(os.scriptdir(), "patches", "v10.0.8", "static_export.patch"), "d18487580faa9af21862bcff30ddfa5d5ab5cda6aa5f779bcc1787a96ca66447")
  45. add_deps("nlohmann_json", "openssl", "zlib")
  46. add_configs("voice", { description = "Enable voice support for the library.", default = true, type = "boolean" , readonly = false})
  47. add_configs("have_voice", { description = "Enable voice support for the library (Deprecated flag, move out to newer version 'voice').", default = false, type = "boolean" , readonly = false})
  48. add_configs("coro", { description = "Enable experimental coroutines support for the library.", default = false, type = "boolean" , readonly = false})
  49. if is_plat("linux", "macosx") then
  50. add_syslinks("pthread")
  51. end
  52. on_load(function (package)
  53. if not package:config("shared") then
  54. package:add("defines", "DPP_STATIC")
  55. end
  56. if package:config("have_voice") then
  57. wprint([[
  58. === Deprecation Warning ===
  59. You should move out to use voice flag, instead of have_voice
  60. Deprecated:
  61. add_requires("dpp", {
  62. configs = {have_voice = true}
  63. })
  64. New (Recommended):
  65. add_requires("dpp", {
  66. configs = {voice = true}
  67. })
  68. This flag will be removed soon, please migrate ASAP!
  69. ]])
  70. end
  71. if package:config("voice") then
  72. package:add("defines", "HAVE_VOICE")
  73. package:add("deps", "libsodium", "libopus")
  74. end
  75. if package:config("coro") then
  76. package:add("defines", "DPP_CORO")
  77. end
  78. if package:version():le("v10.0.13") then
  79. package:add("deps", "fmt")
  80. end
  81. if package:version():ge("v10.0.23") then
  82. package:add("defines", "DPP_USE_EXTERNAL_JSON")
  83. end
  84. end)
  85. on_install("windows", "linux", "macosx", function (package)
  86. -- fix dpp dependencies
  87. for _, file in ipairs(table.join(os.files("include/**.h"), os.files("src/**.cpp"))) do
  88. io.replace(file, "#include <dpp/fmt/", "#include <fmt/", {plain = true})
  89. if package:version():lt("v10.0.23") then
  90. io.replace(file, "#include <dpp/nlohmann/", "#include <nlohmann/", {plain = true})
  91. end
  92. end
  93. for _, file in ipairs(os.files("src/**.cpp")) do
  94. io.replace(file, "#include <nlohmann/json_fwd.hpp>", "#include <nlohmann/json.hpp>", {plain = true})
  95. end
  96. if package:version():le("v10.0.14") then
  97. os.rmdir("include/dpp/fmt")
  98. end
  99. io.replace("include/dpp/restrequest.h", "#include <nlohmann/json_fwd.hpp>", "#include <nlohmann/json.hpp>", {plain = true})
  100. os.rmdir("include/dpp/nlohmann")
  101. local configs = {
  102. voice = package:config("voice") or package:config("have_voice"),
  103. coro = package:config("coro")
  104. }
  105. if package:version():ge("v10.0.29") and package:is_plat("windows") then
  106. configs.cxflags = "/bigobj /Gy"
  107. end
  108. os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
  109. import("package.tools.xmake").install(package, configs)
  110. end)
  111. on_test(function (package)
  112. local test_cpp_ver = "c++17"
  113. if package:config("coro") then
  114. test_cpp_ver = "c++20"
  115. end
  116. assert(package:check_cxxsnippets({test = [[
  117. void test() {
  118. dpp::cluster bot(std::getenv("BOT_TOKEN"));
  119. bot.on_ready([&bot](auto event) {
  120. if (dpp::run_once<struct register_bot_commands>()) {
  121. bot.global_command_create(
  122. dpp::slashcommand("ping", "Ping pong!", bot.me.id)
  123. );
  124. }
  125. });
  126. bot.start(false);
  127. }
  128. ]]}, {configs = {languages = test_cpp_ver}, includes = "dpp/dpp.h"}))
  129. end)