title: Combining several static libraries into one using CMake
body: <p>I have a very similar problem to one <a href="https://cmake.org/pipermail/cmake/2014-August/058231.html" rel="noreferrer">described</a> on the cmake mailing list where we have a project dependent on many static libraries (all built from source in individual submodules, each with their own CMakeLists.txt describing the build process for each library) that I'd like to combine into a single static library for release to the consumers. The dependencies of my library are subject to change, and I do not want to burden developers further down the chain with those changes. The neat solution would be to bundle all of the libs into one single lib.</p>
  
  <p>Interestingly, the <code>target_link_libraries</code> command does not combine all of the statics when setting the target to <code>mylib</code> and using it like so . . </p>
  
  <pre><code>target_link_libraries(mylib a b c d)
  </code></pre>
  
  <p>However, bizarrely, if I make the <code>mylib</code> project a submodule of an executable project, and only link against <code>mylib</code> in the top level executable CMAkeLists.txt, the library does seem to be combined. I.e. mylib is 27 MB, instead of the 3MB when I set the target to only build <code>mylib</code>.</p>
  
  <p>There are solutions describing unpacking of the libs into object files and recombining (<a href="https://cmake.org/pipermail/cmake/2014-August/058235.html" rel="noreferrer">here</a>, and <a href="https://stackoverflow.com/questions/2662430/combining-several-static-archives-into-a-new-one">here</a>), but this seems remarkably clumsy when CMake seems perfectly capable of automatically merging the libs as described in the above example. It there a magic command I'm missing, or a recommended elegant way of making a release library?</p>