--- netcdf-4.6.0/CMakeLists.txt.orig	2018-01-25 18:32:02.000000000 +0100
+++ netcdf-4.6.0/CMakeLists.txt	2018-03-16 18:07:25.976347300 +0100
@@ -169,7 +169,7 @@
 
 # Set Memory test program for non-MSVC based builds.
 # Assume valgrind for now.
-IF(NOT MSVC)
+IF((NOT MSVC) AND (NOT MINGW))
   SET(CTEST_MEMORYCHECK_COMMAND valgrind CACHE STRING "")
 ENDIF()
 
@@ -249,10 +249,14 @@
 
 ADD_DEFINITIONS()
 
+# Add specific flags for environments that use the windows runtime (MSVC and MINGW)
 # Suppress CRT Warnings.
-# Only necessary for Windows
-IF(MSVC)
+# specify tempfile
+# specify exceptions in sscanf
+IF(MSVC OR MINGW)
   ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
+  SET (HAVE_WIN_TEMP ON)
+  SET (HAVE_WIN_SSCANF ON)
 ENDIF()
 
 #####
@@ -273,7 +277,7 @@
 # Configuration for post-install RPath
 # Adapted from http://www.cmake.org/Wiki/CMake_RPATH_handling
 ##
-IF(NOT MSVC AND BUILD_SHARED_LIBS)
+IF(NOT WIN32 AND BUILD_SHARED_LIBS)
   # use, i.e. don't skip the full RPATH for the build tree
   SET(CMAKE_SKIP_BUILD_RPATH  FALSE)
 
@@ -891,7 +895,7 @@
   SET(NC_CTEST_DROP_LOC_PREFIX "" CACHE STRING "Prefix for Dashboard location on remote server when using CTest-based testing.")
 
   FIND_PROGRAM(HOSTNAME_CMD NAMES hostname)
-  IF(NOT MSVC)
+  IF(NOT WIN32)
     SET(HOSTNAME_ARG "-s")
   ENDIF()
   IF(HOSTNAME_CMD)
@@ -1379,7 +1383,9 @@
 CHECK_FUNCTION_EXISTS(strndup HAVE_STRNDUP)
 CHECK_FUNCTION_EXISTS(strtoll HAVE_STRTOLL)
 CHECK_FUNCTION_EXISTS(strtoull  HAVE_STRTOULL)
-CHECK_FUNCTION_EXISTS(mkstemp HAVE_MKSTEMP)
+IF (NOT MINGW)
+   CHECK_FUNCTION_EXISTS(mkstemp HAVE_MKSTEMP)
+ENDIF(NOT MINGW)
 CHECK_FUNCTION_EXISTS(mktemp HAVE_MKTEMP)
 CHECK_FUNCTION_EXISTS(random HAVE_RANDOM)
 CHECK_FUNCTION_EXISTS(gettimeofday  HAVE_GETTIMEOFDAY)
