title: How to manage private dependecies of library with unit tests target in modern target based cmake
body: <p>I have a library <code>A</code> with public and private dependencies. The unit tests are contained in a separate executable <code>ATests</code> which requires to link against both the private and the public dependencies of <code>A</code>.</p>
  
  <p>Currently, I explicitly link all private dependencies of <code>A</code> to the unit tests <code>ATest</code>. This results in a lot of code duplication which becomes increasingly difficult to understand/maintain.</p>
  
  <pre><code>add_library(A)
  target_link_libraries(A PUBLIC Pub1 PRIVATE Priv1 Priv2)
  
  add_executable(ATests)
  target_link_libraries(ATests PRIVATE A Priv1 Priv2)
  </code></pre>
  
  <p>I thought about creating a separate interface library <code>APrivDeps</code> for the private dependencies of <code>A</code>, however, this looks like a hack. I have serious doubts that this is portable and will mess up the static linking due to the link dependency propagation. (I would have to export the helper library <code>APrivDeps</code>.)</p>
  
  <pre><code>add_library(APrivDeps)
  target_link_libraries(APrivDeps PUBLIC Priv1 Priv2)
  
  add_library(A)
  target_link_libraries(A PUBLIC Pub1 PRIVATE ADeps)
  
  add_executable(ATests)
  target_link_libraries(ATests PRIVATE A ADeps)
  </code></pre>
  
  <p>I expect some method that keeps the configuration short and free of code duplication while still following the target based principle of modern CMake.</p>