robotology/idyntree

Compilation against a static iDynTree fails as no one defines Eigen3::Eigen imported target

traversaro opened this issue · 1 comments

@Nicogene experienced the following problem when compiling against a static version of iDynTree:

Severity    Code    Description    Project    File    Line    Suppression State
Error        CMake Error at C:/Users/ngenesio/robotology/install/lib/cmake/iDynTree/iDynTreeTargets.cmake:61 (set_target_properties):
  The link interface of target "iDynTree::idyntree-core" contains:

 

    Eigen3::Eigen

 

  but the target was not found.  Possible reasons include:

 

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.        C:/Users/ngenesio/robotology/install/lib/cmake/iDynTree/iDynTreeTargets.cmake    61    
    * 

The problem is that we are linking Eigen3::Eigen as PRIVATE in several place, and when a library is compiled as static the PRIVATE target links are promoted to PUBLIC . This would make sense if Eigen3 was itself a non-header library, but given that Eigen3::Eigen is an header-only library, no Eigen3 is actually necessary. To avoid that, we should only include the headers of Eigen3::Eigen, without linking it directly, see https://discourse.cmake.org/t/add-only-library-headers-during-target-link-libraries/2973 for a similar use case.

A function that plays a similar role is onnxruntime_add_include_to_target from https://github.com/microsoft/onnxruntime/blob/d49a8de9b1db3486246e65700380e1eb8e7d581d/cmake/CMakeLists.txt#L940 .