Skip to content

Commit

Permalink
Merge branch 'hunter-1.12.0-suitesparse' into hunter-1.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
riegl-gc committed Jul 24, 2017
2 parents 5b186cf + b9e8e39 commit 4735786
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 39 deletions.
50 changes: 25 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,17 @@ unset(CERES_COMPILE_OPTIONS)

# Eigen.
hunter_add_package(Eigen)
find_package(Eigen3 REQUIRED)
# prefer Eigen config file
find_package(Eigen3 CONFIG)
if (NOT Eigen3_FOUND)
find_package(Eigen3)
endif()
if (EIGEN3_FOUND)
if (EIGEN3_VERSION_STRING VERSION_LESS 3.1.0)
if (EIGEN3_VERSION_STRING VERSION_LESS 3.1.0)
message(FATAL_ERROR "-- Ceres requires Eigen version >= 3.1.0 in order "
"that Eigen/SparseCore be available, detected version of Eigen is: "
"${EIGEN3_VERSION_STRING}")
endif (EIGEN3_VERSION VERSION_LESS 3.1.0)
endif ()

message("-- Found Eigen version ${EIGEN_VERSION_STRING}: ${EIGEN3_INCLUDE_DIRS}")
# Ensure that only MPL2 licensed code is part of the default build.
Expand Down Expand Up @@ -242,24 +246,21 @@ endif (EIGEN3_FOUND)

# LAPACK (& BLAS).
if (LAPACK)
find_package(LAPACK QUIET)
# add SuiteSparse hunter package
hunter_add_package(LAPACK)

find_package(LAPACK CONFIG)
if (LAPACK_FOUND)
message("-- Found LAPACK library: ${LAPACK_LIBRARIES}")
get_target_property(lapack_location lapack LOCATION)
message("-- Found LAPACK library: ${lapack_location}")
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))
if (NOT (TARGET lapack AND TARGET blas))
update_cache_variable(LAPACK OFF)
list(APPEND CERES_COMPILE_OPTIONS CERES_NO_LAPACK)
endif (NOT (LAPACK_FOUND AND BLAS_FOUND))
endif ()
else (LAPACK)
message("-- Building without LAPACK.")
list(APPEND CERES_COMPILE_OPTIONS CERES_NO_LAPACK)
Expand All @@ -278,9 +279,12 @@ if (SUITESPARSE)
# By default, if SuiteSparse and all dependencies are found, Ceres is
# built with SuiteSparse support.

# add SuiteSparse hunter package
hunter_add_package(SuiteSparse)

# Check for SuiteSparse and dependencies.
find_package(SuiteSparse)
if (SUITESPARSE_FOUND)
find_package(SuiteSparse CONFIG)
if (SuiteSparse_FOUND)
# On Ubuntu the system install of SuiteSparse (v3.4.0) up to at least
# Ubuntu 13.10 cannot be used to link shared libraries.
if (BUILD_SHARED_LIBS AND
Expand All @@ -294,20 +298,20 @@ if (SUITESPARSE)
"(libsuitesparse-dev) and perform a source install of SuiteSparse "
"(we recommend that you use the latest version), "
"see http://ceres-solver.org/building.html for more information.")
endif (BUILD_SHARED_LIBS AND
SUITESPARSE_IS_BROKEN_SHARED_LINKING_UBUNTU_SYSTEM_VERSION)
endif ()

