diff -Naur hdf-4.2.13-orig/mfhdf/fortran/mfsdf.c hdf-4.2.13/mfhdf/fortran/mfsdf.c
--- hdf-4.2.13-orig/mfhdf/fortran/mfsdf.c	2017-06-25 00:00:04.000000000 +0300
+++ hdf-4.2.13/mfhdf/fortran/mfsdf.c	2018-02-14 14:18:43.158693200 +0300
@@ -47,7 +47,7 @@
 FRETVAL(intf) nsfsflmd();
 #endif /* PROTOTYPE */
 
-#if defined _WIN32 && !defined CMAKE_INTDIR
+#if defined _MSC_VER && !defined CMAKE_INTDIR
 
 /*-----------------------------------------------------------------------------
  * Name:    scend
diff -Naur hdf-4.2.13-orig/mfhdf/hdfimport/CMakeLists.txt hdf-4.2.13/mfhdf/hdfimport/CMakeLists.txt
--- hdf-4.2.13-orig/mfhdf/hdfimport/CMakeLists.txt	2017-06-25 00:00:04.000000000 +0300
+++ hdf-4.2.13/mfhdf/hdfimport/CMakeLists.txt	2018-02-14 14:15:22.137034200 +0300
@@ -4,7 +4,7 @@
 INCLUDE_DIRECTORIES (${HDF4_HDFSOURCE_DIR})
 INCLUDE_DIRECTORIES (${HDF4_MFHDFSOURCE_DIR})
 
-if (WIN32)
+if (MSVC)
   set (CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:LIBCMT")
 endif ()
 
diff -Naur hdf-4.2.13-orig/mfhdf/hdiff/CMakeLists.txt hdf-4.2.13/mfhdf/hdiff/CMakeLists.txt
--- hdf-4.2.13-orig/mfhdf/hdiff/CMakeLists.txt	2017-06-25 00:00:04.000000000 +0300
+++ hdf-4.2.13/mfhdf/hdiff/CMakeLists.txt	2018-02-14 14:13:01.839865000 +0300
@@ -4,7 +4,7 @@
 INCLUDE_DIRECTORIES (${HDF4_HDFSOURCE_DIR})
 INCLUDE_DIRECTORIES (${HDF4_MFHDFSOURCE_DIR})
 
-if (WIN32)
+if (MSVC)
   set (CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:LIBCMT")
 endif ()
 
diff -Naur hdf-4.2.13-orig/mfhdf/xdr/CMakeLists.txt hdf-4.2.13/mfhdf/xdr/CMakeLists.txt
--- hdf-4.2.13-orig/mfhdf/xdr/CMakeLists.txt	2017-06-25 00:00:04.000000000 +0300
+++ hdf-4.2.13/mfhdf/xdr/CMakeLists.txt	2018-02-14 14:17:33.189816100 +0300
@@ -16,7 +16,7 @@
 if (NOT ONLY_SHARED_LIBS)
   add_library (${HDF4_MF_XDR_LIB_TARGET} STATIC ${HDF4_MFHDF_XDR_SRCS} ${HDF4_MFHDF_XDR_HDRS})
   target_include_directories(${HDF4_MF_XDR_LIB_TARGET} PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDF_XDR_SOURCE_DIR}")
-  target_link_libraries (${HDF4_MF_XDR_LIB_TARGET} PUBLIC $<$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:MinGW>>:ws2_32.lib>)
+  target_link_libraries (${HDF4_MF_XDR_LIB_TARGET} PUBLIC "$<$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:MinGW>>:ws2_32;wsock32>")
   TARGET_C_PROPERTIES (${HDF4_MF_XDR_LIB_TARGET} STATIC)
   set_global_variable (HDF4_LIBRARIES_TO_EXPORT "${HDF4_LIBRARIES_TO_EXPORT};${HDF4_MF_XDR_LIB_TARGET}")
   H4_SET_LIB_OPTIONS (${HDF4_MF_XDR_LIB_TARGET} ${HDF4_MF_XDR_LIB_NAME} STATIC)
@@ -31,7 +31,7 @@
 if (BUILD_SHARED_LIBS)
   add_library (${HDF4_MF_XDR_LIBSH_TARGET} SHARED ${HDF4_MFHDF_XDR_SRCS} ${HDF4_MFHDF_XDR_HDRS})
   target_include_directories(${HDF4_MF_XDR_LIBSH_TARGET} PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDF_XDR_SOURCE_DIR}")
-  target_link_libraries (${HDF4_MF_XDR_LIBSH_TARGET} PUBLIC $<$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:MinGW>>:ws2_32.lib>)
+  target_link_libraries (${HDF4_MF_XDR_LIBSH_TARGET} PUBLIC "$<$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:MinGW>>:ws2_32;wsock32>")
   TARGET_C_PROPERTIES (${HDF4_MF_XDR_LIBSH_TARGET} SHARED)
   set_global_variable (HDF4_LIBRARIES_TO_EXPORT "${HDF4_LIBRARIES_TO_EXPORT};${HDF4_MF_XDR_LIBSH_TARGET}")
   H4_SET_LIB_OPTIONS (${HDF4_MF_XDR_LIBSH_TARGET} ${HDF4_MF_XDR_LIB_NAME} SHARED)
diff -Naur hdf-4.2.13-orig/config/cmake_ext_mod/ConfigureChecks.cmake hdf-4.2.13/config/cmake_ext_mod/ConfigureChecks.cmake
--- hdf-4.2.13-orig/config/cmake_ext_mod/ConfigureChecks.cmake	2017-06-25 00:00:04.000000000 +0300
+++ hdf-4.2.13/config/cmake_ext_mod/ConfigureChecks.cmake	2018-02-14 14:44:48.177061500 +0300
@@ -70,16 +70,18 @@
 endif ()
 
 if (WINDOWS)
-  set (HDF4_REQUIRED_LIBRARIES "ws2_32.lib;wsock32.lib")
+  if (MINGW)
+    set (HDF4_REQUIRED_LIBRARIES "ws2_32;wsock32")
+  else ()
+    set (HDF4_REQUIRED_LIBRARIES "ws2_32.lib;wsock32.lib")
+  endif ()
   set (${HDF_PREFIX}_HAVE_WIN32_API 1)
   set (${HDF_PREFIX}_HAVE_LIBM 1)
   set (${HDF_PREFIX}_HAVE_STRDUP 1)
   set (${HDF_PREFIX}_HAVE_SYSTEM 1)
   set (${HDF_PREFIX}_HAVE_LONGJMP 1)
-  if (NOT MINGW)
-    set (${HDF_PREFIX}_HAVE_GETHOSTNAME 1)
-    set (${HDF_PREFIX}_HAVE_FUNCTION 1)
-  endif ()
+  set (${HDF_PREFIX}_HAVE_GETHOSTNAME 1)
+  set (${HDF_PREFIX}_HAVE_FUNCTION 1)
   if (NOT UNIX AND NOT CYGWIN)
     set (${HDF_PREFIX}_HAVE_GETCONSOLESCREENBUFFERINFO 1)
     set (${HDF_PREFIX}_GETTIMEOFDAY_GIVES_TZ 1)
diff -Naur hdf-4.2.13-orig/config/cmake_ext_mod/HDFMacros.cmake hdf-4.2.13/config/cmake_ext_mod/HDFMacros.cmake
--- hdf-4.2.13-orig/config/cmake_ext_mod/HDFMacros.cmake	2017-06-25 00:00:04.000000000 +0300
+++ hdf-4.2.13/config/cmake_ext_mod/HDFMacros.cmake	2018-02-14 14:51:20.357611800 +0300
@@ -155,7 +155,7 @@
   endif ()
 
   #----- Use MSVC Naming conventions for Shared Libraries
-  if (MINGW AND ${libtype} MATCHES "SHARED")
+  if (MSVC AND ${libtype} MATCHES "SHARED")
     set_target_properties (${libtarget}
         PROPERTIES
         IMPORT_SUFFIX ".lib"
@@ -178,7 +178,7 @@
 
   if (${libtype} MATCHES "SHARED")
     if (WIN32)
-      if (MINGW)
+      if (MSVC)
         set_target_properties (${libtarget} PROPERTIES
             IMPORTED_IMPLIB "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${IMPORT_LIB_NAME}.lib"
             IMPORTED_LOCATION "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${IMPORT_LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}"
@@ -207,7 +207,7 @@
       endif ()
     endif ()
   else ()
-    if (WIN32 AND NOT MINGW)
+    if (MSVC)
       set_target_properties (${libtarget} PROPERTIES
           IMPORTED_LOCATION "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_BUILD_TYPE}/${IMPORT_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}"
           IMPORTED_LINK_INTERFACE_LANGUAGES "C"
@@ -236,7 +236,7 @@
 macro (HDF_README_PROPERTIES target_fortran)
   set (BINARY_SYSTEM_NAME ${CMAKE_SYSTEM_NAME})
   set (BINARY_PLATFORM "${CMAKE_SYSTEM_NAME}")
-  if (WIN32)
+  if (MSVC)
     set (BINARY_EXAMPLE_ENDING "zip")
     set (BINARY_INSTALL_ENDING "msi")
     if (CMAKE_CL_64)
diff -Naur hdf-4.2.13-orig/mfhdf/dumper/CMakeLists.txt hdf-4.2.13/mfhdf/dumper/CMakeLists.txt
--- hdf-4.2.13-orig/mfhdf/dumper/CMakeLists.txt	2017-06-25 00:00:04.000000000 +0300
+++ hdf-4.2.13/mfhdf/dumper/CMakeLists.txt	2018-02-14 15:19:28.071305100 +0300
@@ -20,7 +20,7 @@
   target_link_libraries (hdp PRIVATE ${HDF4_MF_LIB_TARGET})
   set_target_properties (hdp PROPERTIES COMPILE_DEFINITIONS "HDF")
-  if (WIN32)
+  if (MSVC)
     set_target_properties (hdp PROPERTIES LINK_FLAGS "/STACK:10000000")
   endif ()
   set_global_variable (HDF4_UTILS_TO_EXPORT "${HDF4_UTILS_TO_EXPORT};hdp")
 
--- hdf-4.2.15/hdf/src/H4api_adpt.h.orig	2020-04-26 14:24:33.590855400 +0300
+++ hdf-4.2.15/hdf/src/H4api_adpt.h	2020-04-26 14:24:37.252966200 +0300
@@ -38,7 +38,7 @@
 
 #if defined(hdf_shared_EXPORTS)
   #if defined (_MSC_VER) || defined(__MINGW32__)  /* MSVC Compiler Case */
