Skip to content

Commit

Permalink
refactor: adjusting discord-rpc dependencies to work with windows
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoc7 committed Apr 27, 2024
1 parent 1610e10 commit 3b63865
Show file tree
Hide file tree
Showing 12 changed files with 460 additions and 623 deletions.
317 changes: 165 additions & 152 deletions .github/workflows/build_cmake.yml

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.vscode
.env*
!.env.example
.cache/
CMakeLists.txt.user

# Prerequisites
*.d
Expand All @@ -16,7 +18,7 @@
*.pch

# Compiled Dynamic libraries
*.so
# *.so
*.dylib

# Fortran module files
Expand Down
46 changes: 14 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
cmake_minimum_required(VERSION 3.10)

list(APPEND CMAKE_PREFIX_PATH ${qt_dir})
list(APPEND CMAKE_PREFIX_PATH ${qtc_dir})

project(CuteDiscordPresence)

list(APPEND CMAKE_PREFIX_PATH ${qt_dir})
list(APPEND CMAKE_PREFIX_PATH "/home/eduardo/AllQtFramewrok/qtcreator-13.0.0")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})

if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(DISCORD_RPC_LIB "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/win64-dynamic/lib/discord-rpc.lib")
set(DISCORD_RPC_LIB_PATH "${CMAKE_SOURCE_DIR}/dependencies/win64-dynamic/lib")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/dependencies/win64-dynamic/include")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(DISCORD_RPC_LIB "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/linux-dynamic/lib/libdiscord-rpc.so")
set(DISCORD_RPC_LIB_PATH "${CMAKE_SOURCE_DIR}/dependencies/linux-dynamic/lib")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/dependencies/linux-dynamic/include")
endif()

find_package(QtCreator REQUIRED COMPONENTS Core ProjectExplorer)
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core5Compat Widgets)
find_package(QtCreator COMPONENTS Core REQUIRED)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core5Compat Widgets REQUIRED)
set(QtX Qt${QT_VERSION_MAJOR})

# Add a CMake option that enables building your plugin with tests.
Expand All @@ -43,8 +34,6 @@ if(WITH_TESTS)
enable_testing()
endif()

link_directories(${DISCORD_RPC_LIB_PATH})

