diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 20b578a..52cea7c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -83,10 +83,6 @@ ADD_LIBRARY(common_obj OBJECT ${common_src})
 SET_TARGET_PROPERTIES(common_obj PROPERTIES
     POSITION_INDEPENDENT_CODE ON
     COMPILE_DEFINITIONS "PAHO_MQTT_EXPORTS=1")
-ADD_EXECUTABLE(MQTTVersion MQTTVersion.c)
-SET_TARGET_PROPERTIES(MQTTVersion PROPERTIES
-    POSITION_INDEPENDENT_CODE ON
-    COMPILE_DEFINITIONS "PAHO_MQTT_IMPORTS=1")
 ENDIF()
 
 IF (PAHO_BUILD_STATIC)    
@@ -96,89 +92,153 @@ SET_TARGET_PROPERTIES(common_obj_static PROPERTIES
     COMPILE_DEFINITIONS "PAHO_MQTT_STATIC=1")
 ENDIF()
 
-IF (PAHO_BUILD_SHARED)
-    ADD_LIBRARY(paho-mqtt3c SHARED $<TARGET_OBJECTS:common_obj> MQTTClient.c)
-    ADD_LIBRARY(paho-mqtt3a SHARED $<TARGET_OBJECTS:common_obj> MQTTAsync.c)
-    
-    TARGET_LINK_LIBRARIES(paho-mqtt3c ${LIBS_SYSTEM})
-    TARGET_LINK_LIBRARIES(paho-mqtt3a ${LIBS_SYSTEM})
-    TARGET_LINK_LIBRARIES(MQTTVersion paho-mqtt3a paho-mqtt3c ${LIBS_SYSTEM})
-    
-    SET_TARGET_PROPERTIES(
-        paho-mqtt3c paho-mqtt3a PROPERTIES
-        VERSION ${CLIENT_VERSION}
-        SOVERSION ${PAHO_VERSION_MAJOR}
-        COMPILE_DEFINITIONS "PAHO_MQTT_EXPORTS=1")
-
-    IF(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
-		SET(MQTTCLIENT_ENTRY_POINT _MQTTClient_init)
-		SET(MQTTASYNC_ENTRY_POINT _MQTTAsync_init)
-	ELSEIF (NOT WIN32)
-		SET(MQTTCLIENT_ENTRY_POINT MQTTClient_init)
-		SET(MQTTASYNC_ENTRY_POINT MQTTAsync_init)
-	ENDIF()
-
-    IF (NOT WIN32)
-        SET_TARGET_PROPERTIES(
-            paho-mqtt3c PROPERTIES
-            LINK_FLAGS "-Wl,-init,${MQTTCLIENT_ENTRY_POINT}")
-        SET_TARGET_PROPERTIES(
-            paho-mqtt3a PROPERTIES
-            LINK_FLAGS "-Wl,-init,${MQTTASYNC_ENTRY_POINT}")
+IF (NOT PAHO_WITH_SSL)
+    IF (PAHO_BUILD_SHARED)
+        IF (PAHO_BUILD_ASYNC)
+            ADD_LIBRARY(paho-mqtt3a SHARED $<TARGET_OBJECTS:common_obj> MQTTAsync.c)
+            TARGET_LINK_LIBRARIES(paho-mqtt3a ${LIBS_SYSTEM})
+                       
+            SET_TARGET_PROPERTIES(
+                paho-mqtt3a PROPERTIES
+                VERSION ${CLIENT_VERSION}
+                SOVERSION ${PAHO_VERSION_MAJOR}
+                COMPILE_DEFINITIONS "PAHO_MQTT_EXPORTS=1")
+                        
+            IF(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
+                SET(MQTTASYNC_ENTRY_POINT _MQTTAsync_init)
+            ELSEIF (NOT WIN32)
+                SET(MQTTASYNC_ENTRY_POINT MQTTAsync_init)
+            ENDIF()            
+        
+            IF (NOT WIN32)
+                SET_TARGET_PROPERTIES(
+                    paho-mqtt3a PROPERTIES
+                    LINK_FLAGS "-Wl,-init,${MQTTASYNC_ENTRY_POINT}")
+            ENDIF()
+        
+            FOREACH(TARGET paho-mqtt3a)
+                TARGET_INCLUDE_DIRECTORIES(${TARGET}
+                    PUBLIC
+                        $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
+                        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
+                    PRIVATE
+                        ${CMAKE_BINARY_DIR})
+            ENDFOREACH()
+            
+            INSTALL(TARGETS paho-mqtt3a
+                EXPORT eclipse-paho-mqtt-cTargets
+                ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+                LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+                RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
+            
+        ELSE()
+            ADD_LIBRARY(paho-mqtt3c SHARED $<TARGET_OBJECTS:common_obj> MQTTClient.c)
+            TARGET_LINK_LIBRARIES(paho-mqtt3c ${LIBS_SYSTEM})
+            
+            SET_TARGET_PROPERTIES(
+                paho-mqtt3c PROPERTIES
+                VERSION ${CLIENT_VERSION}
+                SOVERSION ${PAHO_VERSION_MAJOR}
+                COMPILE_DEFINITIONS "PAHO_MQTT_EXPORTS=1")
+                
+            IF(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
+                SET(MQTTCLIENT_ENTRY_POINT _MQTTClient_init)
+            ELSEIF (NOT WIN32)
+                SET(MQTTCLIENT_ENTRY_POINT MQTTClient_init)
+            ENDIF()
+            
+            IF (NOT WIN32)
+                SET_TARGET_PROPERTIES(
+                    paho-mqtt3c PROPERTIES
+                    LINK_FLAGS "-Wl,-init,${MQTTCLIENT_ENTRY_POINT}")
+            ENDIF()
+        
+            FOREACH(TARGET paho-mqtt3c)
+                TARGET_INCLUDE_DIRECTORIES(${TARGET}
+                    PUBLIC
+                        $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
+                        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
+                    PRIVATE
+                        ${CMAKE_BINARY_DIR})
+            ENDFOREACH()
+            
+            INSTALL(TARGETS paho-mqtt3c
+                EXPORT eclipse-paho-mqtt-cTargets
+                ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+                LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+                RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
+            
+        ENDIF()
     ENDIF()
-
-    FOREACH(TARGET paho-mqtt3c paho-mqtt3a)
-        TARGET_INCLUDE_DIRECTORIES(${TARGET}
-            PUBLIC
-                $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
-                $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
-            PRIVATE
-                ${CMAKE_BINARY_DIR})
-    ENDFOREACH()
     
-	INSTALL(TARGETS paho-mqtt3c paho-mqtt3a
-		EXPORT eclipse-paho-mqtt-cTargets
-		ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
-		LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
-		RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
-    INSTALL(TARGETS MQTTVersion
-        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
-ENDIF()
-
-IF (PAHO_BUILD_STATIC)
-    ADD_LIBRARY(paho-mqtt3c-static STATIC $<TARGET_OBJECTS:common_obj_static> MQTTClient.c)
-    ADD_LIBRARY(paho-mqtt3a-static STATIC $<TARGET_OBJECTS:common_obj_static> MQTTAsync.c)
-
-    TARGET_LINK_LIBRARIES(paho-mqtt3c-static ${LIBS_SYSTEM})
-    TARGET_LINK_LIBRARIES(paho-mqtt3a-static ${LIBS_SYSTEM})
-    IF (NOT WIN32)
-        SET_TARGET_PROPERTIES(paho-mqtt3c-static PROPERTIES OUTPUT_NAME paho-mqtt3c)
-        SET_TARGET_PROPERTIES(paho-mqtt3a-static PROPERTIES OUTPUT_NAME paho-mqtt3a)
-    ENDIF()       
-    SET_TARGET_PROPERTIES(
-        paho-mqtt3c-static paho-mqtt3a-static PROPERTIES
-        VERSION ${CLIENT_VERSION}
-        SOVERSION ${PAHO_VERSION_MAJOR}
-        COMPILE_DEFINITIONS "PAHO_MQTT_STATIC=1")
-
-    FOREACH(TARGET paho-mqtt3c-static paho-mqtt3a-static)
-        TARGET_INCLUDE_DIRECTORIES(${TARGET}
-            PUBLIC
-                $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
-                $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
-            PRIVATE
-                ${CMAKE_BINARY_DIR})
-    ENDFOREACH()
-
-    IF (NOT PAHO_BUILD_SHARED)
-        INSTALL(TARGETS paho-mqtt3c-static paho-mqtt3a-static
-            EXPORT eclipse-paho-mqtt-cTargets
-            ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
-            LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
-            RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
-    ELSE()
-        INSTALL(TARGETS paho-mqtt3c-static paho-mqtt3a-static
-            ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
+    IF (PAHO_BUILD_STATIC)
+        IF (PAHO_BUILD_ASYNC)
+            ADD_LIBRARY(paho-mqtt3a-static STATIC $<TARGET_OBJECTS:common_obj_static> MQTTAsync.c)
+            TARGET_LINK_LIBRARIES(paho-mqtt3a-static ${LIBS_SYSTEM})
+            
+            IF (NOT WIN32)
+                SET_TARGET_PROPERTIES(paho-mqtt3a-static PROPERTIES OUTPUT_NAME paho-mqtt3a)
+            ENDIF()       
+            SET_TARGET_PROPERTIES(
+                paho-mqtt3a-static PROPERTIES
+                VERSION ${CLIENT_VERSION}
+                SOVERSION ${PAHO_VERSION_MAJOR}
+                COMPILE_DEFINITIONS "PAHO_MQTT_STATIC=1")
+        
+            FOREACH(TARGET paho-mqtt3a-static)
+                TARGET_INCLUDE_DIRECTORIES(${TARGET}
+                    PUBLIC
+                        $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
+                        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
+                    PRIVATE
+                        ${CMAKE_BINARY_DIR})
+            ENDFOREACH()
+        
+            IF (NOT PAHO_BUILD_SHARED)
+                INSTALL(TARGETS paho-mqtt3a-static
+                    EXPORT eclipse-paho-mqtt-cTargets
+                    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+                    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+                    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
+            ELSE()
+                INSTALL(TARGETS paho-mqtt3a-static
+                    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
+            ENDIF()
+            
+        ELSE()
+            ADD_LIBRARY(paho-mqtt3c-static STATIC $<TARGET_OBJECTS:common_obj_static> MQTTClient.c)
+            TARGET_LINK_LIBRARIES(paho-mqtt3c-static ${LIBS_SYSTEM})
+    
+            IF (NOT WIN32)
+                SET_TARGET_PROPERTIES(paho-mqtt3c-static PROPERTIES OUTPUT_NAME paho-mqtt3c)
+            ENDIF()       
+            SET_TARGET_PROPERTIES(
+                paho-mqtt3c-static PROPERTIES
+                VERSION ${CLIENT_VERSION}
+                SOVERSION ${PAHO_VERSION_MAJOR}
+                COMPILE_DEFINITIONS "PAHO_MQTT_STATIC=1")
+        
+            FOREACH(TARGET paho-mqtt3c-static)
+                TARGET_INCLUDE_DIRECTORIES(${TARGET}
+                    PUBLIC
+                        $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
+                        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
+                    PRIVATE
+                        ${CMAKE_BINARY_DIR})
+            ENDFOREACH()
+        
+            IF (NOT PAHO_BUILD_SHARED)
+                INSTALL(TARGETS paho-mqtt3c-static
+                    EXPORT eclipse-paho-mqtt-cTargets
+                    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+                    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+                    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
+            ELSE()
+                INSTALL(TARGETS paho-mqtt3c-static
+                    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
+            ENDIF()
+            
+        ENDIF()
     ENDIF()
 ENDIF()
 
@@ -197,48 +257,81 @@ IF (PAHO_WITH_SSL)
     	SET_PROPERTY(TARGET common_ssl_obj PROPERTY	POSITION_INDEPENDENT_CODE ON)
     	SET_PROPERTY(TARGET common_ssl_obj PROPERTY COMPILE_DEFINITIONS "OPENSSL=1;PAHO_MQTT_EXPORTS=1")
     
-        ADD_LIBRARY(paho-mqtt3cs SHARED $<TARGET_OBJECTS:common_ssl_obj> MQTTClient.c SSLSocket.c)
-        ADD_LIBRARY(paho-mqtt3as SHARED $<TARGET_OBJECTS:common_ssl_obj> MQTTAsync.c SSLSocket.c)
+        IF (PAHO_BUILD_ASYNC)
+            ADD_LIBRARY(paho-mqtt3as SHARED $<TARGET_OBJECTS:common_ssl_obj> MQTTAsync.c SSLSocket.c)
+        
+            SET_TARGET_PROPERTIES(
+                paho-mqtt3as PROPERTIES
+                VERSION ${CLIENT_VERSION}
+                SOVERSION ${PAHO_VERSION_MAJOR}
+                COMPILE_DEFINITIONS "OPENSSL=1;PAHO_MQTT_EXPORTS=1")
     
-        SET_TARGET_PROPERTIES(
-            paho-mqtt3cs paho-mqtt3as PROPERTIES
-            VERSION ${CLIENT_VERSION}
-            SOVERSION ${PAHO_VERSION_MAJOR}
-            COMPILE_DEFINITIONS "OPENSSL=1;PAHO_MQTT_EXPORTS=1")
-
-        IF(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
-		    SET(MQTTCLIENT_ENTRY_POINT _MQTTClient_init)
-		    SET(MQTTASYNC_ENTRY_POINT _MQTTAsync_init)
-        ELSEIF (NOT WIN32)
-            SET(MQTTCLIENT_ENTRY_POINT MQTTClient_init)
-		    SET(MQTTASYNC_ENTRY_POINT MQTTAsync_init)
-        ENDIF()
-
-        IF (NOT WIN32)
+            IF(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
+                SET(MQTTASYNC_ENTRY_POINT _MQTTAsync_init)
+            ELSEIF (NOT WIN32)
+                SET(MQTTASYNC_ENTRY_POINT MQTTAsync_init)
+            ENDIF()
+    
+            IF (NOT WIN32)
+                SET_TARGET_PROPERTIES(
+                   paho-mqtt3as PROPERTIES
+                   LINK_FLAGS "-Wl,-init,${MQTTASYNC_ENTRY_POINT}")
+            ENDIF()
+    
+            FOREACH(TARGET paho-mqtt3as)
+                TARGET_INCLUDE_DIRECTORIES(${TARGET}
+                    PUBLIC
+                        $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
+                        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
+                    PRIVATE
+                        ${CMAKE_BINARY_DIR})
+                TARGET_LINK_LIBRARIES(${TARGET}
+                    PUBLIC
+                        OpenSSL::SSL OpenSSL::Crypto ${LIBS_SYSTEM})
+            ENDFOREACH()
+            INSTALL(TARGETS paho-mqtt3as
+                EXPORT eclipse-paho-mqtt-cTargets
+                ARCHIVE DESTINATION  ${CMAKE_INSTALL_LIBDIR}
+                LIBRARY DESTINATION  ${CMAKE_INSTALL_LIBDIR}
+                RUNTIME DESTINATION  ${CMAKE_INSTALL_BINDIR})
+        ELSE()
+            ADD_LIBRARY(paho-mqtt3cs SHARED $<TARGET_OBJECTS:common_ssl_obj> MQTTClient.c SSLSocket.c)
+        
             SET_TARGET_PROPERTIES(
-	           paho-mqtt3cs PROPERTIES
-	           LINK_FLAGS "-Wl,-init,${MQTTCLIENT_ENTRY_POINT}")
-	        SET_TARGET_PROPERTIES(
-	           paho-mqtt3as PROPERTIES
-	           LINK_FLAGS "-Wl,-init,${MQTTASYNC_ENTRY_POINT}")
+                paho-mqtt3cs PROPERTIES
+                VERSION ${CLIENT_VERSION}
+                SOVERSION ${PAHO_VERSION_MAJOR}
+                COMPILE_DEFINITIONS "OPENSSL=1;PAHO_MQTT_EXPORTS=1")
+    
+            IF(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
+                SET(MQTTCLIENT_ENTRY_POINT _MQTTClient_init)
+            ELSEIF (NOT WIN32)
+                SET(MQTTCLIENT_ENTRY_POINT MQTTClient_init)
+            ENDIF()
+    
+            IF (NOT WIN32)
+                SET_TARGET_PROPERTIES(
+                   paho-mqtt3cs PROPERTIES
+                   LINK_FLAGS "-Wl,-init,${MQTTCLIENT_ENTRY_POINT}")
+            ENDIF()
+    
+            FOREACH(TARGET paho-mqtt3cs)
+                TARGET_INCLUDE_DIRECTORIES(${TARGET}
+                    PUBLIC
+                        $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
+                        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
+                    PRIVATE
+                        ${CMAKE_BINARY_DIR})
+                TARGET_LINK_LIBRARIES(${TARGET}
+                    PUBLIC
+                        OpenSSL::SSL OpenSSL::Crypto ${LIBS_SYSTEM})
+            ENDFOREACH()
+            INSTALL(TARGETS paho-mqtt3cs
+                EXPORT eclipse-paho-mqtt-cTargets
+                ARCHIVE DESTINATION  ${CMAKE_INSTALL_LIBDIR}
+                LIBRARY DESTINATION  ${CMAKE_INSTALL_LIBDIR}
+                RUNTIME DESTINATION  ${CMAKE_INSTALL_BINDIR})
         ENDIF()
-
-        FOREACH(TARGET paho-mqtt3cs paho-mqtt3as)
-            TARGET_INCLUDE_DIRECTORIES(${TARGET}
-                PUBLIC
-                    $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
-                    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
-                PRIVATE
-                    ${CMAKE_BINARY_DIR})
-            TARGET_LINK_LIBRARIES(${TARGET}
-                PUBLIC
-                    OpenSSL::SSL OpenSSL::Crypto ${LIBS_SYSTEM})
-        ENDFOREACH()
-        INSTALL(TARGETS paho-mqtt3cs paho-mqtt3as
-            EXPORT eclipse-paho-mqtt-cTargets
-            ARCHIVE DESTINATION  ${CMAKE_INSTALL_LIBDIR}
-            LIBRARY DESTINATION  ${CMAKE_INSTALL_LIBDIR}
-            RUNTIME DESTINATION  ${CMAKE_INSTALL_BINDIR})
     ENDIF()
 
     IF (PAHO_BUILD_STATIC)
@@ -249,57 +342,97 @@ IF (PAHO_WITH_SSL)
     	SET_PROPERTY(TARGET common_ssl_obj_static PROPERTY POSITION_INDEPENDENT_CODE ON)
     	SET_PROPERTY(TARGET common_ssl_obj_static PROPERTY COMPILE_DEFINITIONS "OPENSSL=1;PAHO_MQTT_STATIC=1")
     
-        ADD_LIBRARY(paho-mqtt3cs-static STATIC $<TARGET_OBJECTS:common_ssl_obj_static> MQTTClient.c SSLSocket.c)
-        ADD_LIBRARY(paho-mqtt3as-static STATIC $<TARGET_OBJECTS:common_ssl_obj_static> MQTTAsync.c SSLSocket.c)
-
-        SET_TARGET_PROPERTIES(
-            paho-mqtt3cs-static paho-mqtt3as-static PROPERTIES
-            VERSION ${CLIENT_VERSION}
-            SOVERSION ${PAHO_VERSION_MAJOR}
-            COMPILE_DEFINITIONS "OPENSSL=1;PAHO_MQTT_STATIC=1")
-        IF (NOT WIN32)
-            SET_TARGET_PROPERTIES(paho-mqtt3cs-static PROPERTIES OUTPUT_NAME paho-mqtt3cs)
-            SET_TARGET_PROPERTIES(paho-mqtt3as-static PROPERTIES OUTPUT_NAME paho-mqtt3as)
-        ENDIF()
-
-	    IF(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
-			SET(MQTTCLIENT_ENTRY_POINT _MQTTClient_init)
-			SET(MQTTASYNC_ENTRY_POINT _MQTTAsync_init)
-		ELSEIF (NOT WIN32)
-			SET(MQTTCLIENT_ENTRY_POINT MQTTClient_init)
-			SET(MQTTASYNC_ENTRY_POINT MQTTAsync_init)
-		ENDIF()
-
-		IF (NOT WIN32)
-		    SET_TARGET_PROPERTIES(
-	            paho-mqtt3cs-static PROPERTIES
-	            LINK_FLAGS "-Wl,-init,${MQTTCLIENT_ENTRY_POINT}")
-	        SET_TARGET_PROPERTIES(
-	            paho-mqtt3as-static PROPERTIES
-	            LINK_FLAGS "-Wl,-init,${MQTTASYNC_ENTRY_POINT}")
-	    ENDIF()
-
-        IF (NOT PAHO_BUILD_SHARED)
-            INSTALL(TARGETS paho-mqtt3cs-static paho-mqtt3as-static
-                EXPORT eclipse-paho-mqtt-cTargets
-                ARCHIVE DESTINATION  ${CMAKE_INSTALL_LIBDIR}
-                LIBRARY DESTINATION  ${CMAKE_INSTALL_LIBDIR}
-                RUNTIME DESTINATION  ${CMAKE_INSTALL_BINDIR})
+        IF (PAHO_BUILD_ASYNC)
+            ADD_LIBRARY(paho-mqtt3as-static STATIC $<TARGET_OBJECTS:common_ssl_obj_static> MQTTAsync.c SSLSocket.c)
+    
+            SET_TARGET_PROPERTIES(
+                paho-mqtt3as-static PROPERTIES
+                VERSION ${CLIENT_VERSION}
+                SOVERSION ${PAHO_VERSION_MAJOR}
+                COMPILE_DEFINITIONS "OPENSSL=1;PAHO_MQTT_STATIC=1")
+            IF (NOT WIN32)
+                SET_TARGET_PROPERTIES(paho-mqtt3as-static PROPERTIES OUTPUT_NAME paho-mqtt3as)
+            ENDIF()
+    
+    	    IF(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
+    			SET(MQTTASYNC_ENTRY_POINT _MQTTAsync_init)
+    		ELSEIF (NOT WIN32)
+    			SET(MQTTASYNC_ENTRY_POINT MQTTAsync_init)
+    		ENDIF()
+    
+    		IF (NOT WIN32)
+    	        SET_TARGET_PROPERTIES(
+    	            paho-mqtt3as-static PROPERTIES
+    	            LINK_FLAGS "-Wl,-init,${MQTTASYNC_ENTRY_POINT}")
+    	    ENDIF()
+    
+            IF (NOT PAHO_BUILD_SHARED)
+                INSTALL(TARGETS paho-mqtt3as-static
+                    EXPORT eclipse-paho-mqtt-cTargets
+                    ARCHIVE DESTINATION  ${CMAKE_INSTALL_LIBDIR}
+                    LIBRARY DESTINATION  ${CMAKE_INSTALL_LIBDIR}
+                    RUNTIME DESTINATION  ${CMAKE_INSTALL_BINDIR})
+            ELSE()
+                INSTALL(TARGETS paho-mqtt3as-static
+                    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
+            ENDIF()
+            FOREACH(TARGET paho-mqtt3as-static)
+                TARGET_INCLUDE_DIRECTORIES(${TARGET}
+                    PUBLIC
+                        $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
+                        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
+                    PRIVATE
+                        ${CMAKE_BINARY_DIR})
+                TARGET_LINK_LIBRARIES(${TARGET}
+                    PUBLIC
+                        OpenSSL::SSL OpenSSL::Crypto ${LIBS_SYSTEM})
+            ENDFOREACH()
         ELSE()
-            INSTALL(TARGETS paho-mqtt3cs-static paho-mqtt3as-static
-                ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
+            ADD_LIBRARY(paho-mqtt3cs-static STATIC $<TARGET_OBJECTS:common_ssl_obj_static> MQTTClient.c SSLSocket.c)
+    
+            SET_TARGET_PROPERTIES(
+                paho-mqtt3cs-static PROPERTIES
+                VERSION ${CLIENT_VERSION}
+                SOVERSION ${PAHO_VERSION_MAJOR}
+                COMPILE_DEFINITIONS "OPENSSL=1;PAHO_MQTT_STATIC=1")
+            IF (NOT WIN32)
+                SET_TARGET_PROPERTIES(paho-mqtt3cs-static PROPERTIES OUTPUT_NAME paho-mqtt3cs)
+            ENDIF()
+    
+            IF(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
+                SET(MQTTCLIENT_ENTRY_POINT _MQTTClient_init)
+            ELSEIF (NOT WIN32)
+                SET(MQTTCLIENT_ENTRY_POINT MQTTClient_init)
+            ENDIF()
+    
+            IF (NOT WIN32)
+                SET_TARGET_PROPERTIES(
+                    paho-mqtt3cs-static PROPERTIES
+                    LINK_FLAGS "-Wl,-init,${MQTTCLIENT_ENTRY_POINT}")
+            ENDIF()
+    
+            IF (NOT PAHO_BUILD_SHARED)
+                INSTALL(TARGETS paho-mqtt3cs-static 
+                    EXPORT eclipse-paho-mqtt-cTargets
+                    ARCHIVE DESTINATION  ${CMAKE_INSTALL_LIBDIR}
+                    LIBRARY DESTINATION  ${CMAKE_INSTALL_LIBDIR}
+                    RUNTIME DESTINATION  ${CMAKE_INSTALL_BINDIR})
+            ELSE()
+                INSTALL(TARGETS paho-mqtt3cs-static 
+                    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
+            ENDIF()
+            FOREACH(TARGET paho-mqtt3cs-static)
+                TARGET_INCLUDE_DIRECTORIES(${TARGET}
+                    PUBLIC
+                        $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
+                        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
+                    PRIVATE
+                        ${CMAKE_BINARY_DIR})
+                TARGET_LINK_LIBRARIES(${TARGET}
+                    PUBLIC
+                        OpenSSL::SSL OpenSSL::Crypto ${LIBS_SYSTEM})
+            ENDFOREACH()
         ENDIF()
-        FOREACH(TARGET paho-mqtt3cs-static paho-mqtt3as-static)
-            TARGET_INCLUDE_DIRECTORIES(${TARGET}
-                PUBLIC
-                    $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
-                    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
-                PRIVATE
-                    ${CMAKE_BINARY_DIR})
-            TARGET_LINK_LIBRARIES(${TARGET}
-                PUBLIC
-                    OpenSSL::SSL OpenSSL::Crypto ${LIBS_SYSTEM})
-        ENDFOREACH()
     ENDIF()
 ENDIF()
 
@@ -316,20 +449,3 @@ INSTALL(FILES
     "${CMAKE_CURRENT_BINARY_DIR}/eclipse-paho-mqtt-cConfigVersion.cmake"
     DESTINATION lib/cmake/eclipse-paho-mqtt-c)
 
-# Base64 test
-ADD_EXECUTABLE( Base64Test EXCLUDE_FROM_ALL Base64.c Base64.h )
-TARGET_COMPILE_DEFINITIONS( Base64Test PUBLIC "-DBASE64_TEST" )
-IF (PAHO_WITH_SSL)
-	ADD_EXECUTABLE( Base64TestOpenSSL EXCLUDE_FROM_ALL Base64.c Base64.h )
-	TARGET_LINK_LIBRARIES( Base64TestOpenSSL OpenSSL::SSL OpenSSL::Crypto)
-	TARGET_COMPILE_DEFINITIONS( Base64TestOpenSSL PUBLIC "-DBASE64_TEST -DOPENSSL=1" )
-ENDIF (PAHO_WITH_SSL)
-
-# SHA1 test
-ADD_EXECUTABLE( Sha1Test EXCLUDE_FROM_ALL SHA1.c SHA1.h )
-TARGET_COMPILE_DEFINITIONS( Sha1Test PUBLIC "-DSHA1_TEST" )
-IF (PAHO_WITH_SSL)
-	ADD_EXECUTABLE( Sha1TestOpenSSL EXCLUDE_FROM_ALL SHA1.c SHA1.h )
-	TARGET_LINK_LIBRARIES( Sha1TestOpenSSL OpenSSL::SSL OpenSSL::Crypto)
-	TARGET_COMPILE_DEFINITIONS( Sha1TestOpenSSL PUBLIC "-DSHA1_TEST -DOPENSSL=1" )
-ENDIF (PAHO_WITH_SSL)
