From b88e3d8cd2769009ca3a5876ef0399904d9bdc5a Mon Sep 17 00:00:00 2001 From: Edward Li Date: Sat, 11 Jan 2025 16:51:53 +0800 Subject: [PATCH] Statically link the VCRuntime --- CMakeLists.txt | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 127794a19..e8db0bffb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,5 @@ -cmake_minimum_required(VERSION 3.10.2) +cmake_minimum_required(VERSION 3.15) +cmake_policy(SET CMP0091 NEW) find_program(CCACHE_PROGRAM ccache) if(CCACHE_PROGRAM) @@ -245,6 +246,7 @@ if(MSVC) target_compile_options(${PROJECT_NAME} PRIVATE /ZW) endif() target_compile_options(${PROJECT_NAME} PRIVATE "$<$:/Zi>") + set_property(TARGET ${PROJECT_NAME} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") target_link_options(${PROJECT_NAME} PRIVATE "$<$:/DEBUG>") target_link_options(${PROJECT_NAME} PRIVATE "$<$:/OPT:REF>") target_link_options(${PROJECT_NAME} PRIVATE "$<$:/OPT:ICF>") @@ -458,6 +460,12 @@ if(USE_VULKAN) option(ENABLE_HLSL "Enables HLSL input support" OFF) option(ENABLE_PCH "Enables Precompiled header" OFF) add_subdirectory(core/deps/glslang EXCLUDE_FROM_ALL) + if(MSVC) + set_property(TARGET glslang-default-resource-limits PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + set_property(TARGET MachineIndependent PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + set_property(TARGET GenericCodeGen PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + set_property(TARGET SPIRV PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + endif() add_library(glslang::glslang-default-resource-limits ALIAS glslang-default-resource-limits) add_library(glslang::SPIRV ALIAS SPIRV) endif() @@ -687,6 +695,9 @@ target_sources(${PROJECT_NAME} PRIVATE core/deps/chdpsr/cdipsr.h) add_subdirectory(core/deps/nowide EXCLUDE_FROM_ALL) +if(MSVC) + set_property(TARGET nowide PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") +endif() target_link_libraries(${PROJECT_NAME} PRIVATE nowide::nowide) if(NOT MINIUPNP_FOUND) @@ -698,6 +709,10 @@ if(NOT MINIUPNP_FOUND) option(UPNPC_BUILD_SAMPLE "Build sample executables" OFF) option(UPNPC_NO_INSTALL "Disable installation" ON) add_subdirectory(core/deps/miniupnpc) + if(MSVC) + set_property(TARGET miniupnpc-private PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + set_property(TARGET libminiupnpc-static PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + endif() if(WINDOWS_STORE) get_target_property(miniupnpc-private-defs miniupnpc-private INTERFACE_COMPILE_DEFINITIONS) list(REMOVE_ITEM miniupnpc-private-defs "_WIN32_WINNT=0x0501") @@ -853,6 +868,9 @@ if(USE_DISCORD AND NOT LIBRETRO) endif() cmrc_add_resource_library(flycast-resources ALIAS flycast::res NAMESPACE flycast) +if(MSVC) + set_property(TARGET flycast-resources PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") +endif() target_link_libraries(${PROJECT_NAME} PRIVATE flycast::res) if(LIBRETRO) @@ -1941,7 +1959,7 @@ if(NOT LIBRETRO) if(NOT BUILD_TESTING AND ("x86" IN_LIST ARCHITECTURE OR "x86_64" IN_LIST ARCHITECTURE)) target_include_directories(${PROJECT_NAME} PRIVATE core/deps/Spout/SPOUTSDK/SpoutGL) target_include_directories(${PROJECT_NAME} PRIVATE core/deps/Spout/SPOUTSDK/SpoutDirectX/SpoutDX) - SET(SPOUT_BUILD_CMT OFF CACHE BOOL "For Visual Studio - build /MT to link runtime libraries" FORCE) + SET(SPOUT_BUILD_CMT ON CACHE BOOL "For Visual Studio - build /MT to link runtime libraries" FORCE) SET(SPOUT_BUILD_SPOUTDX ON CACHE BOOL "Build SpoutDX DirectX11 support library" FORCE) SET(SPOUT_BUILD_LIBRARY OFF CACHE BOOL "Build C-compatible cross compiler library" FORCE) SET(SKIP_INSTALL_ALL ON CACHE BOOL "Install headers and libraries" FORCE)