-    #define HDFERRPUBLIC extern __declspec(dllimport)
+    #define HDFERRPUBLIC extern __declspec(dllexport)
     #define HDFPUBLIC __declspec(dllexport)
     #define HDFLIBAPI extern __declspec(dllexport)
     #define HDFFCLIBAPI extern __declspec(dllimport)
--- hdf-4.2.15/config/cmake/h4config.h.in.orig	2020-04-26 18:54:53.111592500 +0300
+++ hdf-4.2.15/config/cmake/h4config.h.in	2020-04-26 18:55:43.931415700 +0300
@@ -131,6 +131,9 @@
 /* Define to 1 if you have the `wait' function. */
 #cmakedefine H4_HAVE_WAIT @H4_HAVE_WAIT@
 
+/* Define to 1 if you have the <winsock2.h> header. */
+#cmakedefine H4_HAVE_WINSOCK2_H @H4_HAVE_WINSOCK2_H@
+
 /* Define to 1 if you have the <zlib.h> header file. */
 #cmakedefine H4_HAVE_ZLIB_H @H4_HAVE_ZLIB_H@
 
--- hdf-4.2.15/hdf/src/hdfi.h.orig	2020-03-03 23:10:50.000000000 +0530
+++ hdf-4.2.15/hdf/src/hdfi.h	2021-05-16 11:26:41.596178300 +0530
@@ -579,7 +579,7 @@
 #endif
 #define GOT_MACHINE 1
 
-#if defined _WINDOWS || defined _WIN32
+#ifdef _MSC_VER
 #pragma comment( lib, "oldnames" )
 #endif
 
