Add option to CMake to disable all tests
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6960473..35faaf8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,8 +1,6 @@
 cmake_minimum_required(VERSION 2.6)
 project(POLARSSL C)
 
-enable_testing()
-
 string(REGEX MATCH "clang" CMAKE_COMPILER_IS_CLANG "${CMAKE_C_COMPILER}")
 
 if(CMAKE_COMPILER_IS_GNUCC)
@@ -41,6 +39,11 @@
 
 option(ENABLE_ZLIB_SUPPORT "Build PolarSSL with zlib library." OFF)
 option(ENABLE_PROGRAMS "Build PolarSSL programs." ON)
+option(ENABLE_TESTING "Build PolarSSL tests." ON)
+
+if(ENABLE_TESTING)
+  enable_testing()
+endif()
 
 if(LIB_INSTALL_DIR)
 else()
@@ -60,12 +63,14 @@
 add_subdirectory(library)
 add_subdirectory(include)
 
-if(CMAKE_COMPILER_IS_GNUCC)
-  add_subdirectory(tests)
-endif(CMAKE_COMPILER_IS_GNUCC)
-if(CMAKE_COMPILER_IS_CLANG)
-  add_subdirectory(tests)
-endif(CMAKE_COMPILER_IS_CLANG)
+if(ENABLE_TESTING)
+  if(CMAKE_COMPILER_IS_GNUCC)
+    add_subdirectory(tests)
+  endif(CMAKE_COMPILER_IS_GNUCC)
+  if(CMAKE_COMPILER_IS_CLANG)
+    add_subdirectory(tests)
+  endif(CMAKE_COMPILER_IS_CLANG)
+endif()
 
 if(ENABLE_PROGRAMS)
   add_subdirectory(programs)
@@ -75,21 +80,22 @@
                   COMMAND doxygen doxygen/polarssl.doxyfile
                   WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
 
-ADD_CUSTOM_TARGET(test-ref-config
+if(ENABLE_TESTING)
+  ADD_CUSTOM_TARGET(test-ref-config
     COMMAND tests/scripts/test-ref-configs.pl
     )
 
-# add programs/test/selftest even though the selftest functions are
-# called from the testsuites since it runs them in verbose mode,
-# avoiding spurious "uncovered" printf lines
-ADD_CUSTOM_TARGET(covtest
+  # add programs/test/selftest even though the selftest functions are
+  # called from the testsuites since it runs them in verbose mode,
+  # avoiding spurious "uncovered" printf lines
+  ADD_CUSTOM_TARGET(covtest
     COMMAND make test
     COMMAND programs/test/selftest
     COMMAND cd tests && ./compat.sh
     COMMAND cd tests && ./ssl-opt.sh
     )
 
-ADD_CUSTOM_TARGET(lcov
+  ADD_CUSTOM_TARGET(lcov
     COMMAND rm -rf Coverage
     COMMAND lcov --capture --directory library/CMakeFiles/polarssl.dir -o polarssl.info
     COMMAND gendesc tests/Descriptions.txt -o descriptions
@@ -97,8 +103,9 @@
     COMMAND rm -f polarssl.info descriptions
     )
 
-ADD_CUSTOM_TARGET(memcheck
+  ADD_CUSTOM_TARGET(memcheck
     COMMAND ctest -O memcheck.log -D ExperimentalMemCheck
     COMMAND tail -n1 memcheck.log | grep 'Memory checking results:' > /dev/null
     COMMAND rm -f memcheck.log
     )
+endif()