Cleanup import of TBB in CMake.

- Update FindSuiteSparse to use FindTBB.cmake to find TBB.
- Fix logic handling of TBB=ON if TBB is not found to continue with
  build after disabling TBB rather than throwing a fatal error.
- Use TBB_LIBRARIES instead of TBB_tbb_LIBRARY as a Ceres dependency,
  the former also includes the TBB malloc library.
- Add warning message about GPL licensing if TBB version < 2017.
- Add ‘TBB’ & ‘Mulithreading’ component options to find_package(Ceres),
  where ‘Mulithreading’ is equivalent to ‘TBB’ || ‘OpenMP’.

Change-Id: Ifc7f1d01b050ba6e2097ad1913b178805df4769a
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fa070ba..f6062d6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -416,19 +416,16 @@
   message("-- Building without OpenMP, disabling.")
 endif (OPENMP)
 
-# Initialise CMAKE_REQUIRED_FLAGS used by CheckCXXSourceCompiles with the
-# contents of CMAKE_CXX_FLAGS such that if the user has passed extra flags
-# they are used when discovering shared_ptr/unordered_map.
-set(CMAKE_REQUIRED_FLAGS ${CMAKE_CXX_FLAGS})
-
 if (TBB)
-  find_package(TBB REQUIRED)
+  find_package(TBB QUIET)
   if (TBB_FOUND)
-    message("-- Building with TBB.")
+    message("-- Building with TBB (version: ${TBB_VERSION}).")
     list(APPEND CERES_COMPILE_OPTIONS CERES_USE_TBB)
     include_directories(${TBB_INCLUDE_DIRS})
-    # TBB requires C++11
-    update_cache_variable(CXX11 ON)
+    if (NOT CXX11)
+      message("-- Enabling CXX11 (C++11) option required by TBB=ON.")
+      update_cache_variable(CXX11 ON)
+    endif()
   else (TBB_FOUND)
     message("-- Failed to find TBB, disabling.")
     update_cache_variable(TBB OFF)
@@ -436,7 +433,7 @@
 endif (TBB)
 
 if (NOT OPENMP AND NOT TBB)
-  message("-- Nor OpenMP neither TBB is used, disabling multithreading.")
+  message("-- Neither OpenMP or TBB is enabled, disabling multithreading.")
   list(APPEND CERES_COMPILE_OPTIONS CERES_NO_THREADS)
 else (NOT OPENMP AND NOT TBB)
   if (UNIX)
@@ -448,6 +445,10 @@
   endif (UNIX)
 endif (NOT OPENMP AND NOT TBB)
 
+# Initialise CMAKE_REQUIRED_FLAGS used by CheckCXXSourceCompiles with the
+# contents of CMAKE_CXX_FLAGS such that if the user has passed extra flags
+# they are used when discovering shared_ptr/unordered_map.
+set(CMAKE_REQUIRED_FLAGS ${CMAKE_CXX_FLAGS})
 include(CheckCXXCompilerFlag)
 check_cxx_compiler_flag("-std=c++11" COMPILER_HAS_CXX11_FLAG)
 if (CXX11 AND COMPILER_HAS_CXX11_FLAG)
diff --git a/cmake/CeresCompileOptionsToComponents.cmake b/cmake/CeresCompileOptionsToComponents.cmake
index 7177475..2243ab3 100644
--- a/cmake/CeresCompileOptionsToComponents.cmake
+++ b/cmake/CeresCompileOptionsToComponents.cmake
@@ -83,7 +83,9 @@
   add_to_output_if_found(CURRENT_CERES_COMPILE_OPTIONS ${CERES_COMPONENTS_VAR}
     CERES_USE_CXX11 "C++11")
   add_to_output_if_found(CURRENT_CERES_COMPILE_OPTIONS ${CERES_COMPONENTS_VAR}
-    CERES_USE_OPENMP "OpenMP")
+    CERES_USE_OPENMP "OpenMP;Multithreading")
+  add_to_output_if_found(CURRENT_CERES_COMPILE_OPTIONS ${CERES_COMPONENTS_VAR}
+    CERES_USE_TBB "TBB;Multithreading")
   # Remove duplicates of SparseLinearAlgebraLibrary if multiple sparse backends
   # are present.
   list(REMOVE_DUPLICATES ${CERES_COMPONENTS_VAR})
