Update LAPACK option to refer to direct use by Ceres only.

- Previously the LAPACK option meant would Ceres link against LAPACK,
  whether directly or indirectly via SuiteSparse (if SUITESPARSE=ON),
  as such if LAPACK=OFF, the use of SuiteSparse was disabled, even if
  it was found.
- To support the use-case of using a limited LAPACK implementation that
  satisfies SuiteSparse’s requirements, but potentially not Ceres’ we
  now adopt the more conventional terminology whereby the LAPACK option
  refers only to whether Ceres itself will directly call LAPACK
  routines, not whether it or any of its dependencies will.
- This means that the LAPACK and SUITESPARSE options are now
  independent.
- Also unnecessary calls to find_package(BLAS), as find_package(LAPACK)
  already searches for BLAS, and appends the resulting libraries to
  LAPACK_LIBRARIES if they are found.

Change-Id: I9cf5fa5e4cb621812f6f0526db8d16a7a39c9c8f
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0174824..087f227 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -94,7 +94,7 @@
 option(GFLAGS "Enable Google Flags." ON)
 option(SUITESPARSE "Enable SuiteSparse." ON)
 option(CXSPARSE "Enable CXSparse." ON)
-option(LAPACK "Enable use of LAPACK." ON)
+option(LAPACK "Enable use of LAPACK directly within Ceres." ON)
 # Template specializations for the Schur complement based solvers. If
 # compile time, binary size or compiler performance is an issue, you
 # may consider disabling this.
@@ -241,40 +241,20 @@
     message("")
 endif (EIGEN_FOUND)
 
-# LAPACK (& BLAS).
 if (LAPACK)
   find_package(LAPACK QUIET)
   if (LAPACK_FOUND)
     message("-- Found LAPACK library: ${LAPACK_LIBRARIES}")
   else (LAPACK_FOUND)
     message("-- Did not find LAPACK library, disabling LAPACK support.")
-  endif (LAPACK_FOUND)
-
-  find_package(BLAS QUIET)
-  if (BLAS_FOUND)
-    message("-- Found BLAS library: ${BLAS_LIBRARIES}")
-  else (BLAS_FOUND)
-    message("-- Did not find BLAS library, disabling LAPACK support.")
-  endif (BLAS_FOUND)
-
-  if (NOT (LAPACK_FOUND AND BLAS_FOUND))
     update_cache_variable(LAPACK OFF)
     list(APPEND CERES_COMPILE_OPTIONS CERES_NO_LAPACK)
-  endif (NOT (LAPACK_FOUND AND BLAS_FOUND))
+  endif (LAPACK_FOUND)
 else (LAPACK)
   message("-- Building without LAPACK.")
   list(APPEND CERES_COMPILE_OPTIONS CERES_NO_LAPACK)
 endif (LAPACK)
 
-# SuiteSparse.
-if (SUITESPARSE AND NOT LAPACK)
-  # If user has disabled LAPACK, but left SUITESPARSE ON, turn it OFF,
-  # LAPACK controls whether Ceres will be linked, directly or indirectly
-  # via SuiteSparse to LAPACK.
-  message("-- Disabling SuiteSparse as use of LAPACK has been disabled, "
-    "turn ON LAPACK to enable (optional) building with SuiteSparse.")
-  update_cache_variable(SUITESPARSE OFF)
-endif (SUITESPARSE AND NOT LAPACK)
 if (SUITESPARSE)
   # By default, if SuiteSparse and all dependencies are found, Ceres is
   # built with SuiteSparse support.
diff --git a/docs/source/installation.rst b/docs/source/installation.rst
index 53c557c..1479aca 100644
--- a/docs/source/installation.rst
+++ b/docs/source/installation.rst
@@ -525,15 +525,18 @@
 Options controlling Ceres configuration
 ---------------------------------------
 
-#. ``LAPACK [Default: ON]``: By default Ceres will use ``LAPACK`` (&
-   ``BLAS``) if they are found.  Turn this ``OFF`` to build Ceres
-   without ``LAPACK``. Turning this ``OFF`` also disables
-   ``SUITESPARSE`` as it depends on ``LAPACK``.
+#. ``LAPACK [Default: ON]``: If this option is enabled, and the ``BLAS`` and
+   ``LAPACK`` libraries are found, Ceres will enable **direct** use of
+   ``LAPACK`` routines (i.e. Ceres itself will call them).  If this option is
+   disabled, then Ceres will not require ``LAPACK`` or ``BLAS``.  It is
+   however still possible that Ceres may call ``LAPACK`` routines indirectly
+   via SuiteSparse if ``LAPACK=OFF`` and ``SUITESPARSE=ON``.  Finally
+   note that if ``LAPACK=ON`` and ``SUITESPARSE=ON``, the ``LAPACK`` and
+   ``BLAS`` libraries used by SuiteSparse and Ceres should be the same.
 
 #. ``SUITESPARSE [Default: ON]``: By default, Ceres will link to
    ``SuiteSparse`` if it and all of its dependencies are present. Turn
-   this ``OFF`` to build Ceres without ``SuiteSparse``. Note that
-   ``LAPACK`` must be ``ON`` in order to build with ``SuiteSparse``.
+   this ``OFF`` to build Ceres without ``SuiteSparse``.
 
 #. ``CXSPARSE [Default: ON]``: By default, Ceres will link to
    ``CXSparse`` if all its dependencies are present. Turn this ``OFF``
@@ -710,18 +713,9 @@
 to build Ceres via ``-D<VAR>=<VALUE>``.  This should result in the
 libraries being found for any common variant of each.
 
-If you are building on an exotic system, or setting
-``CMAKE_LIBRARY_PATH`` does not work, or is not appropriate for some
-other reason, one option would be to write your own custom versions of
-``FindBLAS.cmake`` & ``FindLAPACK.cmake`` specific to your
-environment.  In this case you must set ``CMAKE_MODULE_PATH`` to the
-directory containing these custom scripts when invoking ``CMake`` to
-build Ceres and they will be used in preference to the default
-versions.  However, in order for this to work, your scripts must
-provide the full set of variables provided by the default scripts.
-Also, if you are building Ceres with ``SuiteSparse``, the versions of
-``BLAS`` & ``LAPACK`` used by ``SuiteSparse`` and Ceres should be the
-same.
+Alternatively, you may also directly specify the ``BLAS_LIBRARIES`` and
+``LAPACK_LIBRARIES`` variables via ``-D<VAR>=<VALUE>`` when invoking CMake
+to configure Ceres.
 
 .. _section-using-ceres:
 
diff --git a/internal/ceres/CMakeLists.txt b/internal/ceres/CMakeLists.txt
index 21669d0..c48472f 100644
--- a/internal/ceres/CMakeLists.txt
+++ b/internal/ceres/CMakeLists.txt
@@ -168,10 +168,9 @@
   list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${CXSPARSE_LIBRARIES})
 endif (CXSPARSE AND CXSPARSE_FOUND)
 
-if (BLAS_FOUND AND LAPACK_FOUND)
+if (LAPACK_FOUND)
   list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${LAPACK_LIBRARIES})
-  list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${BLAS_LIBRARIES})
-endif (BLAS_FOUND AND LAPACK_FOUND)
+endif ()
 
 if (OPENMP_FOUND)
   # OpenMP support in Clang requires a non-GNU OpenMP library.