From f22f299330e97e68eed1a256b41630fd981ad1b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Tue, 14 Nov 2017 16:03:07 +0100 Subject: [PATCH] Fix mingw builds --- CMakeLists.txt | 8 ++++---- src/CMakeLists.txt | 3 +++ src/discord_register_win.cpp | 13 +++++++++---- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ffc1ed..9411b07 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,12 +27,12 @@ else(CLANG_FORMAT_CMD) endif(CLANG_FORMAT_CMD) # thirdparty stuff -execute_process( +execute_process( COMMAND mkdir ${CMAKE_SOURCE_DIR}/thirdparty ERROR_QUIET ) -find_file(RAPIDJSONTEST NAMES rapidjson rapidjson-1.1.0 PATHS ${CMAKE_SOURCE_DIR}/thirdparty) +find_file(RAPIDJSONTEST NAMES rapidjson rapidjson-1.1.0 PATHS ${CMAKE_SOURCE_DIR}/thirdparty CMAKE_FIND_ROOT_PATH_BOTH) if (NOT RAPIDJSONTEST) message("no rapidjson, download") set(RJ_TAR_FILE ${CMAKE_SOURCE_DIR}/thirdparty/v1.1.0.tar.gz) @@ -44,11 +44,11 @@ if (NOT RAPIDJSONTEST) file(REMOVE ${RJ_TAR_FILE}) endif(NOT RAPIDJSONTEST) -find_file(RAPIDJSON NAMES rapidjson rapidjson-1.1.0 PATHS ${CMAKE_SOURCE_DIR}/thirdparty) +find_file(RAPIDJSON NAMES rapidjson rapidjson-1.1.0 PATHS ${CMAKE_SOURCE_DIR}/thirdparty CMAKE_FIND_ROOT_PATH_BOTH) add_library(rapidjson STATIC IMPORTED ${RAPIDJSON}) # add subdirs add_subdirectory(src) -add_subdirectory(examples/send-presence) \ No newline at end of file +add_subdirectory(examples/send-presence) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 00ea0cb..fa516d5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -29,6 +29,7 @@ if(WIN32) add_definitions(-DDISCORD_WINDOWS) set(BASE_RPC_SRC ${BASE_RPC_SRC} connection_win.cpp discord_register_win.cpp) add_library(discord-rpc ${RPC_LIBRARY_TYPE} ${BASE_RPC_SRC}) + if (MSVC) target_compile_options(discord-rpc PRIVATE /EHsc /MT /Wall @@ -44,6 +45,8 @@ if(WIN32) /wd4946 # reinterpret_cast used between related classes /wd5027 # move assignment operator was implicitly defined as deleted ) + endif(MSVC) + target_link_libraries(discord-rpc PRIVATE psapi) endif(WIN32) if(UNIX) diff --git a/src/discord_register_win.cpp b/src/discord_register_win.cpp index 7f05e38..fc4b627 100644 --- a/src/discord_register_win.cpp +++ b/src/discord_register_win.cpp @@ -1,3 +1,9 @@ +#ifdef __MINGW32__ +// 0x0600 == vista +#define WINVER 0x0600 +#define _WIN32_WINNT 0x0600 +#endif // __MINGW32__ + #include "discord-rpc.h" #include @@ -6,9 +12,8 @@ #define NOSERVICE #define NOIME #include -#include -#include -#pragma comment(lib, "Psapi.lib") +#include +#include void Discord_RegisterW(const wchar_t* applicationId, const wchar_t* command) { @@ -24,7 +29,7 @@ void Discord_RegisterW(const wchar_t* applicationId, const wchar_t* command) StringCbPrintfW(openCommand, sizeof(openCommand), L"%s", command); } else { - lstrcpyW(openCommand, exeFilePath); + StringCbCopyW(openCommand, sizeof(openCommand), exeFilePath); } wchar_t protocolName[64];