- Modified CMakeLists to support zlib

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 689d563..bae87e3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -17,6 +17,8 @@
 
 option(USE_PKCS11_HELPER_LIBRARY "Build PolarSSL with the pkcs11-helper library." OFF)
 
+option(ENABLE_ZLIB_SUPPORT "Build PolarSSL with zlib library." OFF)
+
 if(LIB_INSTALL_DIR)
 else()
 set(LIB_INSTALL_DIR lib)
@@ -24,6 +26,14 @@
 
 include_directories(include/)
 
+if(ENABLE_ZLIB_SUPPORT)
+  find_package(ZLIB)
+
+  if(ZLIB_FOUND)
+    include_directories(ZLIB_INCLUDE_DIR)
+  endif(ZLIB_FOUND)
+endif(ENABLE_ZLIB_SUPPORT)
+
 add_subdirectory(library)
 add_subdirectory(include)
 
diff --git a/programs/ssl/CMakeLists.txt b/programs/ssl/CMakeLists.txt
index 4dcf01c..1986b08 100644
--- a/programs/ssl/CMakeLists.txt
+++ b/programs/ssl/CMakeLists.txt
@@ -6,6 +6,10 @@
     set(libs ${libs} pkcs11-helper)
 endif(USE_PKCS11_HELPER_LIBRARY)
 
+if(ENABLE_ZLIB_SUPPORT)
+    set(libs ${libs} ${ZLIB_LIBRARIES})
+endif(ENABLE_ZLIB_SUPPORT)
+
 add_executable(ssl_client1 ssl_client1.c)
 target_link_libraries(ssl_client1 ${libs})
 
diff --git a/programs/test/CMakeLists.txt b/programs/test/CMakeLists.txt
index f00fc9d..c05b903 100644
--- a/programs/test/CMakeLists.txt
+++ b/programs/test/CMakeLists.txt
@@ -8,6 +8,10 @@
     set(libs ${libs} pkcs11-helper)
 endif(USE_PKCS11_HELPER_LIBRARY)
 
+if(ENABLE_ZLIB_SUPPORT)
+    set(libs ${libs} ${ZLIB_LIBRARIES})
+endif(ENABLE_ZLIB_SUPPORT)
+
 add_executable(selftest selftest.c)
 target_link_libraries(selftest ${libs})
 
diff --git a/programs/x509/CMakeLists.txt b/programs/x509/CMakeLists.txt
index 554d9a0..08a962a 100644
--- a/programs/x509/CMakeLists.txt
+++ b/programs/x509/CMakeLists.txt
@@ -6,6 +6,10 @@
     set(libs ${libs} pkcs11-helper)
 endif(USE_PKCS11_HELPER_LIBRARY)
 
+if(ENABLE_ZLIB_SUPPORT)
+    set(libs ${libs} ${ZLIB_LIBRARIES})
+endif(ENABLE_ZLIB_SUPPORT)
+
 add_executable(cert_app cert_app.c)
 target_link_libraries(cert_app ${libs})
 
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 494fd2b..3ff4f0b 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -6,6 +6,10 @@
     set(libs ${libs} pkcs11-helper)
 endif(USE_PKCS11_HELPER_LIBRARY)
 
+if(ENABLE_ZLIB_SUPPORT)
+    set(libs ${libs} ${ZLIB_LIBRARIES})
+endif(ENABLE_ZLIB_SUPPORT)
+
 function(add_test_suite suite_name)
     if(ARGV1)
     set(data_name ${ARGV1})