-1

I am currently developing a library, HAMMER, and using CMake as its build system. I'm in the process of integrating YARP which also uses CMake as its build system. Consequently I import YARP using the standard CMake method, ie. pointing CMake to a YARPConfig.cmake file that was generated during YARP compilation and using YARP_LIBRARIES and YARP_INCLUDE_DIRS. So far, so good.

The problem is that during the linking stage (of my library) CMake will automatically link against all the libraries that YARP depends upon. For example YARP uses gsl but my library does not (at most it calls the YARP methods that use gsl), yet gsl appears listed as one the ld dependencies of my library (using ldd).

This is not much of an issue when using libraries that are in the default library path, but if you need to link against a library that is not on the library path (and that is not part of your project), then linking will fail (as the required library won't be found).

That is exactly what is happens when trying to build an application that uses HAMMER (also with CMake), since YARP is not installed in the default location, my application tries to link against it (as per the behaviour just described) and fails because it cannot find the YARP libraries.

Does anyone know why CMake has this policy? And, more importantly, is there a way around this that doesn't imply importing YARP into the CMake scripts of the application?

Thanks!

Miguel S.
  • 1
  • 1
  • 4

1 Answers1

1

See the CMake FAQ Why are libraries linked to my shared library included when something links to it?. If you want to prevent that behavior, I think you have to change the LINK_INTERFACE_LIBRARIES property of YARP.

Benjamin
  • 144
  • 3