diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5339244f2b..1fc0fe1d16 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -247,6 +247,14 @@ set_target_properties(openttd PROPERTIES OUTPUT_NAME "${BINARY_NAME}")
 if(MSVC)
     # Add DPI manifest to project; other WIN32 targets get this via ottdres.rc
     target_sources(openttd PRIVATE "${CMAKE_SOURCE_DIR}/os/windows/openttd.manifest")
+
+    # If target -static is used, switch our project to static (/MT) too.
+    # If the target ends on -static-md, it will remain dynamic (/MD).
+    if(VCPKG_TARGET_TRIPLET MATCHES "-static" AND NOT VCPKG_TARGET_TRIPLET MATCHES "-md")
+        set_property(TARGET openttd_lib PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
+        set_property(TARGET openttd PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
+        set_property(TARGET openttd_test PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
+     endif()
 endif()
 
 target_precompile_headers(openttd_lib
diff --git a/cmake/CompileFlags.cmake b/cmake/CompileFlags.cmake
index a499714481..ef2ea2dd49 100644
--- a/cmake/CompileFlags.cmake
+++ b/cmake/CompileFlags.cmake
@@ -4,23 +4,6 @@
 #
 macro(compile_flags)
     if(MSVC)
-        if(VCPKG_TARGET_TRIPLET MATCHES "-static" AND NOT VCPKG_TARGET_TRIPLET MATCHES "-md")
-            # Switch to MT (static) instead of MD (dynamic) binary
-
-            # For MSVC two generators are available
-            # - a command line generator (Ninja) using CMAKE_BUILD_TYPE to specify the
-            #   configuration of the build tree
-            # - an IDE generator (Visual Studio) using CMAKE_CONFIGURATION_TYPES to
-            #   specify all configurations that will be available in the generated solution
-            list(APPEND MSVC_CONFIGS "${CMAKE_BUILD_TYPE}" "${CMAKE_CONFIGURATION_TYPES}")
-
-            # Set usage of static runtime for all configurations
-            foreach(MSVC_CONFIG ${MSVC_CONFIGS})
-                string(TOUPPER "CMAKE_CXX_FLAGS_${MSVC_CONFIG}" MSVC_FLAGS)
-                string(REPLACE "/MD" "/MT" ${MSVC_FLAGS} "${${MSVC_FLAGS}}")
-            endforeach()
-        endif()
-
         # "If /Zc:rvalueCast is specified, the compiler follows section 5.4 of the
         # C++11 standard". We need C++11 for the way we use threads.
         add_compile_options(/Zc:rvalueCast)