Fix install path for CeresConfig.cmake to be architecture-aware.

- Previously we were auto-detecting a "64" suffix for the install path
  for the Ceres library on non-Debian/Arch Linux distributions, but
  we were installing CeresConfig.cmake to an architecture independent
  location.
- We now install CeresConfig.cmake to lib${LIB_SUFFIX}/cmake/Ceres.
- Also make LIB_SUFFIX visible to the user in the CMake GUI s/t they can
  easily override the auto-detected value if desired.
- Reported by jpgr87@gmail.com as Issue #194.

Change-Id: If126260d7af685779487c01220ae178ac31f7aea
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 96ae6d1..1e3ae33 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -138,6 +138,30 @@
     update_cache_variable(BUILD_TESTING OFF)
   endif (BUILD_TESTING AND BUILD_SHARED_LIBS)
 endif (MSVC)
+# Allow user to specify a suffix for the library install directory, the only
+# really sensible option (other than "") being "64", such that:
+# ${CMAKE_INSTALL_PREFIX}/lib -> ${CMAKE_INSTALL_PREFIX}/lib64.
+#
+# Heuristic for determining LIB_SUFFIX. FHS recommends that 64-bit systems
+# install native libraries to lib64 rather than lib. Most distros seem to
+# follow this convention with a couple notable exceptions (Debian-based and
+# Arch-based distros) which we try to detect here.
+if (CMAKE_SYSTEM_NAME MATCHES "Linux" AND
+    NOT DEFINED LIB_SUFFIX AND
+    NOT CMAKE_CROSSCOMPILING AND
+    CMAKE_SIZEOF_VOID_P EQUAL "8" AND
+    NOT EXISTS "/etc/debian_version" AND
+    NOT EXISTS "/etc/arch-release")
+  message("-- Detected non-Debian/Arch-based 64-bit Linux distribution. "
+    "Defaulting to library install directory: lib${LIB_SUFFIX}. You can "
+    "override this by specifying LIB_SUFFIX.")
+  set(LIB_SUFFIX "64")
+endif ()
+# Only create the cache variable (for the CMake GUI) after attempting to detect
+# the suffix *if not specified by the user* (NOT DEFINED LIB_SUFFIX in if())
+# s/t the user could override our autodetected suffix with "" if desired.
+set(LIB_SUFFIX "${LIB_SUFFIX}" CACHE STRING
+  "Suffix of library install directory (to support lib/lib64)." FORCE)
 
 # IOS is defined iff using the iOS.cmake CMake toolchain to build a static
 # library for iOS.
@@ -762,7 +786,7 @@
 if (WIN32)
   set(RELATIVE_CMAKECONFIG_INSTALL_DIR CMake)
 else ()
-  set(RELATIVE_CMAKECONFIG_INSTALL_DIR lib/cmake/Ceres)
+  set(RELATIVE_CMAKECONFIG_INSTALL_DIR lib${LIB_SUFFIX}/cmake/Ceres)
 endif ()
 
 # This "exports" for installation all targets which have been put into the
diff --git a/docs/source/building.rst b/docs/source/building.rst
index af5c30a..03f6dfd 100644
--- a/docs/source/building.rst
+++ b/docs/source/building.rst
@@ -614,6 +614,20 @@
    Ceres will use the Visual Studio default, *shared* C-Run Time (CRT) library.
    Turn this ``ON`` to use the *static* C-Run Time library instead.
 
+#. ``LIB_SUFFIX [Default: "64" on non-Debian/Arch based 64-bit Linux, otherwise: ""]``:
+   The suffix to append to the library install directory, built from:
+   ``${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}``.
+
+   The filesystem hierarchy standard recommends that 64-bit systems install
+   native libraries to lib64 rather than lib.  Most Linux distributions follow
+   this convention, but Debian and Arch based distros do not.  Note that the
+   only generally sensible values for ``LIB_SUFFIX`` are "" and "64".
+
+   Although by default Ceres will auto-detect non-Debian/Arch based 64-bit
+   Linux distributions and default ``LIB_SUFFIX`` to "64", this can always be
+   overridden by manually specifying LIB_SUFFIX using: ``-DLIB_SUFFIX=<VALUE>``
+   when invoking CMake.
+
 
 Options controlling Ceres dependency locations
 ----------------------------------------------
diff --git a/internal/ceres/CMakeLists.txt b/internal/ceres/CMakeLists.txt
index a9fee1a..5d24a8a 100644
--- a/internal/ceres/CMakeLists.txt
+++ b/internal/ceres/CMakeLists.txt
@@ -116,19 +116,6 @@
     wall_time.cc
 )
 
-# Heuristic for determining LIB_SUFFIX. FHS recommends that 64-bit systems
-# install native libraries to lib64 rather than lib. Most distros seem to
-# follow this convention with a couple notable exceptions (Debian-based and
-# Arch-based distros) which we try to detect here.
-if (CMAKE_SYSTEM_NAME MATCHES "Linux" AND
-    NOT DEFINED LIB_SUFFIX AND
-    NOT CMAKE_CROSSCOMPILING AND
-    CMAKE_SIZEOF_VOID_P EQUAL "8" AND
-    NOT EXISTS "/etc/debian_version" AND
-    NOT EXISTS "/etc/arch-release")
-  set(LIB_SUFFIX "64")
-endif ()
-
 # Also depend on the header files so that they appear in IDEs.
 file(GLOB CERES_INTERNAL_HDRS *.h)