0

I installed eigen3 master branch from github and installed via:

cmake ../eigen -DCMAKE_INSTALL_PREFIX=../install
make install

which outputs

-- Installing: /home/jeff/workspace/eigen/install/share/eigen3/cmake/Eigen3Targets.cmake
-- Installing: /home/jeff/workspace/eigen/install/share/eigen3/cmake/UseEigen3.cmake
-- Installing: /home/jeff/workspace/eigen/install/share/eigen3/cmake/Eigen3Config.cmake
-- Installing: /home/jeff/workspace/eigen/install/share/eigen3/cmake/Eigen3ConfigVersion.cmake
-- Installing: /home/jeff/workspace/eigen/install/include/eigen3/Eigen/Cholesky
...

I then consumed the installed Eigen3 cmake target in another project via:

find_package(Eigen3 CONFIG REQUIRED
    PATHS "/home/jeff/workspace/eigen/install/share/eigen3/cmake")

add_executable(foo foo.cpp)
target_link_libraries(foo Eigen3::Eigen)

but this gives foo the eigen source headers (/home/jeff/workspace/eigen/eigen), instead of the installed ones (/home/jeff/workspace/eigen/install/include/eigen3).

Is this a bug in Eigen or am I missing something?

Jeff
  • 718
  • 8
  • 20
  • Eigen is a headers-only package. You can give the correct address of the header files using the approach discussed in [this](https://stackoverflow.com/questions/12249140/find-package-eigen3-for-cmake) question. –  Mar 31 '18 at 22:37
  • @AmitSingh thanks for the comment. I am trying to take a target based approach to my cmake code (see for example [this post](https://pabloariasal.github.io/2018/02/19/its-time-to-do-cmake-right/)) and trying to avoid code like in the question you linked. Regardless, something is wrong somewhere with my installed cmake targets. – Jeff Mar 31 '18 at 22:54
  • Does it use the correct headers if you use just "/home/jeff/workspace/eigen/install" for the `PATHS` argument? – Miles Budnek Mar 31 '18 at 23:12
  • @MilesBudnek actually I am really confused now, it seems to pick up the source directory headers even if I give find_package no PATHS argument at all. I have no idea how it is finding the eigen config in that case =/ – Jeff Apr 01 '18 at 09:29
  • I have no idea why, but find_package was finding the config in my build directory which pointed to the eigen source headers. deleting the build directory after installation fixed the problem. – Jeff Apr 01 '18 at 09:37

1 Answers1

0

This was due to building eigen adding this file (see here):

jeff@jeff-laptop:~$ cat ~/.cmake/packages/Eigen3/2668cceac18b59405e572a6fd3cffc86 
/home/jeff/workspace/eigen/build

so find_package would find the eigen build config (without specifying any extra search paths) which pointed to the eigen source headers instead of the installed ones.

When building my project I can add -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON so that find_package does not look into ~/.cmake/packages.

Not sure why eigen creates this file or what use it has, but at least it all works as expected now.

Jeff
  • 718
  • 8
  • 20