Closed peci1 closed 4 years ago
AFAIK, the best practise these days is to instruct CMake to link the Eigen3::Eigen target.
target_link_libraries (${PROJECT_NAME}_core Eigen3::Eigen)
Do you have a reference for using the Eigen3::Eigen
target? It seems weird to me that you'd add include directories by putting something into target_link_libraries
...
Ah, found it... https://eigen.tuxfamily.org/dox/TopicCMakeGuide.html
But that'd mean we have to give up on catkin passing the dependency to dependent packages? Because catkin_package(DEPENDS)
will only pass the the CMake variables, and not the target...
As I understand it, catkin_package(DEPENDS) is for dependencies in the ROS ecosystem. That's with a package.xml and a typical CMakeLists.txt. System dependencies - that is Eigen, Qt, libraries, etc., - can be resolved through the regular find_package(...)
and target_link_libraries(...)
commands. Do you agree with this?
You're probably talking about catkin_package(CATKIN_DEPENDS)
. See https://answers.ros.org/question/58498/what-is-the-purpose-of-catkin_depends/ for a good explanation.
Thanks! Eigen is a transitive dependency of packages that depend on this package, so it should indeed be passed with the DEPENDS. While the target based way of including libraries is a the modern way, passing the variables should work just as fine.
So the dependency is commented out now because the library does not actually do anything with it. I think it adds to this example to do use Eigen.
Now, if Eigen is only used in source files it will not be a transitive dependency so we should not add it to the DEPENDS
, do you agree?
Yes, if it's only build dependency and isn't anywhere in .h files, then it shouldn't be in DEPDENDS. But maybe a comment could be there explaning when to add it there.
Specifying
${EIGEN3_INCLUDE_DIR}
as an explicit catkin_package INCLUDE_DIR is not as good idea as putting it as a DEPENDS package. That will do the same thing and, moreover, is future-proof. Further, it also adds required compiler definitions, which you've forgot to do here (and I think lots of people would). This can have disastrous consequences if you change some flags that alter memory layout of Eigen objects.Also, adding the include directory via a UseEigen3 file is more future-proof.