title: VSCode CMake Extension rebuild all project each time
body: <p>I'm working on a project in C++ configured using CMake.<br />
  Each time I build the project, all files are recompiled, which is unbearable considering the time it takes.</p>
  <h3>With Visual Studio Code</h3>
  <p>I'm trying to use VSCode and the CMake Extension.<br />
  The <code>CMake:Configure</code> command works well and so does the <code>CMake:Build</code> command. It takes a lot of time to compile because I use highly templatized header-only libraries like Eigen3, Boost and CGAL, so I need to build a pre-compiled header. It build some librairies too. But it is normal that it takes time for a first compilation.</p>
  <p>However, if I build the target again (without modifying anything in the code) the compilation is completely redone ! I just want the modified source files or librairies to be re-compiled. Or if a header in the list of pre-compiled headers is modified, only then should the pre-compiled headers be recompiled.</p>
  <h3>With Visual Studio 2019</h3>
  <p>I thought that VSCode didn't work with a concept of &quot;project&quot;, and therefore had to reconfigure and recompile the whole project every time it was launched.<br />
  So I decided to generate a Visual Studio Solution with the CMake-GUI program and use Visual Studio 2019 instead of VSCode.<br />
  Now when I build a second time my project, nothing is recompiled and the program is directly lauched. Visual Studio say :</p>
  <pre><code>========== Build: 0 succeeded, 0 failed, 5 up-to-date, 0 skipped ==========
  </code></pre>
  <p>Wonderful!<br />
  Unfortunately not..., because if I modify a file, Visual Studio keeps telling me that everything is up-to-date and my modifications are not taken into account. I need to &quot;Rebuild&quot; the project so that everything will be recompiled, which does not solve my problem as it takes a lot of time.</p>
  <h3>Question</h3>
  <p>How to recompile only modified source files, librairies or pre-compiled headers (with VS Code, Visual Studio or both) ?</p>
  <hr />
  <p><strong>Plaform</strong> : Windows 10</p>
  <h1>Edit 15.04.21</h1>
  <p>I did some more methodical testing today to find out what the problem might be.<br />
  I used a very simple project to do the tests.</p>
  <h3>CMakeList.txt</h3>
  <pre><code>cmake_minimum_required (VERSION 3.8)
  project (&quot;HelloCMake&quot;)
  add_executable (HelloCMake &quot;HelloCMake.cpp&quot;)
  </code></pre>
  <h3>HelloCMake.cpp</h3>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  int main() {
      std::cout &lt;&lt; &quot;Hello CMake !&quot; &lt;&lt; std::endl;
      return 0;
  }
  </code></pre>
  <h2>1. With VSCode and CMake Tools Extension</h2>
  <blockquote>
  <p>With the <a href="https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools" rel="nofollow noreferrer">CMake Tools</a> Extension, VSCode can configure and build a CMake project. It generate a Visual Studio Solution (<code>.sln</code>).</p>
  </blockquote>
  <ol>
  <li>Build the target with CMake Tools Extension which makes VSCode to run the command :
  <pre class="lang-sh prettyprint-override"><code>cmake --build &lt;PROJECT_DIR&gt;/build --config Release --target HelloCMake -- 
  /maxcpucount:14
  </code></pre>
  </li>
  <li>The entire target is compiled</li>
  <li>I build it again (without changes)</li>
  <li>The target is completely recompiled again</li>
  </ol>
  <p>The problem is that the target is completely recompiled, every time. I asked the question directly to the CMake Tools developers. <a href="https://github.com/microsoft/vscode-cmake-tools/issues/1768" rel="nofollow noreferrer"><em>GitHub Issue</em></a></p>
  <h2>2. .sln project generated by CMake (Visual Studio 2019)</h2>
  <ol>
  <li>I generated a Visual Studio Solution with CMake and open it.</li>
  <li>I build my project HelloCMake</li>
  <li>I do some modifications in source file</li>
  <li>I build the project again, but Visual Studio never takes my modifications into account. The builds are always &quot;up-to-date&quot;.</li>
  </ol>
  <p>The problem is that Visual Studio does not take my changes into account. I have to rebuild the project, which takes too much time.</p>
  <h2>3. Directly open CMake project with Visual Studio 2019 (Ninja)</h2>
  <blockquote>
  <p>If you open a CMakeList.txt with Visual Studio 2019, it is not a Visual Studio Solution that is generated but a Ninja one.</p>
  </blockquote>
  <p>It seems that this way the compilation works correctly !</p>
  <p>According to this research, it is the CMake Tools Extension for VSCode as well as the Visual Studio Solution that cause problems.</p>
  <p><strong>I can't figure out why such a simple project doesn't compile properly with a Visual Studio Solution generated by CMake.</strong></p>