Fix mingw builds

This commit is contained in:
Michał Janiszewski 2017-11-14 16:03:07 +01:00 committed by Chris Marsh
parent 767b15184f
commit f22f299330
3 changed files with 16 additions and 8 deletions

View file

@ -27,12 +27,12 @@ else(CLANG_FORMAT_CMD)
endif(CLANG_FORMAT_CMD) endif(CLANG_FORMAT_CMD)
# thirdparty stuff # thirdparty stuff
execute_process( execute_process(
COMMAND mkdir ${CMAKE_SOURCE_DIR}/thirdparty COMMAND mkdir ${CMAKE_SOURCE_DIR}/thirdparty
ERROR_QUIET 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) if (NOT RAPIDJSONTEST)
message("no rapidjson, download") message("no rapidjson, download")
set(RJ_TAR_FILE ${CMAKE_SOURCE_DIR}/thirdparty/v1.1.0.tar.gz) 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}) file(REMOVE ${RJ_TAR_FILE})
endif(NOT RAPIDJSONTEST) 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_library(rapidjson STATIC IMPORTED ${RAPIDJSON})
# add subdirs # add subdirs
add_subdirectory(src) add_subdirectory(src)
add_subdirectory(examples/send-presence) add_subdirectory(examples/send-presence)

View file

@ -29,6 +29,7 @@ if(WIN32)
add_definitions(-DDISCORD_WINDOWS) add_definitions(-DDISCORD_WINDOWS)
set(BASE_RPC_SRC ${BASE_RPC_SRC} connection_win.cpp discord_register_win.cpp) set(BASE_RPC_SRC ${BASE_RPC_SRC} connection_win.cpp discord_register_win.cpp)
add_library(discord-rpc ${RPC_LIBRARY_TYPE} ${BASE_RPC_SRC}) add_library(discord-rpc ${RPC_LIBRARY_TYPE} ${BASE_RPC_SRC})
if (MSVC)
target_compile_options(discord-rpc PRIVATE /EHsc target_compile_options(discord-rpc PRIVATE /EHsc
/MT /MT
/Wall /Wall
@ -44,6 +45,8 @@ if(WIN32)
/wd4946 # reinterpret_cast used between related classes /wd4946 # reinterpret_cast used between related classes
/wd5027 # move assignment operator was implicitly defined as deleted /wd5027 # move assignment operator was implicitly defined as deleted
) )
endif(MSVC)
target_link_libraries(discord-rpc PRIVATE psapi)
endif(WIN32) endif(WIN32)
if(UNIX) if(UNIX)

View file

@ -1,3 +1,9 @@
#ifdef __MINGW32__
// 0x0600 == vista
#define WINVER 0x0600
#define _WIN32_WINNT 0x0600
#endif // __MINGW32__
#include "discord-rpc.h" #include "discord-rpc.h"
#include <stdio.h> #include <stdio.h>
@ -6,9 +12,8 @@
#define NOSERVICE #define NOSERVICE
#define NOIME #define NOIME
#include <windows.h> #include <windows.h>
#include <Psapi.h> #include <psapi.h>
#include <Strsafe.h> #include <strsafe.h>
#pragma comment(lib, "Psapi.lib")
void Discord_RegisterW(const wchar_t* applicationId, const wchar_t* command) 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); StringCbPrintfW(openCommand, sizeof(openCommand), L"%s", command);
} }
else { else {
lstrcpyW(openCommand, exeFilePath); StringCbCopyW(openCommand, sizeof(openCommand), exeFilePath);
} }
wchar_t protocolName[64]; wchar_t protocolName[64];