From 4f0ca73be60ff91f4680f548838749dec6cf7474 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 26 Jul 2023 14:47:08 +0200 Subject: [PATCH] [cmake] set MSVC runtime for SDL client --- CMakeLists.txt | 2 +- client/SDL/CMakeLists.txt | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a7c21507..f5e9a02be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -249,7 +249,7 @@ endif() if(MSVC) include(MSVCRuntime) if(NOT DEFINED MSVC_RUNTIME) - set(MSVC_RUNTIME "dynamic") + set(MSVC_RUNTIME "dynamic" CACHE STRING "MSVC runtime type [dynamic|static]") endif() if(MSVC_RUNTIME STREQUAL "static") if(BUILD_SHARED_LIBS) diff --git a/client/SDL/CMakeLists.txt b/client/SDL/CMakeLists.txt index 5658c00e7..9f9971499 100644 --- a/client/SDL/CMakeLists.txt +++ b/client/SDL/CMakeLists.txt @@ -39,6 +39,27 @@ option(WITH_DEBUG_SDL_EVENTS "[dangerous, not for release builds!] Debug SDL eve option(WITH_DEBUG_SDL_KBD_EVENTS "[dangerous, not for release builds!] Debug SDL keyboard events" OFF) option(WITH_WIN_CONSOLE "Build ${PROJECT_NAME} with console support" ON) +# Configure MSVC Runtime +if(MSVC) + include(MSVCRuntime) + if(NOT DEFINED MSVC_RUNTIME) + set(MSVC_RUNTIME "dynamic" CACHE STRING "MSVC runtime type [dynamic|static]") + endif() + if(MSVC_RUNTIME STREQUAL "static") + if(BUILD_SHARED_LIBS) + message(FATAL_ERROR "Static CRT is only supported in a fully static build") + endif() + message(STATUS "Use the MSVC static runtime option carefully!") + message(STATUS "OpenSSL uses /MD by default, and is very picky") + message(STATUS "Random freeing errors are a common sign of runtime issues") + endif() + configure_msvc_runtime() + + if(NOT DEFINED CMAKE_SUPPRESS_REGENERATION) + set(CMAKE_SUPPRESS_REGENERATION ON) + endif() +endif() + if(WITH_WIN_CONSOLE) set(WIN32_GUI_FLAG "") else()