Skip to content

Commit

Permalink
Merge pull request #6482 from daftmugi/cmake-build-with-discord-option
Browse files Browse the repository at this point in the history
Add FSO_BUILD_WITH_DISCORD cmake option
  • Loading branch information
Goober5000 authored Dec 24, 2024
2 parents a3b709c + 642ff82 commit 82304a2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ option(FSO_RELEASE_LOGGING "Enable logging output for release builds" OFF)

OPTION(FSO_BUILD_WITH_FFMPEG "Enable the usage of FFmpeg for sound and custscenes" ON)

OPTION(FSO_BUILD_WITH_DISCORD "Build with Discord support" ON)

OPTION(FSO_BUILD_WITH_OPENGL "Enable compilation of the OpenGL renderer" ON)
OPTION(FSO_BUILD_WITH_OPENGL_DEBUG "Enables debug option for OpenGL" OFF)

Expand Down Expand Up @@ -152,6 +154,7 @@ mark_as_advanced(FORCE FSO_INSTALL_DEBUG_FILES)
mark_as_advanced(FORCE ENABLE_COTIRE)
mark_as_advanced(FORCE FSO_RELEASE_LOGGING)
mark_as_advanced(FORCE FSO_BUILD_WITH_FFMPEG)
mark_as_advanced(FORCE FSO_BUILD_WITH_DISCORD)
mark_as_advanced(FORCE FSO_BUILD_WITH_OPENGL)
mark_as_advanced(FORCE FSO_BUILD_WITH_OPENGL_DEBUG)
mark_as_advanced(FORCE FSO_BUILD_WITH_VULKAN)
Expand Down Expand Up @@ -243,6 +246,7 @@ message(STATUS "Building qtFRED: ${FSO_BUILD_QTFRED}")
message(STATUS "Fatal warnings: ${FSO_FATAL_WARNINGS}")
message(STATUS "Release logging: ${FSO_RELEASE_LOGGING}")
message(STATUS "With FFmpeg: ${FSO_BUILD_WITH_FFMPEG}")
message(STATUS "With Discord: ${FSO_BUILD_WITH_DISCORD}")
message(STATUS "With OpenGL: ${FSO_BUILD_WITH_OPENGL}")
message(STATUS "With Vulkan: ${FSO_BUILD_WITH_VULKAN}")
message(STATUS "With OpenXR: ${FSO_BUILD_WITH_OPENXR}")
5 changes: 4 additions & 1 deletion code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ TARGET_LINK_LIBRARIES(code PUBLIC compiler)

target_link_libraries(code PUBLIC md5)

target_link_libraries(code PUBLIC discord-rpc)
if (FSO_BUILD_WITH_DISCORD)
target_link_libraries(code PUBLIC discord-rpc)
add_definitions(-DWITH_DISCORD)
endif()

target_link_libraries(code PUBLIC libRocket)

Expand Down
18 changes: 18 additions & 0 deletions code/libs/discord/discord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "parse/parselo.h"
#include "playerman/player.h"

#if WITH_DISCORD

#include "discord_rpc.h"

namespace {
Expand Down Expand Up @@ -284,3 +286,19 @@ void set_presence_gameplay()

} // namespace discord
} // namespace libs

#else
// Stubs for building without Discord support.
namespace libs {
namespace discord {

void init() {
mprintf(("Cannot create Discord session. Not built with Discord support.\n"));
}
void shutdown() {}
void set_presence_string(const SCP_string &text) {}
void set_presence_gameplay() {}

} // namespace discord
} // namespace libs
#endif
2 changes: 2 additions & 0 deletions code/mod_table/mod_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ bool Dont_show_callsigns_in_escort_list;
bool Fix_scripted_velocity;
color Overhead_line_colors[MAX_SHIP_SECONDARY_BANKS];

#ifdef WITH_DISCORD
static auto DiscordOption __UNUSED = options::OptionBuilder<bool>("Game.Discord",
std::pair<const char*, int>{"Discord Presence", 1754},
std::pair<const char*, int>{"Toggle Discord Rich Presence", 1755})
Expand All @@ -179,6 +180,7 @@ static auto DiscordOption __UNUSED = options::OptionBuilder<bool>("Game.Discord"
return true;
})
.finish();
#endif

void mod_table_set_version_flags();

Expand Down
4 changes: 3 additions & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ if (FSO_BUILD_WITH_FFMPEG)
include(FFmpeg.cmake)
endif()

add_subdirectory(discord)
if (FSO_BUILD_WITH_DISCORD)
add_subdirectory(discord)
endif()

include(libRocket.cmake)

Expand Down

0 comments on commit 82304a2

Please sign in to comment.