title: CMake: How can I build a shared and a static library without recompiling the sources twice
body: <p>I want to build both a static and shared version of the same library as described <a href="https://stackoverflow.com/questions/2152077/is-it-possible-to-get-cmake-to-build-both-a-static-and-shared-version-of-the-sam">Is it possible to get CMake to build both a static and shared version of the same library?</a></p>
  
  <p>However, the sources are compiled twice, one for each version which is not necessary. Is there any way to avoid this?</p>
  
  <p>Currently I have:</p>
  
  <pre><code>add_library(${LIB} SHARED ${${LIB}_srcs})
  
  add_library(${LIB}_static STATIC ${${LIB}_srcs})
  </code></pre>
  
  <p>What do I need to change in order to only need to compile once? FYI. I have the same compiler flags and defines.</p>