add_qtc_plugin(CuteDiscordPresence
PLUGIN_DEPENDS
QtCreator::Core
Expand All @@ -53,28 +42,21 @@ add_qtc_plugin(CuteDiscordPresence
${QtX}::Widgets
QtCreator::ExtensionSystem
QtCreator::Utils
${DISCORD_RPC_LIB}
SOURCES
.github/workflows/build_cmake.yml
.github/workflows/README.md
README.md
CuteDiscordPresence.json.in
)

extend_qtc_plugin(CuteDiscordPresence
SOURCES
.github/workflows/build_cmake.yml
.github/workflows/README.md
README.md
cutediscordpresence.cpp
cutediscordpresence.h
)
find_package(discord-rpc REQUIRED)

target_link_libraries(CuteDiscordPresence PRIVATE ${DISCORD_RPC_LIB})
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/dependencies/discord-rpc/win64-static/include")

add_custom_command(TARGET CuteDiscordPresence POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${DISCORD_RPC_LIB}
$<TARGET_FILE_DIR:CuteDiscordPresence>
COMMENT "Copying discord-rpc library to output directory"
extend_qtc_plugin(CuteDiscordPresence
CONDITION TARGET discord-rpc
DEPENDS discord-rpc
SOURCES
cutediscordpresence.cpp
cutediscordpresence.h
)
436 changes: 0 additions & 436 deletions CMakeLists.txt.user

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ To use the plugin with different versions of Qt Creator, you need to generate a
## How to Build
Create a build directory and run
```bash
cmake -DCMAKE_PREFIX_PATH=<path_to_qtcreator> -DCMAKE_BUILD_TYPE=RelWithDebInfo <path_to_plugin_source>
cmake -DCMAKE_PREFIX_PATH=<path_to_qt_framework>;<path_to_qtcreator> -DCMAKE_BUILD_TYPE=RelWithDebInfo <path_to_plugin_source>
cmake --build .
```
where `<path_to_qtcreator>` is the relative or absolute path to a Qt Creator build directory, or to a
Expand Down Expand Up @@ -54,4 +54,4 @@ on Windows and Linux, or
for the `Command line arguments` field in the run settings.

## Thanks and Credits
- [@PsychedelicShayna](https://github.com/PsychedelicShayna)
- [@PsychedelicShayna](https://github.com/PsychedelicShayna)
50 changes: 50 additions & 0 deletions cmake/Finddiscord-rpc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
if(TARGET discord-rpc)
return()
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(DISCORD_RPC_INCLUDE_HINT "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/discord-rpc/win64-static/include")
set(DISCORD_RPC_LIB_HINT "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/discord-rpc/win64-static/lib/")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(DISCORD_RPC_INCLUDE_HINT "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/discord-rpc/linux-dynamic/include")
set(DISCORD_RPC_LIB_HINT "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/discord-rpc/linux-dynamic/lib")
else()
message(FATAL_ERROR "Unsupported system")
endif()

find_path(DISCORD_RPC_INCLUDE_DIR
NAMES discord_register.h discord_rpc.h
PATH_SUFFIXES include
HINTS ${DISCORD_RPC_INCLUDE_HINT}
REQUIRED
)

find_library(DISCORD_RPC_LIB
NAMES discord-rpc
HINTS ${DISCORD_RPC_LIB_HINT}
PATH_SUFFIXES lib
REQUIRED
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(discord-rpc
DEFAULT_MSG DISCORD_RPC_INCLUDE_DIR DISCORD_RPC_LIB
)

if(discord-rpc_FOUND)
if (NOT TARGET discord-rpc)
add_library(discord-rpc UNKNOWN IMPORTED)
set_target_properties(discord-rpc
PROPERTIES
IMPORTED_LOCATION "${DISCORD_RPC_LIB}"
INTERFACE_INCLUDE_DIRECTORIES "${DISCORD_RPC_INCLUDE_DIR}"
)
endif()
endif()

mark_as_advanced(DISCORD_RPC_INCLUDE_DIR DISCORD_RPC_LIB)

set_package_properties(discord-rpc PROPERTIES
URL "https://github.com/discord/discord-rpc"
DESCRIPTION "Discord RPC library"
)
26 changes: 26 additions & 0 deletions dependencies/discord-rpc/linux-dynamic/include/discord_register.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#if defined(DISCORD_DYNAMIC_LIB)
#if defined(_WIN32)
#if defined(DISCORD_BUILDING_SDK)
#define DISCORD_EXPORT __declspec(dllexport)
#else
#define DISCORD_EXPORT __declspec(dllimport)
#endif
#else
#define DISCORD_EXPORT __attribute__((visibility("default")))
#endif
#else
#define DISCORD_EXPORT
#endif

#ifdef __cplusplus
extern "C" {
#endif

DISCORD_EXPORT void Discord_Register(const char* applicationId, const char* command);
DISCORD_EXPORT void Discord_RegisterSteamGame(const char* applicationId, const char* steamId);

#ifdef __cplusplus
}
#endif
87 changes: 87 additions & 0 deletions dependencies/discord-rpc/linux-dynamic/include/discord_rpc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#pragma once
#include <stdint.h>

// clang-format off

#if defined(DISCORD_DYNAMIC_LIB)
# if defined(_WIN32)
# if defined(DISCORD_BUILDING_SDK)
# define DISCORD_EXPORT __declspec(dllexport)
# else
# define DISCORD_EXPORT __declspec(dllimport)
# endif
# else
# define DISCORD_EXPORT __attribute__((visibility("default")))
# endif
#else
# define DISCORD_EXPORT
#endif

// clang-format on

#ifdef __cplusplus
extern "C" {
#endif

typedef struct DiscordRichPresence {
const char* state; /* max 128 bytes */
const char* details; /* max 128 bytes */
int64_t startTimestamp;
int64_t endTimestamp;
const char* largeImageKey; /* max 32 bytes */
const char* largeImageText; /* max 128 bytes */
const char* smallImageKey; /* max 32 bytes */
const char* smallImageText; /* max 128 bytes */
const char* partyId; /* max 128 bytes */
int partySize;
int partyMax;
const char* matchSecret; /* max 128 bytes */
const char* joinSecret; /* max 128 bytes */
const char* spectateSecret; /* max 128 bytes */
int8_t instance;
} DiscordRichPresence;

typedef struct DiscordUser {
const char* userId;
const char* username;
const char* discriminator;
const char* avatar;
} DiscordUser;

typedef struct DiscordEventHandlers {
void (*ready)(const DiscordUser* request);
void (*disconnected)(int errorCode, const char* message);
void (*errored)(int errorCode, const char* message);
void (*joinGame)(const char* joinSecret);
void (*spectateGame)(const char* spectateSecret);
void (*joinRequest)(const DiscordUser* request);
} DiscordEventHandlers;

#define DISCORD_REPLY_NO 0
#define DISCORD_REPLY_YES 1
#define DISCORD_REPLY_IGNORE 2

DISCORD_EXPORT void Discord_Initialize(const char* applicationId,
DiscordEventHandlers* handlers,
int autoRegister,
const char* optionalSteamId);
DISCORD_EXPORT void Discord_Shutdown(void);

/* checks for incoming messages, dispatches callbacks */
DISCORD_EXPORT void Discord_RunCallbacks(void);

/* If you disable the lib starting its own io thread, you'll need to call this from your own */
#ifdef DISCORD_DISABLE_IO_THREAD
DISCORD_EXPORT void Discord_UpdateConnection(void);
#endif

DISCORD_EXPORT void Discord_UpdatePresence(const DiscordRichPresence* presence);
DISCORD_EXPORT void Discord_ClearPresence(void);

DISCORD_EXPORT void Discord_Respond(const char* userid, /* DISCORD_REPLY_ */ int reply);

DISCORD_EXPORT void Discord_UpdateHandlers(DiscordEventHandlers* handlers);

#ifdef __cplusplus
} /* extern "C" */
#endif
Binary file not shown.
26 changes: 26 additions & 0 deletions dependencies/discord-rpc/win64-static/include/discord_register.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#if defined(DISCORD_DYNAMIC_LIB)
#if defined(_WIN32)
#if defined(DISCORD_BUILDING_SDK)
#define DISCORD_EXPORT __declspec(dllexport)
#else
#define DISCORD_EXPORT __declspec(dllimport)
#endif
#else
#define DISCORD_EXPORT __attribute__((visibility("default")))
#endif
#else
#define DISCORD_EXPORT
#endif

#ifdef __cplusplus
extern "C" {
#endif

DISCORD_EXPORT void Discord_Register(const char* applicationId, const char* command);
DISCORD_EXPORT void Discord_RegisterSteamGame(const char* applicationId, const char* steamId);

#ifdef __cplusplus
}
#endif
87 changes: 87 additions & 0 deletions dependencies/discord-rpc/win64-static/include/discord_rpc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#pragma once
#include <stdint.h>

// clang-format off

#if defined(DISCORD_DYNAMIC_LIB)
# if defined(_WIN32)
# if defined(DISCORD_BUILDING_SDK)
# define DISCORD_EXPORT __declspec(dllexport)
# else
# define DISCORD_EXPORT __declspec(dllimport)
# endif
# else
# define DISCORD_EXPORT __attribute__((visibility("default")))
# endif
#else
# define DISCORD_EXPORT
#endif

// clang-format on

#ifdef __cplusplus
extern "C" {
#endif

typedef struct DiscordRichPresence {
const char* state; /* max 128 bytes */
const char* details; /* max 128 bytes */
int64_t startTimestamp;
int64_t endTimestamp;
const char* largeImageKey; /* max 32 bytes */
const char* largeImageText; /* max 128 bytes */
const char* smallImageKey; /* max 32 bytes */
const char* smallImageText; /* max 128 bytes */
const char* partyId; /* max 128 bytes */
int partySize;
int partyMax;
const char* matchSecret; /* max 128 bytes */
const char* joinSecret; /* max 128 bytes */
const char* spectateSecret; /* max 128 bytes */
int8_t instance;
} DiscordRichPresence;

typedef struct DiscordUser {
const char* userId;
const char* username;
const char* discriminator;
const char* avatar;
} DiscordUser;

typedef struct DiscordEventHandlers {
void (*ready)(const DiscordUser* request);
void (*disconnected)(int errorCode, const char* message);
void (*errored)(int errorCode, const char* message);
void (*joinGame)(const char* joinSecret);
void (*spectateGame)(const char* spectateSecret);
void (*joinRequest)(const DiscordUser* request);
} DiscordEventHandlers;

#define DISCORD_REPLY_NO 0
#define DISCORD_REPLY_YES 1
#define DISCORD_REPLY_IGNORE 2

DISCORD_EXPORT void Discord_Initialize(const char* applicationId,
DiscordEventHandlers* handlers,
int autoRegister,
const char* optionalSteamId);
DISCORD_EXPORT void Discord_Shutdown(void);

/* checks for incoming messages, dispatches callbacks */
DISCORD_EXPORT void Discord_RunCallbacks(void);

/* If you disable the lib starting its own io thread, you'll need to call this from your own */
#ifdef DISCORD_DISABLE_IO_THREAD
DISCORD_EXPORT void Discord_UpdateConnection(void);
#endif

DISCORD_EXPORT void Discord_UpdatePresence(const DiscordRichPresence* presence);
DISCORD_EXPORT void Discord_ClearPresence(void);

DISCORD_EXPORT void Discord_Respond(const char* userid, /* DISCORD_REPLY_ */ int reply);

DISCORD_EXPORT void Discord_UpdateHandlers(DiscordEventHandlers* handlers);

#ifdef __cplusplus
} /* extern "C" */
#endif
Binary file not shown.

0 comments on commit 3b63865

Please sign in to comment.