Skip to content

Commit 14dbe41

Browse files
fix: discord-rpc in cmake
1 parent 8cf226d commit 14dbe41

File tree

7 files changed

+36
-10
lines changed

7 files changed

+36
-10
lines changed

Diff for: README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,13 @@ Beyond of it's flexibility with scripts, otclient comes with tons of other featu
277277
278278
279279
- <details>
280-
<summary>Support Discord RPC by @SkullzOTS (Doesn't work with CMAKE)</summary>
280+
<summary>Support Discord RPC by @SkullzOTS</summary>
281281
282282
- by [@SkullzOTS](https://github.com/SkullzOTS)
283283
284-
- 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
284+
- To enable just go to [config.h](https://github.com/mehah/otclient/blob/main/src/framework/config.h#L43), set 1 in TOGGLE_DISCORD_RPC and configure the others definitions
285+
286+
- If using CMake then set `-DTOGGLE_DISCORD_RPC=ON`
285287
286288
- You can see the step by step in [YouTube](https://www.youtube.com/watch?v=zCHYtRlD58g)
287289

Diff for: cmake/FindDiscordRPC.cmake

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Try to find the DISCORDRPC library
2+
# DISCORDRPC_FOUND - system has DISCORDRPC
3+
# DISCORDRPC_INCLUDE_DIR - the DISCORDRPC include directory
4+
# DISCORDRPC_LIBRARY - the DISCORDRPC library
5+
6+
FIND_PATH(DISCORDRPC_INCLUDE_DIR NAMES discord_rpc.h)
7+
SET(_DISCORDRPC_STATIC_LIBS discord-rpc.lib libdiscord-rpc.a)
8+
SET(_DISCORDRPC_SHARED_LIBS discord-rpc.lib libdiscord-rpc.dylib libdiscord-rpc.so)
9+
IF(USE_STATIC_LIBS)
10+
FIND_LIBRARY(DISCORDRPC_LIBRARY NAMES ${_DISCORDRPC_STATIC_LIBS} ${_DISCORDRPC_SHARED_LIBS})
11+
ELSE()
12+
FIND_LIBRARY(DISCORDRPC_LIBRARY NAMES ${_DISCORDRPC_SHARED_LIBS} ${_DISCORDRPC_STATIC_LIBS})
13+
ENDIF()
14+
INCLUDE(FindPackageHandleStandardArgs)
15+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(DiscordRPC DEFAULT_MSG DISCORDRPC_LIBRARY DISCORDRPC_INCLUDE_DIR)
16+
MARK_AS_ADVANCED(DISCORDRPC_LIBRARY DISCORDRPC_INCLUDE_DIR)

Diff for: src/CMakeLists.txt

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ option(TOGGLE_FRAMEWORK_XML "Use XML " ON)
1010
option(TOGGLE_FRAMEWORK_NET "Use NET " ON)
1111
option(TOGGLE_FRAMEWORK_EDITOR "Use Editor " OFF)
1212
option(TOGGLE_DIRECTX "Use DX9 support" OFF)
13+
option(TOGGLE_DISCORD_RPC "Use Discord Rich Presence" OFF)
1314
option(TOGGLE_BIN_FOLDER "Use build/bin folder for generate compilation files" OFF)
1415
option(TOGGLE_BOT_PROTECTION "Use bot protection" ON)
1516
option(DEBUG_LOG "Enable Debug Log" OFF)
@@ -172,7 +173,6 @@ endif(TOGGLE_BOT_PROTECTION)
172173
add_definitions(-D_WIN32_WINNT=0x0501)
173174
add_definitions(${FRAMEWORK_DEFINITIONS})
174175
add_definitions(-D"VERSION=${VERSION}")
175-
176176
# === Build options ===
177177
message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
178178
add_definitions(-D"BUILD_TYPE=\\\"${CMAKE_BUILD_TYPE}\\\"")
@@ -210,6 +210,10 @@ endif(WIN32)
210210
if(NOT OPENSSL_FOUND)
211211
find_package(GMP REQUIRED)
212212
endif()
213+
if(TOGGLE_DISCORD_RPC AND NOT ANDROID)
214+
find_package(DiscordRPC REQUIRED)
215+
add_compile_definitions(-DTOGGLE_DISCORD_RPC=1)
216+
endif()
213217
if(TOGGLE_DIRECTX)
214218
find_package(DirectX REQUIRED)
215219
endif()
@@ -586,6 +590,9 @@ else() # Linux
586590
endif()
587591

588592
endif()
593+
if(TOGGLE_DISCORD_RPC AND NOT ANDROID)
594+
target_link_libraries(${PROJECT_NAME} PRIVATE ${DISCORDRPC_LIBRARY})
595+
endif()
589596

590597
# *****************************************************************************
591598
# Enable otclient console only for debug build

Diff for: src/framework/config.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@
3939
#define ENCRYPTION_HEADER "SET_YOUR_HEADER_HERE"
4040

4141
// DISCORD RPC (https://discord.com/developers/applications)
42-
// Note: Only for VSSolution, doesn't work with CMAKE
4342
// Enable Discord Rich Presence
44-
#define ENABLE_DISCORD_RPC 0 // 1 to enable | 0 to disable
43+
#ifndef TOGGLE_DISCORD_RPC
44+
#define TOGGLE_DISCORD_RPC 0 // 1 to enable | 0 to disable
45+
#endif
4546
#define RPC_API_KEY "1060650448522051664" // Your API Key
4647
// RPC Configs (https://youtu.be/zCHYtRlD58g) step by step to config your rich presence
4748
#define SHOW_CHARACTER_NAME_RPC 1 // 1 to enable | 0 to disable

Diff for: src/framework/discord/discord.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "discord.h"
2424

2525
#ifndef ANDROID
26-
#if ENABLE_DISCORD_RPC == 1
26+
#if TOGGLE_DISCORD_RPC == 1
2727
#include <framework/core/eventdispatcher.h>
2828
#include <time.h>
2929

Diff for: src/framework/discord/discord.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <string>
2828

2929
#ifndef ANDROID
30-
#if ENABLE_DISCORD_RPC == 1
30+
#if TOGGLE_DISCORD_RPC == 1
3131
#include <discord_register.h>
3232
#include <discord_rpc.h>
3333

Diff for: src/main.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include <framework/luaengine/luainterface.h>
3030

3131
#ifndef ANDROID
32-
#if ENABLE_DISCORD_RPC == 1
32+
#if TOGGLE_DISCORD_RPC == 1
3333
#include <framework/discord/discord.h>
3434
#endif
3535
#endif
@@ -79,7 +79,7 @@ extern "C" {
7979
g_logger.fatal("Unable to find work directory, the application cannot be initialized.");
8080

8181
#ifndef ANDROID
82-
#if ENABLE_DISCORD_RPC == 1
82+
#if TOGGLE_DISCORD_RPC == 1
8383
std::function<bool()> canUpdate = []() -> bool { return g_game.isOnline(); };
8484
std::function<void(std::string&)> onUpdate = [](std::string& info) {
8585
#if SHOW_CHARACTER_NAME_RPC == 1
@@ -124,4 +124,4 @@ extern "C" {
124124
}
125125
#ifdef ANDROID
126126
}
127-
#endif
127+
#endif

0 commit comments

Comments
 (0)