--- a/CMakeLists.txt	2017-11-16 15:31:24.236356700 +0800
+++ b/CMakeLists.txt	2017-11-16 16:01:41.086054700 +0800
@@ -119,9 +119,9 @@
 project(freetype)
 
 
-if (WIN32 AND NOT MINGW AND BUILD_SHARED_LIBS)
-  message(FATAL_ERROR "Building shared libraries on Windows needs MinGW")
-endif ()
+#if (WIN32 AND NOT MINGW AND BUILD_SHARED_LIBS)
+#  message(FATAL_ERROR "Building shared libraries on Windows needs MinGW")
+#endif ()
 
 # Disallow in-source builds
 if ("${PROJECT_BINARY_DIR}" STREQUAL "${PROJECT_SOURCE_DIR}")
@@ -163,6 +163,11 @@
 # Compiler definitions for building the library
 add_definitions(-DFT2_BUILD_LIBRARY)
 
+if (MSVC)
+  add_definitions(-D_CRT_SECURE_NO_WARNINGS)
+  add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)
+endif ()
+
 
 # Find dependencies
 foreach (d ZLIB BZip2 PNG HarfBuzz)
@@ -254,6 +259,19 @@
     "/\\* +(#define +FT_CONFIG_OPTION_USE_HARFBUZZ) +\\*/" "\\1"
     FTOPTION_H "${FTOPTION_H}")
 endif ()
+if (BUILD_SHARED_LIBS)
+  # Windows/MSVC: Define FT_EXPORT and FT_EXPORT_DEF appropriately to dllexport/dllimport when building Freetype DLL
+  if (MSVC)
+    string(REGEX REPLACE
+      "/\\* +(#define +FT_EXPORT\\(x\\)+ +extern x) +\\*/"
+      "#ifdef FT2_BUILD_LIBRARY\n# define FT_EXPORT(x) extern __declspec(dllexport) x\n#else\n# define FT_EXPORT(x) extern __declspec(dllimport) x\n#endif"
+      FTOPTION_H "${FTOPTION_H}")
+    string(REGEX REPLACE
+      "/\\* +(#define +FT_EXPORT_DEF\\(x\\)+ +x) +\\*/"
+      "#ifdef FT2_BUILD_LIBRARY\n# define FT_EXPORT_DEF(x) __declspec(dllexport) x\n#else\n# define FT_EXPORT_DEF(x) __declspec(dllimport) x\n#endif"
+      FTOPTION_H "${FTOPTION_H}")
+  endif ()
+endif ()
 file(WRITE "${PROJECT_BINARY_DIR}/include/freetype/config/ftoption.h-new"
   "${FTOPTION_H}")
 execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different

Add patch for CMake builds
FreeType: Add patch for CMake builds

This enables CMake builds on Visual Studio to build DLLs, so we no
longer need to patch ftoption.h when we start to use CMake to build our
deps.
