title: CMake automatically linking external library dependencies
body: <p>I am currently developing a library, <a href="http://bitbucket.org/miguelsdc/hammer" rel="nofollow">HAMMER</a>, 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 <code>YARPConfig.cmake</code> file that was generated during YARP compilation and using <code>YARP_LIBRARIES</code> and <code>YARP_INCLUDE_DIRS</code>. So far, so good.</p>
  
  <p>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 <code>ldd</code>).</p>
  
  <p>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).</p>
  
  <p>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.</p>
  
  <p>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?</p>
  
  <p>Thanks!</p>