Ignore warnings from within Eigen/SparseQR (3.2.2).

- As reported by Chris Sweeney on the mailing list, Eigen 3.2.2
  trips various warnings in Eigen/SparseQR when compiling with GCC.
- Following Petter Strandmark's suggestion, Eigen headers are now
  treated as system headers, which implicitly suppresses all warnings.

Change-Id: I104e8cb3f00935cefb894089bea827771e0e9fd0
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8433688..aaf89d1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -528,8 +528,18 @@
   include
   internal
   internal/ceres
-  ${GLOG_INCLUDE_DIRS}
-  ${EIGEN_INCLUDE_DIRS})
+  ${GLOG_INCLUDE_DIRS})
+# Eigen SparseQR generates various compiler warnings related to unused and
+# uninitialised local variables, which prevents Ceres compilation as we use
+# -Werror.  To avoid having to individually suppress these warnings around
+# the #include statments for Eigen headers across all GCC/Clang versions, we
+# tell CMake to treat Eigen headers as system headers.  This results in all
+# compiler warnings from them being suppressed.
+#
+# Note that this is *not* propagated to clients, ie CERES_INCLUDE_DIRS
+# used by clients after find_package(Ceres) does not identify Eigen as
+# as system headers.
+INCLUDE_DIRECTORIES(SYSTEM ${EIGEN_INCLUDE_DIRS})
 
 IF (SUITESPARSE)
   INCLUDE_DIRECTORIES(${SUITESPARSE_INCLUDE_DIRS})
diff --git a/internal/ceres/covariance_impl.cc b/internal/ceres/covariance_impl.cc
index cfbfb44..cbbf139 100644
--- a/internal/ceres/covariance_impl.cc
+++ b/internal/ceres/covariance_impl.cc
@@ -38,26 +38,11 @@
 #include <cstdlib>
 #include <utility>
 #include <vector>
+
 #include "Eigen/SparseCore"
-
-// Suppress unused local variable warning from Eigen Ordering.h #included by
-// SparseQR in Eigen 3.2.0. This was fixed in Eigen 3.2.1, but 3.2.0 is still
-// widely used (Ubuntu 14.04), and Ceres won't compile otherwise due to -Werror.
-#if defined(_MSC_VER)
-#pragma warning( push )
-#pragma warning( disable : 4189 )
-#else
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
-#endif
 #include "Eigen/SparseQR"
-#if defined(_MSC_VER)
-#pragma warning( pop )
-#else
-#pragma GCC diagnostic pop
-#endif
-
 #include "Eigen/SVD"
+
 #include "ceres/compressed_col_sparse_matrix_utils.h"
 #include "ceres/compressed_row_sparse_matrix.h"
 #include "ceres/covariance.h"