title: CMake: how create a single shared library from all static libraries of subprojects?
body: <p>I have the following layout:</p>
  
  <pre><code>top_project
      + subproject1
      + subproject2
  </code></pre>
  
  <p>Each of <code>subproject1</code> and <code>subproject2</code> creates a static library. I would like to link these static libraries in a single shared library at the <code>top_project</code> level.</p>
  
  <p>The information I gathered so far is:</p>
  
  <ul>
  <li>Either compile using <code>-fPic</code> (necessary on everything but Windows) in order to create position-independent code which will allow linking the static libraries into a single shared library or decompress all static libraries (e.g. using <code>ar</code>) and re-link them into a shared library (which I think is an inelegant &amp; non-portable solution)</li>
  <li>All source files must be given explicitly to the <code>add_library</code> command: for some reason which I cannot comprehend, simply writing <code>add_library(${PROJECT_NAME} SHARED subproject1 subproject2)</code> does not work as expected (it essentially creates an empty library &amp; does not register the dependencies properly)</li>
  <li>There is an OBJECT library feature in CMake but I don't think it's purpose is really to do what I want.</li>
  </ul>
  
  <p>Any thoughts?</p>