diff --git a/CMakeLists.txt b/CMakeLists.txt
index b53745b..d8787d8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -37,7 +37,7 @@ STRING(TIMESTAMP BUILD_TIMESTAMP UTC)
 MESSAGE(STATUS "Timestamp is ${BUILD_TIMESTAMP}")
 
 IF(WIN32)
-  ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE -DWIN32_LEAN_AND_MEAN -MD)
+  ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE -DWIN32_LEAN_AND_MEAN)
 ELSEIF(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
   ADD_DEFINITIONS(-DOSX)
 ENDIF()
@@ -61,34 +61,6 @@ IF(PAHO_BUILD_DOCUMENTATION)
     ADD_SUBDIRECTORY(doc)
 ENDIF()
 
-IF (PAHO_ENABLE_CPACK)
-       ### packaging settings
-       FILE(GLOB samples "src/samples/*.c")
-       INSTALL(FILES ${samples} DESTINATION samples)
-
-       SET(CPACK_PACKAGE_VENDOR "Eclipse Paho")
-       SET(CPACK_PACKAGE_NAME "Eclipse-Paho-MQTT-C")
-       INSTALL(FILES CONTRIBUTING.md epl-v10 edl-v10 README.md notice.html DESTINATION .)
-
-       IF (WIN32)
-               SET(CPACK_GENERATOR "ZIP")
-       ELSEIF(PAHO_BUILD_DEB_PACKAGE)
-               INSTALL(FILES CONTRIBUTING.md epl-v10 edl-v10 README.md notice.html DESTINATION .)
-
-               SET(CPACK_GENERATOR "DEB")
-               CONFIGURE_FILE(${CMAKE_SCRIPTS}/CPackDebConfig.cmake.in
-                       ${CMAKE_BINARY_DIR}/CPackDebConfig.cmake @ONLY)
-               SET(CPACK_PROJECT_CONFIG_FILE ${CMAKE_BINARY_DIR}/CPackDebConfig.cmake)
-               ADD_SUBDIRECTORY(debian)
-       ELSE()
-               SET(CPACK_GENERATOR "TGZ")
-       ENDIF()
-ELSE()
-       FILE(GLOB samples "src/samples/*.c")
-       INSTALL(FILES ${samples} DESTINATION ${CMAKE_INSTALL_DOCDIR})
-
-ENDIF()
-
 SET(CPACK_PACKAGE_VERSION_MAJOR ${PAHO_VERSION_MAJOR})
 SET(CPACK_PACKAGE_VERSION_MINOR ${PAHO_VERSION_MINOR})
 SET(CPACK_PACKAGE_VERSION_PATCH ${PAHO_VERSION_PATCH})
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b46eaca..399b37d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -55,7 +55,7 @@ SET(common_src
     )
 
 IF (WIN32)
-    SET(LIBS_SYSTEM ws2_32)
+    SET(LIBS_SYSTEM ws2_32 rpcrt4 crypt32 wsock32)
 ELSEIF (UNIX)
     IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
         SET(LIBS_SYSTEM c dl pthread)
diff --git a/src/MQTTAsync.c b/src/MQTTAsync.c
index a5813b4..4f209ec 100644
--- a/src/MQTTAsync.c
+++ b/src/MQTTAsync.c
@@ -205,6 +205,14 @@ START_TIME_TYPE MQTTAsync_start_clock(void)
 	clock_gettime(CLOCK_MONOTONIC, &start);
 	return start;
 }
+#elif defined(__APPLE__) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101200
+#define START_TIME_TYPE struct timeval
+START_TIME_TYPE MQTTAsync_start_clock(void)
+{
+	static struct timeval start;
+	gettimeofday(&start, NULL);
+	return start;
+}
 #else
 #define START_TIME_TYPE struct timeval
 START_TIME_TYPE MQTTAsync_start_clock(void)
@@ -235,6 +243,16 @@ long MQTTAsync_elapsed(struct timespec start)
 	ntimersub(now, start, res);
 	return (res.tv_sec)*1000L + (res.tv_nsec)/1000000L;
 }
+#elif defined(__APPLE__) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101200
+
+long MQTTAsync_elapsed(struct timeval start)
+{
+	struct timeval now, res;
+
+	gettimeofday(&now, NULL);
+	timersub(&now, &start, &res);
+	return (res.tv_sec)*1000 + (res.tv_usec)/1000;
+}
 #else
 long MQTTAsync_elapsed(struct timeval start)
 {
diff --git a/src/MQTTClient.c b/src/MQTTClient.c
index 2069ff9..faee1ae 100644
--- a/src/MQTTClient.c
+++ b/src/MQTTClient.c
@@ -258,6 +258,14 @@ START_TIME_TYPE MQTTClient_start_clock(void)
 	clock_gettime(CLOCK_MONOTONIC, &start);
 	return start;
 }
+#elif defined(__APPLE__) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101200
+#define START_TIME_TYPE struct timeval
+START_TIME_TYPE MQTTClient_start_clock(void)
+{
+	static struct timeval start;
+	gettimeofday(&start, NULL);
+	return start;
+}
 #else
 #define START_TIME_TYPE struct timeval
 START_TIME_TYPE MQTTClient_start_clock(void)
@@ -288,6 +296,15 @@ long MQTTClient_elapsed(struct timespec start)
 	ntimersub(now, start, res);
 	return (res.tv_sec)*1000L + (res.tv_nsec)/1000000L;
 }
+#elif defined(__APPLE__) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101200
+long MQTTClient_elapsed(struct timeval start)
+{
+	struct timeval now, res;
+
+	gettimeofday(&now, NULL);
+	timersub(&now, &start, &res);
+	return (res.tv_sec)*1000 + (res.tv_usec)/1000;
+}
 #else
 long MQTTClient_elapsed(struct timeval start)
 {
diff --git a/src/Thread.c b/src/Thread.c
index 4cb2f16..40ce8dc 100644
--- a/src/Thread.c
+++ b/src/Thread.c
@@ -409,9 +409,16 @@ int Thread_wait_cond(cond_type condvar, int timeout)
 	struct timespec cond_timeout;
 
 	FUNC_ENTRY;
+#if defined(__APPLE__) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101200
+    struct timeval cur_time;
+    gettimeofday(&cur_time, NULL);
+    cond_timeout.tv_sec = cur_time.tv_sec + timeout;
+    cond_timeout.tv_nsec = cur_time.tv_usec * 1000;
+#else
 	clock_gettime(CLOCK_REALTIME, &cond_timeout);
 
 	cond_timeout.tv_sec += timeout;
+#endif
 	pthread_mutex_lock(&condvar->mutex);
 	rc = pthread_cond_timedwait(&condvar->cond, &condvar->mutex, &cond_timeout);
 	pthread_mutex_unlock(&condvar->mutex);
diff --git a/src/WebSocket.c b/src/WebSocket.c
index 47b1dad..3f96dac 100644
--- a/src/WebSocket.c
+++ b/src/WebSocket.c
@@ -28,6 +28,11 @@
 #include "MQTTProtocolOut.h"
 #include "StackTrace.h"
 
+#ifdef __MINGW32__
+#define htonll __builtin_bswap64
+#define ntohll __builtin_bswap64
+#endif
+
 #if defined(__linux__)
 #  include <endian.h>
 #elif defined(__APPLE__)