# By default, if all of SuiteSparse's dependencies are found, Ceres is
# built with SuiteSparse support.
message("-- Found SuiteSparse ${SUITESPARSE_VERSION}, "

message("-- Found SuiteSparse ${SuiteSparse_VERSION}, "
"building with SuiteSparse.")
else (SUITESPARSE_FOUND)
else ()
# Disable use of SuiteSparse if it cannot be found and continue.
message("-- Did not find all SuiteSparse dependencies, disabling "
"SuiteSparse support.")
update_cache_variable(SUITESPARSE OFF)
list(APPEND CERES_COMPILE_OPTIONS CERES_NO_SUITESPARSE)
endif (SUITESPARSE_FOUND)
endif ()
else (SUITESPARSE)
message("-- Building without SuiteSparse.")
list(APPEND CERES_COMPILE_OPTIONS CERES_NO_SUITESPARSE)
Expand Down Expand Up @@ -520,10 +524,6 @@ endif(CXX11)
# as system headers.
#include_directories(SYSTEM ${EIGEN3_INCLUDE_DIRS})

if (SUITESPARSE)
include_directories(${SUITESPARSE_INCLUDE_DIRS})
endif (SUITESPARSE)

if (CXSPARSE)
include_directories(${CXSPARSE_INCLUDE_DIRS})
endif (CXSPARSE)
Expand Down
7 changes: 6 additions & 1 deletion cmake/CeresConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ list(APPEND EIGEN3_INCLUDE_DIR_HINTS @EIGEN3_INCLUDE_DIR@)
# Search quietly to control the timing of the error message if not found. The
# search should be for an exact match, but for usability reasons do a soft
# match and reject with an explanation below.
find_package(Eigen3 ${CERES_EIGEN_VERSION} QUIET)
find_package(Eigen3 QUIET)
if (EIGEN3_FOUND)
if (NOT EIGEN3_VERSION_STRING VERSION_EQUAL CERES_EIGEN_VERSION)
# CMake's VERSION check in FIND_PACKAGE() will accept any version >= the
Expand Down Expand Up @@ -333,6 +333,11 @@ if (TARGET ${CERES_LIBRARIES} AND
endif()
endif()

set(CERES_USES_SUITESPARSE @SUITESPARSE@)
if (CERES_USES_SUITESPARSE) # SuiteSparse
find_package(SuiteSparse CONFIG REQUIRED)
endif()

# Set legacy include directories variable for backwards compatibility.
set(CERES_INCLUDES ${CERES_INCLUDE_DIRS})

Expand Down
34 changes: 21 additions & 13 deletions internal/ceres/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,22 +142,29 @@ if (NOT MINIGLOG AND GLOG_FOUND)
endif()
endif (NOT MINIGLOG AND GLOG_FOUND)

if (SUITESPARSE AND SUITESPARSE_FOUND)
if (SUITESPARSE AND SuiteSparse_FOUND)
# Define version information for use in Solver::FullReport.
add_definitions(-DCERES_SUITESPARSE_VERSION="${SUITESPARSE_VERSION}")
list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${SUITESPARSE_LIBRARIES})
endif (SUITESPARSE AND SUITESPARSE_FOUND)
add_definitions(-DCERES_SUITESPARSE_VERSION="${SuiteSparse_VERSION}")
list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES
SuiteSparse::spqr
SuiteSparse::cholmod
SuiteSparse::ccolamd
SuiteSparse::camd
SuiteSparse::colamd
SuiteSparse::amd
)
endif ()

if (CXSPARSE AND CXSPARSE_FOUND)
# Define version information for use in Solver::FullReport.
add_definitions(-DCERES_CXSPARSE_VERSION="${CXSPARSE_VERSION}")
list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${CXSPARSE_LIBRARIES})
endif (CXSPARSE AND CXSPARSE_FOUND)

if (BLAS_FOUND AND LAPACK_FOUND)
list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${LAPACK_LIBRARIES})
list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${BLAS_LIBRARIES})
endif (BLAS_FOUND AND LAPACK_FOUND)
if (TARGET blas AND TARGET lapack)
list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES lapack)
list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES blas)
endif ()

if (OPENMP_FOUND)
# OpenMP support in Clang requires a non-GNU OpenMP library.
Expand Down Expand Up @@ -245,10 +252,11 @@ endif (BUILD_SHARED_LIBS)

# link Eigen3 if target exists, otherwise use legacy variable
# Eigen3Config.cmake introduced with Eigen 3.3.1
# ceres/jet.h uses Eigen/Core, therefore Eigen needs to be public
if (TARGET Eigen3::Eigen)
target_link_libraries(ceres Eigen3::Eigen)
target_link_libraries(ceres PUBLIC Eigen3::Eigen)
else()
target_include_directories(ceres SYSTEM PRIVATE
target_include_directories(ceres SYSTEM PUBLIC
$<BUILD_INTERFACE:${EIGEN3_INCLUDE_DIRS}>)
endif()

Expand Down Expand Up @@ -380,11 +388,11 @@ if (BUILD_TESTING AND GFLAGS)

# TODO(sameeragarwal): This test should ultimately be made
# independent of SuiteSparse.
if (SUITESPARSE AND SUITESPARSE_FOUND)
if (SUITESPARSE AND SuiteSparse_FOUND)
ceres_test(compressed_col_sparse_matrix_utils)
target_link_libraries(compressed_col_sparse_matrix_utils_test
${SUITESPARSE_LIBRARIES})
endif (SUITESPARSE AND SUITESPARSE_FOUND)
${SuiteSparse_LIBRARIES})
endif ()

ceres_test(symmetric_linear_solver)
ceres_test(triplet_sparse_matrix)
Expand Down

0 comments on commit 4735786

Please sign in to comment.