From 77612f7cb49da9949cc392e4bdb3187ac6738ad9 Mon Sep 17 00:00:00 2001 From: nat Date: Tue, 15 Oct 2024 00:02:03 +0200 Subject: [PATCH] fix: discord-rpc in cmake --- README.md | 4 +++- cmake/FindDiscordRPC.cmake | 16 ++++++++++++++++ src/CMakeLists.txt | 9 ++++++++- src/framework/config.h | 5 +++-- src/framework/discord/discord.cpp | 2 +- src/framework/discord/discord.h | 2 +- src/main.cpp | 6 +++--- 7 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 cmake/FindDiscordRPC.cmake diff --git a/README.md b/README.md index 87d01e242f..19518722e2 100644 --- a/README.md +++ b/README.md @@ -277,12 +277,14 @@ Beyond of it's flexibility with scripts, otclient comes with tons of other featu -
- Support Discord RPC by @SkullzOTS (Doesn't work with CMAKE) + Support Discord RPC by @SkullzOTS - by [@SkullzOTS](https://github.com/SkullzOTS) - To enable just go to [config.h](https://github.com/mehah/otclient/blob/main/src/framework/config.h#L43), set 1 in ENABLE_DISCORD_RPC and configure the others definitions + - If using CMake then set `-DTOGGLE_DISCORD_RPC=ON` + - You can see the step by step in [YouTube](https://www.youtube.com/watch?v=zCHYtRlD58g)
diff --git a/cmake/FindDiscordRPC.cmake b/cmake/FindDiscordRPC.cmake new file mode 100644 index 0000000000..c712c31c31 --- /dev/null +++ b/cmake/FindDiscordRPC.cmake @@ -0,0 +1,16 @@ +# Try to find the DISCORDRPC library +# DISCORDRPC_FOUND - system has DISCORDRPC +# DISCORDRPC_INCLUDE_DIR - the DISCORDRPC include directory +# DISCORDRPC_LIBRARY - the DISCORDRPC library + +FIND_PATH(DISCORDRPC_INCLUDE_DIR NAMES discord_rpc.h) +SET(_DISCORDRPC_STATIC_LIBS discord-rpc.lib libdiscord-rpc.a) +SET(_DISCORDRPC_SHARED_LIBS discord-rpc.lib libdiscord-rpc.dylib libdiscord-rpc.so) +IF(USE_STATIC_LIBS) + FIND_LIBRARY(DISCORDRPC_LIBRARY NAMES ${_DISCORDRPC_STATIC_LIBS} ${_DISCORDRPC_SHARED_LIBS}) +ELSE() + FIND_LIBRARY(DISCORDRPC_LIBRARY NAMES ${_DISCORDRPC_SHARED_LIBS} ${_DISCORDRPC_STATIC_LIBS}) +ENDIF() +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(DiscordRPC DEFAULT_MSG DISCORDRPC_LIBRARY DISCORDRPC_INCLUDE_DIR) +MARK_AS_ADVANCED(DISCORDRPC_LIBRARY DISCORDRPC_INCLUDE_DIR) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cc50ab7249..3626f5a0f0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,6 +10,7 @@ option(TOGGLE_FRAMEWORK_XML "Use XML " ON) option(TOGGLE_FRAMEWORK_NET "Use NET " ON) option(TOGGLE_FRAMEWORK_EDITOR "Use Editor " OFF) option(TOGGLE_DIRECTX "Use DX9 support" OFF) +option(TOGGLE_DISCORD_RPC "Use Discord Rich Presence" OFF) option(TOGGLE_BIN_FOLDER "Use build/bin folder for generate compilation files" OFF) option(TOGGLE_BOT_PROTECTION "Use bot protection" ON) option(DEBUG_LOG "Enable Debug Log" OFF) @@ -172,7 +173,6 @@ endif(TOGGLE_BOT_PROTECTION) add_definitions(-D_WIN32_WINNT=0x0501) add_definitions(${FRAMEWORK_DEFINITIONS}) add_definitions(-D"VERSION=${VERSION}") - # === Build options === message(STATUS "Build type: " ${CMAKE_BUILD_TYPE}) add_definitions(-D"BUILD_TYPE=\\\"${CMAKE_BUILD_TYPE}\\\"") @@ -210,6 +210,10 @@ endif(WIN32) if(NOT OPENSSL_FOUND) find_package(GMP REQUIRED) endif() +if(TOGGLE_DISCORD_RPC AND NOT ANDROID) + find_package(DiscordRPC REQUIRED) + add_compile_definitions(-DTOGGLE_DISCORD_RPC=1) +endif() if(TOGGLE_DIRECTX) find_package(DirectX REQUIRED) endif() @@ -586,6 +590,9 @@ else() # Linux endif() endif() +if(TOGGLE_DISCORD_RPC AND NOT ANDROID) + target_link_libraries(${PROJECT_NAME} PRIVATE ${DISCORDRPC_LIBRARY}) +endif() # ***************************************************************************** # Enable otclient console only for debug build diff --git a/src/framework/config.h b/src/framework/config.h index 4492f8d4cb..fadf2435f8 100644 --- a/src/framework/config.h +++ b/src/framework/config.h @@ -39,9 +39,10 @@ #define ENCRYPTION_HEADER "SET_YOUR_HEADER_HERE" // DISCORD RPC (https://discord.com/developers/applications) -// Note: Only for VSSolution, doesn't work with CMAKE // Enable Discord Rich Presence -#define ENABLE_DISCORD_RPC 0 // 1 to enable | 0 to disable +#ifndef TOGGLE_DISCORD_RPC + #define TOGGLE_DISCORD_RPC 0 // 1 to enable | 0 to disable +#endif #define RPC_API_KEY "1060650448522051664" // Your API Key // RPC Configs (https://youtu.be/zCHYtRlD58g) step by step to config your rich presence #define SHOW_CHARACTER_NAME_RPC 1 // 1 to enable | 0 to disable diff --git a/src/framework/discord/discord.cpp b/src/framework/discord/discord.cpp index db94a2df26..09b581a1fe 100644 --- a/src/framework/discord/discord.cpp +++ b/src/framework/discord/discord.cpp @@ -23,7 +23,7 @@ #include "discord.h" #ifndef ANDROID - #if ENABLE_DISCORD_RPC == 1 + #if TOGGLE_DISCORD_RPC == 1 #include #include diff --git a/src/framework/discord/discord.h b/src/framework/discord/discord.h index fb92070051..6340cdbccb 100644 --- a/src/framework/discord/discord.h +++ b/src/framework/discord/discord.h @@ -27,7 +27,7 @@ #include #ifndef ANDROID - #if ENABLE_DISCORD_RPC == 1 + #if TOGGLE_DISCORD_RPC == 1 #include #include diff --git a/src/main.cpp b/src/main.cpp index f397572b00..1db14ad4d3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,7 +29,7 @@ #include #ifndef ANDROID -#if ENABLE_DISCORD_RPC == 1 +#if TOGGLE_DISCORD_RPC == 1 #include #endif #endif @@ -79,7 +79,7 @@ extern "C" { g_logger.fatal("Unable to find work directory, the application cannot be initialized."); #ifndef ANDROID -#if ENABLE_DISCORD_RPC == 1 +#if TOGGLE_DISCORD_RPC == 1 std::function canUpdate = []() -> bool { return g_game.isOnline(); }; std::function onUpdate = [](std::string& info) { #if SHOW_CHARACTER_NAME_RPC == 1 @@ -124,4 +124,4 @@ extern "C" { } #ifdef ANDROID } -#endif \ No newline at end of file +#endif