title: Detecting Unnecessary Libraries in target_link_libraries
body: <p>I'm working on a C++ project that uses cmake and we're having issues with inflated build times for some targets. After some digging, I found unnecessary libraries are listed in some of the <code>target_link_libraries</code>.</p>
  
  <p>In the following example, main depends on A, which depends on B, so when main is compiled, A and B also get built.</p>
  
  <pre><code>add_library(A STATIC a.c)
  add_library(B STATIC b.c)
  target_link_libraries(A B)
  add_executable(main main.c)
  target_link_libraries(main A)
  </code></pre>
  
  <p>However, A doesn't include any files from B, so it doesn't need to be listed in the <code>target_link_libraries</code>. Is there a way to detect that B is unnecessary?</p>