diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3d96059..56b46ad 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -100,7 +100,7 @@ set(DBUS_LIBEXECDIR          ${CMAKE_INSTALL_FULL_LIBEXECDIR})
 set(DBUS_DATADIR             ${CMAKE_INSTALL_FULL_DATADIR})
 
 #enable building of shared library
-set(BUILD_SHARED_LIBS ON)
+option(BUILD_SHARED_LIBS "Enable building of shared library" ON)
 
 set(INSTALL_TARGETS_DEFAULT_ARGS EXPORT DBus1Targets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
 
@@ -183,6 +183,14 @@ endif()
 find_package(EXPAT)
 find_package(X11)
 find_package(GLIB2)
+
+if(EXPAT_FOUND)
+    if(MINGW)
+        # always linked with static expat lib
+        set(EXPAT_LIBRARIES "${CMAKE_STATIC_LIBRARY_PREFIX}expat${CMAKE_STATIC_LIBRARY_SUFFIX}")
+    endif()
+endif()
+
 if(GLIB2_FOUND)
     option(DBUS_WITH_GLIB "build with glib" ON)
 endif()
@@ -828,12 +836,16 @@ add_custom_target(help-options
 # create pkgconfig file
 #
 if(DBUS_ENABLE_PKGCONFIG)
-    set(PLATFORM_LIBS pthread ${LIBRT})
+    if(NOT MINGW)
+        set(PLATFORM_LIBS pthread ${LIBRT})
+    endif()
     if(PKG_CONFIG_FOUND)
         # convert lists of link libraries into -lstdc++ -lm etc..
-        foreach(LIB ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${PLATFORM_LIBS})
-            set(LIBDBUS_LIBS "${LIBDBUS_LIBS} -l${LIB}")
-        endforeach()
+        if(NOT MINGW)
+            foreach(LIB ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${PLATFORM_LIBS})
+                set(LIBDBUS_LIBS "${LIBDBUS_LIBS} -l${LIB}")
+            endforeach()
+        endif()
         set(original_prefix "${CMAKE_INSTALL_PREFIX}")
         if(DBUS_RELOCATABLE)
             set(pkgconfig_prefix "\${pcfiledir}/../..")
diff --git a/dbus/CMakeLists.txt b/dbus/CMakeLists.txt
index 04f9ca2..8d5a8af 100644
--- a/dbus/CMakeLists.txt
+++ b/dbus/CMakeLists.txt
@@ -262,14 +262,20 @@ find_library(LIBRT rt)
 # for socket() on QNX
 find_library(LIBSOCKET socket)
 
+if(BUILD_SHARED_LIBS)
+    set(LIBRARY_TYPE SHARED)
+else()
+    set(LIBRARY_TYPE STATIC)
+endif()
+
 ### Client library
-add_library(dbus-1 SHARED
+add_library(dbus-1 ${LIBRARY_TYPE}
     ${libdbus_SOURCES}
     ${libdbus_HEADERS}
 )
 
 if(WIN32)
-    if(DEFINED DBUS_LIBRARY_REVISION)
+    if(DEFINED DBUS_LIBRARY_REVISION AND BUILD_SHARED_LIBS)
         set_target_properties(dbus-1 PROPERTIES SUFFIX "-${DBUS_LIBRARY_MAJOR}${CMAKE_SHARED_LIBRARY_SUFFIX}")
         add_custom_command(TARGET dbus-1 POST_BUILD
             COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:dbus-1>" "$<TARGET_FILE_DIR:dbus-1>/${CMAKE_SHARED_LIBRARY_PREFIX}dbus-1${CMAKE_SHARED_LIBRARY_SUFFIX}"
diff --git a/dbus/dbus-macros.h b/dbus/dbus-macros.h
index 5ca7bf0..5ba490e 100644
--- a/dbus/dbus-macros.h
+++ b/dbus/dbus-macros.h
@@ -198,7 +198,7 @@
 
 #if defined(DBUS_EXPORT)
   /* value forced by compiler command line, don't redefine */
-#elif defined(_WIN32)
+#elif defined(_MSC_VER)
 #  if defined(DBUS_STATIC_BUILD)
 #  define DBUS_EXPORT
 #  elif defined(dbus_1_EXPORTS)
diff --git a/dbus/dbus-macros-internal.h b/dbus/dbus-macros-internal.h
index 474a84b..986e955 100644
--- a/dbus/dbus-macros-internal.h
+++ b/dbus/dbus-macros-internal.h
@@ -38,7 +38,7 @@
 
 #if defined(DBUS_PRIVATE_EXPORT)
   /* value forced by compiler command line, don't redefine */
-#elif defined(_WIN32)
+#elif defined(_MSC_VER)
 #  if defined(DBUS_STATIC_BUILD)
 #    define DBUS_PRIVATE_EXPORT /* no decoration */
 #  elif defined(dbus_1_EXPORTS)
