Skip to content

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

@traversaro

Description

@traversaro

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions