Search code examples
c++cmakeeigeneigen3

installed eigen cmake target points to source include and not installed include


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?


Solution

  • 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.