title: How to build static and shared library at the same time through cmake
body: <p>I am learning cmake on windows.<br>
  I read and run <a href="https://cognitivewaves.wordpress.com/cmake-and-visual-studio/" rel="nofollow noreferrer">this example</a> so that I can build both static and shared libraries from one visual studio project.<br>
  I found this command:<br></p>
  
  <pre><code>add_library(math SHARED ${MATH_SOURCES} ${SIMPLE_FUNCTION_SOURCES} ${ADVANCED_FUNCTION_SOURCES})
  </code></pre>
  
  <p>According to my understanding, this command is building shared library. Also, from <a href="https://stackoverflow.com/questions/2152077/is-it-possible-to-get-cmake-to-build-both-a-static-and-shared-version-of-the-sam">here</a>, if I want to build static and shared library, I have to do it by two projects.<br>
  <br>
  So, why the first example I used can build both libraries from one Visual Studio project?<br></p>
  
  <p><strong>Edit</strong><br>
  Thanks for <code>Florian</code>, the key point is in <code>MathExports.h</code>. To let people easier to see, I put the file here:<br></p>
  
  <pre><code>#ifndef MathExports_h
  #define MathExports_h
  
  #ifdef _WIN32
      #ifdef math_EXPORTS
          #define  MATH_EXPORT __declspec( dllexport )
      #else
          #define  MATH_EXPORT __declspec( dllimport )
      #endif
  #else
      #define    MATH_EXPORT
  #endif
  
  #endif // MathExports_h
  </code></pre>