Use Eigen3::Eigen target

Since version 3.3 Eigen provides Eigen3Config.cmake with the imported
target Eigen3::Eigen. [1]
Use this imported target as descibed in Eigen-Wiki [2]

In the CeresConfig file improve relocatability by removing absolute
paths to the compiled dependencies. Instead find the used Eigen3::Eigen.
Furthermore use the find_dependency() [4] CMake function instead of the
find_package() call in CeresConfig.

This commit relies on all targets to be explicitly linked private or
public as done in the the change [3]

[1] https://bitbucket.org/eigen/eigen/pull-requests/257/cmake-imported-target-take-2/diff
[2] https://eigen.tuxfamily.org/dox/TopicCMakeGuide.html
[3] https://ceres-solver-review.googlesource.com/c/ceres-solver/+/16220
[4] https://cmake.org/cmake/help/latest/module/CMakeFindDependencyMacro.html

Change-Id: I44f44a089083f7169bcf430b59775242e4eb72d1
This commit is contained in:
NeroBurner
2019-12-03 10:05:15 +01:00
parent 47e784bb41
commit 33dd469a53
4 changed files with 40 additions and 322 deletions
+11 -17
View File
@@ -60,6 +60,8 @@
# CMake target already includes the definition of its public
# include directories.
include(CMakeFindDependencyMacro)
# Called if we failed to find Ceres or any of its required dependencies,
# unsets all public (designed to be used externally) variables and reports
# error message at priority depending upon [REQUIRED/QUIET/<NONE>] argument.
@@ -166,38 +168,30 @@ find_dependency(Threads)
# Eigen.
# Flag set during configuration and build of Ceres.
set(CERES_EIGEN_VERSION @EIGEN_VERSION@)
set(EIGEN_WAS_BUILT_WITH_CMAKE @FOUND_INSTALLED_EIGEN_CMAKE_CONFIGURATION@)
# Append the locations of Eigen when Ceres was built to the search path hints.
if (EIGEN_WAS_BUILT_WITH_CMAKE)
set(Eigen3_DIR "@Eigen3_DIR@")
set(EIGEN_PREFER_EXPORTED_EIGEN_CMAKE_CONFIGURATION TRUE)
else()
list(APPEND EIGEN_INCLUDE_DIR_HINTS "@EIGEN_INCLUDE_DIR@")
endif()
set(CERES_EIGEN_VERSION @EIGEN3_VERSION_STRING@)
# 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(Eigen ${CERES_EIGEN_VERSION} QUIET)
if (EIGEN_FOUND)
if (NOT EIGEN_VERSION VERSION_EQUAL CERES_EIGEN_VERSION)
find_dependency(Eigen3 ${CERES_EIGEN_VERSION} CONFIG 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
# specified version. However, only version = is supported. Improve
# usability by explaining why we don't accept non-exact version matching.
ceres_report_not_found("Found Eigen dependency, but the version of Eigen "
"found (${EIGEN_VERSION}) does not exactly match the version of Eigen "
"found (${EIGEN3_VERSION_STRING}) does not exactly match the version of Eigen "
"Ceres was compiled with (${CERES_EIGEN_VERSION}). This can cause subtle "
"bugs by triggering violations of the One Definition Rule. See the "
"Wikipedia article http://en.wikipedia.org/wiki/One_Definition_Rule "
"for more details")
endif ()
message(STATUS "Found required Ceres dependency: "
"Eigen version ${CERES_EIGEN_VERSION} in ${EIGEN_INCLUDE_DIRS}")
else (EIGEN_FOUND)
"Eigen version ${CERES_EIGEN_VERSION} in ${EIGEN3_INCLUDE_DIRS}")
else (EIGEN3_FOUND)
ceres_report_not_found("Missing required Ceres "
"dependency: Eigen version ${CERES_EIGEN_VERSION}, please set "
"EIGEN_INCLUDE_DIR.")
endif (EIGEN_FOUND)
"Eigen3_DIR.")
endif (EIGEN3_FOUND)
# Glog.
# Flag set during configuration and build of Ceres.