title: Using --whole-archive linker option with CMake and libraries with other library dependencies
body: <p>I've got a project that used to be a giant set of source files that all got compiled and then linked as one executable.  As a first step in making the project more modular, I am breaking up the build into several smaller chunks and making them static libraries. There's a hierarchy, so <code>Exe1</code> will link against static libs <code>Lib2A</code> and <code>Lib2B</code>. <code>Lib2A</code> will depend on static <code>Lib3A</code>, <code>lib3B</code>, <code>lib3C</code>, etc.  The numbers here show their layer in the hierarchy.</p>
  
  <p>The problem is that I need to use <code>--whole-archive</code> when linking or else some symbols from the underlying libraries are not found.  </p>
  
  <p>When I add the below for the linking of <code>Exe1</code>:</p>
  
  <pre><code>target_link_libraries(Exe1 -Wl,--whole-archive Lib2A Lib2B -Wl,--no-whole-archive)
  </code></pre>
  
  <p>I end up with an actual link stage command like:</p>
  
  <pre><code>g++ -o Exe1 -Wl,--whole-archive libLib2A.a libLib2B.a -Wl,--no-whole-archive libLib3A.a libLib3B.a libLib3C.a
  </code></pre>
  
  <p>Inevitably, symbols from some of the layer 3 static libraries get lost and I get missing symbol errors.</p>
  
  <p>I expected that because <code>Lib2A</code> has <code>Lib3*</code> libraries as dependencies, that they would also be "inside" the <code>--whole-archive</code> part of the linker command, but they show up outside.</p>
  
  <p>I've tried many different combinations (e.g. putting the <code>--whole-archive</code> stuff at lower layers), but haven't come across an approach that works using CMake.  What am I doing wrong?</p>
  
  <p>Thanks</p>