From 3c678f06e402d17e667ed71c578b61880638546d Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Mon, 2 Sep 2013 09:47:53 +0200 Subject: [PATCH] If given build tree as Eigen3 root, find source Eigen3 is a template-library, so we must compile the source code directly together with ours instead of linking to a library. If the build script gives us the location of a "built" Eigen3, meaning a directory in which CMake has been run, locate the true source directory from the cache entries. --- cmake/Modules/FindEigen3.cmake | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/cmake/Modules/FindEigen3.cmake b/cmake/Modules/FindEigen3.cmake index 014b59076..49fc6c68d 100644 --- a/cmake/Modules/FindEigen3.cmake +++ b/cmake/Modules/FindEigen3.cmake @@ -65,9 +65,36 @@ if (NOT EIGEN3_INCLUDE_DIR) # other version to be swapped in to substitute; if not specified, then # go search usual locations if (EIGEN3_ROOT) + # if we are given the path to a "build" tree (meaning somewhere Eigen3 + # has been configured), then use the eigen3.pc file to figure out the + # name of the *real* root directory + if (EXISTS "${EIGEN3_ROOT}/CMakeCache.txt") + # get the cache entry that tells use the source tree location + set (_regex "Eigen_SOURCE_DIR:STATIC=\(.*\)") + file (STRINGS + "${EIGEN3_ROOT}/CMakeCache.txt" + EIGEN3_SOURCE_TREE + REGEX "${_regex}" + ) + # trim away the key definition, be left with the value + if (EIGEN3_SOURCE_TREE) + string (REGEX REPLACE + "${_regex}" + "\\1" + EIGEN3_SOURCE_TREE + "${EIGEN3_SOURCE_TREE}" + ) + # if something doesn't look as expected, abort and search in _ROOT + else () + set (EIGEN3_SOURCE_TREE "${EIGEN3_ROOT}") + endif () + else () + set (EIGEN3_SOURCE_TREE "${EIGEN3_ROOT}") + endif () + find_path (EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library - PATHS ${EIGEN3_ROOT} + PATHS ${EIGEN3_SOURCE_TREE} PATH_SUFFIXES eigen3 include/eigen3 eigen include/eigen NO_DEFAULT_PATH )