Avoid cMake rebuild/compilation of sub project (library)
<p>I have a bunch of C++ source files and static libraries which form a <strong>framework F</strong>. To use this, I have created a main_A.cpp and some cMake files, which create an executable and run successfully (<strong>project A</strong>).</p>

<p>Now I use a different main_B.cpp for <strong>project B</strong>. For this I created an own cMakeLists.txt with e.g. a different executable name and which refers to the config.cmake files for <strong>framework F</strong></p>

<pre><code>framework F (global config.cmake)  
|  
|___ project A   
|  
|___ project B (own cMakeLists.txt)  
</code></pre>

<p>When I compile <strong>project B</strong> after <strong>project A</strong>, all the files from <strong>framework F</strong> get recompiled, which takes long and is unnecessary. </p>

<p><em>How do I get cMake to detect that framework F is already compiled when using a different projects?</em></p>

<p><strong>Approach:</strong> Create static libraries, and compile them into a common folder (lib):</p>

<pre><code>add_library( framework STATIC ${SRC_FILES} )
set_target_properties( framework PROPERTIES LIBRARY_OUTPUT_DIRECTORY /lib)
</code></pre>

<p>The libraries got compiled and put into /lib but when I compile <strong>project B</strong>, everything gets re-compiled.</p>