--- wolfssl-4.7.0-stable/CMakeLists.txt	2021-02-16 00:29:51.000000000 +0200
+++ wolfssl-4.7.0-stable-patched/CMakeLists.txt	2021-02-25 10:50:37.000000000 +0200
@@ -1508,3 +1508,25 @@
 
 # TODO: Distro build + rules for what to include in the distro.
 #       See various include.am files.
+
+#MSVC patch
+option(LEGACY_MSVC_STATIC "Build with static MSVC runtime" ON)
+if(MSVC AND LEGACY_MSVC_STATIC)
+  message(STATUS "Patching MSVC build for static linking")
+  set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /EHsc /O2")
+  set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /EHa /W3")
+
+  set(CompilerFlags
+          CMAKE_CXX_FLAGS
+          CMAKE_CXX_FLAGS_DEBUG
+          CMAKE_CXX_FLAGS_RELEASE
+          CMAKE_C_FLAGS
+          CMAKE_C_FLAGS_DEBUG
+          CMAKE_C_FLAGS_RELEASE
+          )
+
+  foreach(CompilerFlag ${CompilerFlags})
+    string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
+  endforeach()
+endif()
+
