mirror of
https://github.com/ceres-solver/ceres-solver.git
synced 2026-08-29 16:40:38 +08:00
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
This commit is contained in:
+11
-10
@@ -416,19 +416,16 @@ else (OPENMP)
|
||||
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 @@ if (TBB)
|
||||
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 @@ else (NOT OPENMP AND NOT TBB)
|
||||
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)
|
||||
|
||||
@@ -83,7 +83,9 @@ function(ceres_compile_options_to_components CURRENT_CERES_COMPILE_OPTIONS CERES
|
||||
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})
|
||||
|
||||
@@ -291,21 +291,14 @@ if (SUITESPARSEQR_FOUND)
|
||||
# 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.")
|
||||
|
||||
@@ -865,6 +865,11 @@ The Ceres components which can be specified are:
|
||||
|
||||
#. ``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
|
||||
|
||||
@@ -184,7 +184,7 @@ if (OPENMP_FOUND)
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user