Add dpp package (#1222)
* Add dpp package * Update xmake.lua * Update xmake.lua * dpp: Fix MinGW * Improve dpp package * Improve dpp to minimize patch size * Update xmake.luapull/1225/head
parent
f791c679d4
commit
750bbd13b3
3 changed files with 128 additions and 0 deletions
@ -0,0 +1,48 @@ |
||||
diff --git a/include/dpp/export.h b/include/dpp/export.h
|
||||
index b7b35b5..838f79d 100644
|
||||
--- a/include/dpp/export.h
|
||||
+++ b/include/dpp/export.h
|
||||
@@ -24,25 +24,29 @@
|
||||
// Investigate: MSVC doesn't like this
|
||||
//static_assert(__cplusplus >= 201703L, "D++ Requires a C++17 compatible compiler. Please ensure that you have enabled C++17 in your compiler flags.");
|
||||
|
||||
-#ifdef DPP_BUILD
|
||||
+#ifndef DPP_STATIC
|
||||
|
||||
- #ifdef _WIN32
|
||||
- #include <dpp/win32_safe_warnings.h>
|
||||
- #endif
|
||||
+ #ifdef DPP_BUILD
|
||||
+
|
||||
+ #ifdef _WIN32
|
||||
+ #include <dpp/win32_safe_warnings.h>
|
||||
+ #endif
|
||||
|
||||
- #ifdef _WIN32
|
||||
- #define DPP_EXPORT __declspec(dllexport)
|
||||
+ #ifdef _WIN32
|
||||
+ #define DPP_EXPORT __declspec(dllexport)
|
||||
+ #else
|
||||
+ #define DPP_EXPORT
|
||||
+ #endif
|
||||
#else
|
||||
- #define DPP_EXPORT
|
||||
+ #ifdef _WIN32
|
||||
+ #define DPP_EXPORT __declspec(dllimport)
|
||||
+ #else
|
||||
+ #define DPP_EXPORT
|
||||
+ #endif
|
||||
#endif
|
||||
+
|
||||
#else
|
||||
- #ifdef _WIN32
|
||||
- #define DPP_EXPORT __declspec(dllimport)
|
||||
- /* This is required otherwise fmt::format requires additional file linkage to your project */
|
||||
- #define FMT_HEADER_ONLY
|
||||
- #else
|
||||
- #define DPP_EXPORT
|
||||
- #endif
|
||||
+ #define DPP_EXPORT
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
@ -0,0 +1,26 @@ |
||||
add_rules("mode.debug", "mode.release") |
||||
|
||||
add_requires("fmt", "nlohmann_json", "libsodium", "libopus", "openssl", "zlib") |
||||
|
||||
target("dpp") |
||||
set_kind("$(kind)") |
||||
set_languages("c++17") |
||||
add_includedirs("include") |
||||
add_headerfiles("include/(dpp/**.h)") |
||||
add_files("src/dpp/**.cpp") |
||||
add_packages("fmt", "nlohmann_json", "libsodium", "libopus", "openssl", "zlib") |
||||
|
||||
add_defines("DPP_BUILD") |
||||
add_defines("HAVE_VOICE") |
||||
|
||||
if is_plat("windows", "mingw") then |
||||
add_defines("WIN32", "_WINSOCK_DEPRECATED_NO_WARNINGS", "WIN32_LEAN_AND_MEAN") |
||||
add_defines("_CRT_SECURE_NO_WARNINGS", "_CRT_NONSTDC_NO_DEPRECATE") |
||||
add_defines("FD_SETSIZE=1024") |
||||
if is_plat("windows") then |
||||
add_cxflags("/Zc:preprocessor") |
||||
end |
||||
if is_kind("static") then |
||||
add_defines("DPP_STATIC", {public = true}) |
||||
end |
||||
end |
@ -0,0 +1,54 @@ |
||||
package("dpp") |
||||
set_homepage("https://github.com/brainboxdotcc/DPP") |
||||
set_description("D++ Extremely Lightweight C++ Discord Library") |
||||
set_license("Apache-2.0") |
||||
|
||||
add_urls("https://github.com/brainboxdotcc/DPP/archive/refs/tags/$(version).tar.gz", |
||||
"https://github.com/brainboxdotcc/DPP.git") |
||||
|
||||
add_versions("v10.0.8", "7a16d31841fc67fabcafbc33abb1a6b2ac472202df7e8c48542f77e089de08e3") |
||||
add_patches("v10.0.8", path.join(os.scriptdir(), "patches", "v10.0.8", "static_export.patch"), "d18487580faa9af21862bcff30ddfa5d5ab5cda6aa5f779bcc1787a96ca66447") |
||||
|
||||
add_deps("fmt", "nlohmann_json", "libsodium", "libopus", "openssl", "zlib") |
||||
|
||||
if is_plat("linux", "macosx") then |
||||
add_syslinks("pthread") |
||||
end |
||||
|
||||
on_load("windows", "mingw", function (package) |
||||
if not package:config("shared") then |
||||
package:add("defines", "DPP_STATIC") |
||||
end |
||||
end) |
||||
|
||||
on_install("windows", "linux", "macosx", "mingw", function (package) |
||||
-- fix dpp dependencies |
||||
for _, file in ipairs(table.join(os.files("include/**.h"), os.files("src/**.cpp"))) do |
||||
io.replace(file, "#include <dpp/fmt/", "#include <fmt/", {plain = true}) |
||||
io.replace(file, "#include <dpp/nlohmann/", "#include <nlohmann/", {plain = true}) |
||||
end |
||||
io.replace("include/dpp/restrequest.h", "#include <nlohmann/json_fwd.hpp>", "#include <nlohmann/json.hpp>", {plain = true}) |
||||
os.rmdir("include/dpp/fmt") |
||||
os.rmdir("include/dpp/nlohmann") |
||||
|
||||
os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua") |
||||
import("package.tools.xmake").install(package) |
||||
end) |
||||
|
||||
on_test(function (package) |
||||
assert(package:check_cxxsnippets({test = [[ |
||||
void test() { |
||||
dpp::cluster bot(std::getenv("BOT_TOKEN")); |
||||
|
||||
bot.on_ready([&bot](auto event) { |
||||
if (dpp::run_once<struct register_bot_commands>()) { |
||||
bot.global_command_create( |
||||
dpp::slashcommand("ping", "Ping pong!", bot.me.id) |
||||
); |
||||
} |
||||
}); |
||||
|
||||
bot.start(false); |
||||
} |
||||
]]}, {configs = {languages = "c++17"}, includes = "dpp/dpp.h"})) |
||||
end) |
Loading…
Reference in new issue