Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
    • Switch to GitLab Next
  • Sign in / Register
  • eigen eigen
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 665
    • Issues 665
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Custom issue tracker
    • Custom issue tracker
  • Merge requests 17
    • Merge requests 17
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • libeigenlibeigen
  • eigeneigen
  • Issues
  • #1319
Closed
Open
Issue created Dec 04, 2019 by Eigen Bugzilla@eigenbzReporter

With CMake, import CMake as a target instead of setting the include directories

Submitted by Alain Vaucher

Assigned to Nobody

Link to original bugzilla bug (#1319)

Description

Created attachment 742
Updated FindEigen3.cmake for setting Eigen as a target

The status quo for employing Eigen in a CMake project is to call
find_package(Eigen3)
followed, for instance, by
include_directories(${EIGEN3_INCLUDE_DIR})
or something similar.

However, for some time, CMake has allowed for a more handy way to import dependencies, which, in the case of Eigen, would look something like
find_package(Eigen3)
target_link_libraries(myLibrary Eigen)

So far, there is no big difference, but the advantages appear when "myLibrary" itself is used in other CMake projects, since CMake keeps track of the dependencies and is quite intelligent when installing targets. Then, one could for instance call
find_package(Eigen3)
target_link_libraries(myLibrary PUBLIC Eigen)
which would automatically include the Eigen header directories to all CMake projects that employ "myLibrary".

Note that as long as "myLibrary" is used on the computer where it was compiled, the status quo allows for
find_package(Eigen3)
target_include_directories(myLibrary PUBLIC ${EIGEN3_INCLUDE_DIR})
which, however, is problematic when distributing "myLibrary" to other systems, or when different Eigen versions exist or when it is updated, since the path in ${EIGEN3_INCLUDE_DIR} is then hard-coded in the exported "myLibrary", unless Eigen is distributed together with it.
On the other hand, allowing for Eigen to be a CMake target would not hard-code the location of the header files, but would just require clients to also have Eigen on their systems.

There are other advantages to this new syntax and it is being applied by many projects such as Qt or Boost.
For Eigen, allowing for this would be pretty easy. One still needs to consider whether Eigen is imported by the FindEigen3.cmake file or if it is installed first with CMake and imported with the file Eigen3Config.cmake, but in both cases it would not require too much work.

I tested a modified version of FindEigen3.cmake to implement this and I added it here as an attachment.

I am happy to discuss the topic in more detail and/or to contribute to its implementation (also with the second import possibility with Eigen3Config.cmake).

Best,
Alain

Attachment 742, "Updated FindEigen3.cmake for setting Eigen as a target":
FindEigen3.cmake

Blocking

#558 (closed)

Edited Dec 05, 2019 by Eigen Bugzilla
Assignee
Assign to
Time tracking