Add one CMake option to build the examples.

Currently the examples are always built. For external projects, it is useful
not to compile the examples.

Change-Id: I41d3bde19c7e742818e60f78222d39c43992ca8b
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 117e86b..c6cce47 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -582,7 +582,6 @@
 ENDIF (MSVC)
 
 ADD_SUBDIRECTORY(internal/ceres)
-ADD_SUBDIRECTORY(examples)
 
 OPTION(BUILD_DOCUMENTATION
        "Build User's Guide (pdf)"
@@ -595,3 +594,12 @@
   # The corresponding target is UserGuide, but is included in ALL.
   ADD_SUBDIRECTORY(docs)
 ENDIF (${BUILD_DOCUMENTATION})
+
+OPTION(BUILD_EXAMPLES "Build examples" ON)
+
+IF (${BUILD_EXAMPLES})
+  MESSAGE("-- Build the examples.")
+  ADD_SUBDIRECTORY(examples)
+ELSE (${BUILD_EXAMPLES})
+  MESSAGE("-- Do not build any example.")
+ENDIF (${BUILD_EXAMPLES})