title: CMake unexpected transitive private dependency in shared library
body: <p>I have been trying to figure this out for a few days now  based on the various existing SO questions &amp; cmake mailing list archives. However, I can't quite put my finger on it.</p>
  
  <p>I want to build a library named <code>libA</code> which will be a shared library that gets consumed by another executable. <code>libA</code> has many internal dependencies (<code>libB</code>, <code>libC</code>, <code>libD</code>, ...) which are built/present either as static libraries or cmake's object libraries. <code>libA</code> is supposed to contain all the code in order to be a self-consistent shared library that an application can link against without the need to propagate the internal dependencies.</p>
  
  <p><code>libA</code> is being built like this:</p>
  
  <pre><code>add_library(libA-objs OBJECT ${HEADERS_PUBLIC} ${HEADERS_PRIVATE} ${SOURCES_PRIVATE})
  target_compile_options(libA-objs
      PRIVATE
          -o1
          -Wall -Wextra -pedantic
          -Wl,--whole-archive
  )
  target_link_libraries(libA-objs
     PRIVATE
         libB
         libC
         libD
  )
  
  ...
  
  # Build static library
  add_library(libA-static STATIC)
  target_link_libraries(libA-static PUBLIC libA-objs)
  
  # Build shared library
  add_library(libA-shared SHARED)
  target_link_libraries(libA-shared PUBLIC libA-objs)
  </code></pre>
  
  <p>I am properly installing <code>libA</code> on the system. I also have everything working to export <code>libA</code> in a way that a consuming application can just use <code>find_package()</code>.</p>
  
  <p>The application consuming <code>libA-shared</code> is a shared library itself (a plugin for a 3rd-party application):</p>
  
  <pre><code>find_package(libA REQUIRED)
  
  add_library(myplugin SHARED)
  target_link_libraries(myplugin
      PRIVATE
          libA::libA-shared
  )
  </code></pre>
  
  <p>Upon trying to build, the linker complains about not being able to find/resolve/link <code>libB</code>, <code>libC</code> and <code>libD</code>.
  I checked the targets configuration file generated by cmake when installing the exported targets (the scripts that a consuming application pulls in via <code>find_package()</code>) and I see that <code>libA-shared</code> contains references to <code>libB</code>, <code>libC</code> and <code>libD</code> in the <code>INTERFACE_LINK_LIBRARIES</code> as <code>LINK_ONLY</code>.</p>
  
  <p>Given that <code>libA-objs</code> links to the internal dependencies as <code>PRIVATE</code> and given that I am building a shared library (executable!) together with including the whole dependency archives I would have assumed for this to just work.
  I do not understand why the internal dependencies show up in the linking commands of a consuming executable as they are marked as <code>PRIVATE</code> within the <code>libA-objs</code> target.</p>
  
  <p>How do I solve this?</p>
  
  <p>I am using CMake 3.15, GCC 9.2 and would like this to also work with clang 8.0.</p>