Created attachment 742 [details] 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
Thanks a lot for the detailed explanation. There is a pull-request implementing such a feature: https://bitbucket.org/eigen/eigen/pull-requests/255/cmake-added-eigen3-eigen-imported-target It would be very helpful if you could quickly review it to assess it properly cover your issue.
I just commented on the pull request.
Fixed: https://bitbucket.org/eigen/eigen/pull-requests/257/cmake-imported-target-take-2/diff
-- GitLab Migration Automatic Message -- This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/1319.