diff --git a/cmake/FindSuiteSparse.cmake b/cmake/FindSuiteSparse.cmake
index 50d4ae1..e887e3b 100644
--- a/cmake/FindSuiteSparse.cmake
+++ b/cmake/FindSuiteSparse.cmake
@@ -291,21 +291,14 @@
   # SuiteSparseQR may be compiled with Intel Threading Building Blocks,
   # we assume that if TBB is installed, SuiteSparseQR was compiled with
   # support for it, this will do no harm if it wasn't.
-  suitesparse_find_component(TBB LIBRARIES tbb)
+  find_package(TBB QUIET)
   if (TBB_FOUND)
-    message(STATUS "Found Intel Thread Building Blocks (TBB) library: "
-      "${TBB_LIBRARY}, assuming SuiteSparseQR was compiled with TBB.")
-    suitesparse_find_component(TBB_MALLOC LIBRARIES tbbmalloc)
-    if (TBB_MALLOC_FOUND)
-      message(STATUS "Found Intel Thread Building Blocks (TBB) Malloc library: "
-        "${TBB_MALLOC_LIBRARY}")
-      # Add the TBB libraries to the SuiteSparseQR libraries (the only
-      # libraries to optionally depend on TBB).
-      list(APPEND SUITESPARSEQR_LIBRARY ${TBB_LIBRARY} ${TBB_MALLOC_LIBRARY})
-    else()
-      message(STATUS "Did not find Intel Thread Building Blocks (TBB) Malloc "
-        "Library, discarding TBB as a dependency.")
-    endif()
+    message(STATUS "Found Intel Thread Building Blocks (TBB) library "
+      "(${TBB_VERSION}) assuming SuiteSparseQR was compiled "
+      "with TBB.")
+    # Add the TBB libraries to the SuiteSparseQR libraries (the only
+    # libraries to optionally depend on TBB).
+    list(APPEND SUITESPARSEQR_LIBRARY ${TBB_LIBRARIES})
   else()
     message(STATUS "Did not find Intel TBB library, assuming SuiteSparseQR was "
       "not compiled with TBB.")
diff --git a/docs/source/installation.rst b/docs/source/installation.rst
index c95049e..27979ce 100644
--- a/docs/source/installation.rst
+++ b/docs/source/installation.rst
@@ -865,6 +865,11 @@
 
 #. ``OpenMP``: Ceres built with OpenMP (``OPENMP=ON``).
 
+#. ``TBB``: Ceres built with Intel Thread Building Blocks (TBB) (``TBB=ON``).
+
+#. ``Multithreading``: Ceres built with *a* multithreading library.
+   This is equivalent to ``OpenMP`` **OR** ``TBB``.
+
 #. ``C++11``: Ceres built with C++11 (``CXX11=ON``).
 
 To specify one/multiple Ceres components use the ``COMPONENTS`` argument to
diff --git a/internal/ceres/CMakeLists.txt b/internal/ceres/CMakeLists.txt
index 829a383..c68edab 100644
--- a/internal/ceres/CMakeLists.txt
+++ b/internal/ceres/CMakeLists.txt
@@ -184,7 +184,7 @@
 endif (OPENMP_FOUND)
 
 if (TBB_FOUND)
-  list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${TBB_tbb_LIBRARY})
+  list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${TBB_LIBRARIES})
   if (NOT MSVC)
     list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${CMAKE_THREAD_LIBS_INIT})
   endif (NOT MSVC)