title: CMake: reuse object files built for a lib into another lib target
body: <p>I'm trying to move my project to CMake, and at the same time have some optimization on the compilation process.</p>
  
  <p>Here's the deal:  </p>
  
  <ul>
  <li>I have several subdirs that are (have to be) each compiled into a static library (this works).</li>
  <li>I want to gather all the object files from each subdir into another bigger, complete, static library.</li>
  </ul>
  
  <p>It looks like this:</p>
  
  <pre><code>.
  libBig.a  # made from object from subdir1 and subdir2
  subdir1/
     src/
     libSubdir1.a
  subdir2/
     src/
     libSubdir2.a
  </code></pre>
  
  <p>Today, I managed to use a global variable in which every subdir CMakeLists.txt will append its own source files. I use this variable as a "source" input in my big library:</p>
  
  <pre><code># the big library depends on all the source files
  # ${all_src} is automatically filled with each subdir's cpp file
  get_property( BigLib_src GLOBAL PROPERTY all_src)
  add_library( Big STATIC ${BigLib_src}) # recompiles all the sources
  </code></pre>
  
  <p>Now, this works, not too bad, but the thing is, <strong>all my source files get compiled twice</strong>: once for the subdir library, and once for the big library.</p>
  
  <p>CMake seems to forget that it has already built them.</p>
  
  <p>I <em>have</em> to keep the subdir libraries and <code>ar</code> can't merge two static libraries.</p>
  
  <p>Do you know how to do that?</p>