From 704c56d13f3c7472fffbf06565324056a020fa64 Mon Sep 17 00:00:00 2001 From: Ted John Date: Mon, 13 Nov 2017 17:22:45 +0000 Subject: [PATCH] Add option for building with /MT --- build.py | 4 ++-- src/CMakeLists.txt | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/build.py b/build.py index cbc7396..65768f8 100755 --- a/build.py +++ b/build.py @@ -73,9 +73,9 @@ def main(clean): generator64 = 'Visual Studio 14 2015 Win64' build_lib('win32-static', generator32, {}) - build_lib('win32-dynamic', generator32, {'BUILD_SHARED_LIBS': True}) + build_lib('win32-dynamic', generator32, {'BUILD_SHARED_LIBS': True, 'USE_STATIC_CRT': True}) build_lib('win64-static', generator64, {}) - build_lib('win64-dynamic', generator64, {'BUILD_SHARED_LIBS': True}) + build_lib('win64-dynamic', generator64, {'BUILD_SHARED_LIBS': True, 'USE_STATIC_CRT': True}) # todo: this in some better way src_dll = os.path.join(SCRIPT_PATH, 'builds', 'win64-dynamic', 'src', 'Release', 'discord-rpc.dll') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 34d415d..3fccf6f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,7 @@ include_directories(${PROJECT_SOURCE_DIR}/include) option(ENABLE_IO_THREAD "Start up a separate I/O thread, otherwise I'd need to call an update function" ON) +option(USE_STATIC_CRT "Use /MT[d] for dynamic library" OFF) set(BASE_RPC_SRC ${PROJECT_SOURCE_DIR}/include/discord-rpc.h @@ -22,11 +23,21 @@ if (${BUILD_SHARED_LIBS}) endif(${BUILD_SHARED_LIBS}) if(WIN32) + set(CRT_FLAGS) + if(USE_STATIC_CRT) + if (CMAKE_BUILD_TYPE STREQUAL "Debug") + set(CRT_FLAGS /MTd) + else() + set(CRT_FLAGS /MT) + endif() + endif(USE_STATIC_CRT) + add_definitions(-DDISCORD_WINDOWS) set(BASE_RPC_SRC ${BASE_RPC_SRC} connection_win.cpp discord_register_win.cpp) add_library(discord-rpc ${BASE_RPC_SRC}) if (MSVC) target_compile_options(discord-rpc PRIVATE /EHsc + ${CRT_FLAGS} /Wall /wd4100 # unreferenced formal parameter /wd4514 # unreferenced inline