robotology / ycm-cmake-modules

YCM (YCM CMake modules) is a collection of various useful CMake modules.
http://robotology.github.io/ycm-cmake-modules
Other
52 stars 23 forks source link

Support installing imported targets #420

Open aminya opened 2 years ago

aminya commented 2 years ago

Hi, I am the developer of project options that uses install_basic_package_files from ycm internally for its package_project functionality.

I have noticed that ycm fails to install IMPORTED targets. I have written a patch that detects such imported targets and installs them as a FILE instead of a TARGET.

However, this still fails when calling the export function. This is because when the install(TARGETS ... EXPORT ...) is not called, no export exists.

I am wondering if we can handle this corner case.

See this for more information

CMake Error at build/_deps/_ycm-src/modules/InstallBasicPackageFiles.cmake:660 (export):
  export Export set "test" not found.
Call Stack (most recent call first):
  build/_deps/_project_options-src/src/PackageProject.cmake:217 (install_basic_package_files)
  CMakeLists.txt:36 (package_project)
traversaro commented 2 years ago

Hello @aminya, thanks for the feedback!

I have noticed that ycm fails to install IMPORTED targets.

This is the case, and I think it is actually due to CMake not being able to install IMPORTED targets. This is kind of "by design" (I think), as tipically imported targets are defined in downstream packages by calling find_dependency . To explain with an example, let's say that you are using YCM's install_basic_package_files in a package called PackageA, that is using an imported target DepA::DepA defined by the call to find_package(DepA). The typical way to make sure that if a downstream projects calls find_package(PackageA) it also gets DepA::DepA is to insert a call to find_dependency(DepA) in the PackageAConfig.cmake file. In the context of install_basic_package_files, this is done by passing DepA in the DEPENDENCIES argument. This is done as in general the relative position of the install prefixes of DepA and PackageA may be different between the machine in which you are building PackageA and the machine in which you are consuming PackageA.

However, if you need to install IMPORTED targets probably you have a different use case, can you explain it, so it would be easier to find a solution? Thanks!

aminya commented 2 years ago

Hi, thanks for the explanation.

My use-case is wrapping a pre-built library generated by another build system so it can be used from CMake. The one way CMake allows defining such libraries is imported targets. I have given an example here in the pull request description under the "How to test" section: https://github.com/aminya/project_options/pull/167