title: CMake building for Windows (clang-cl) using Ninja Generator
body: <p>I am trying to build a simple application on a Windows machine using CMake as the main build tool. Once CMake is invoked on the project the is an error on configuration phase:</p>
  
  <pre><code>&gt; cmake -H. -G Ninja -Bbuild -DCMAKE_C_COMPILER:PATH="C:\Program Files\LLVM\bin\clang-cl.exe" -DCMAKE_CXX_COMPILER:PATH="C:\Program Files\LLVM\bin\clang-cl.exe"
  
  -- The C compiler identification is Clang 7.0.0
  -- The CXX compiler identification is Clang 7.0.0
  -- Check for working C compiler: C:/Program Files/LLVM/bin/clang-cl.exe
  -- Check for working C compiler: C:/Program Files/LLVM/bin/clang-cl.exe --broken
  CMake Error at C:/Program Files/CMake/share/cmake-3.12/Modules/CMakeTestCCompile
  r.cmake:52 (message):
    The C compiler
  
      "C:/Program Files/LLVM/bin/clang-cl.exe"
  
    is not able to compile a simple test program.
  
    It fails with the following output:
  
      Change Dir: C:/Users/mak/Desktop/cmake-test/build/CMakeFiles/CMakeTmp
  
      Run Build Command:"C:/Qt/Tools/QtCreator/bin/ninja.exe" "cmTC_f5485"
      [1/2] Building C object CMakeFiles\cmTC_f5485.dir\testCCompiler.c.obj
      [2/2] Linking C executable cmTC_f5485.exe
      FAILED: cmTC_f5485.exe
      cmd.exe /C "cd . &amp;&amp; "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_f5485.dir --manifests  -- CMAKE_LINKER-NOTFOUND  /nologo CMakeFiles\cmTC_f5485.dir\testCCompiler.c.obj  /out:cmTC_f5485.exe /implib:cmTC_f5485.lib /pdb:cmTC_f5485.pdb /version:0.0  /machine:x64  /debug /INCREMENTAL /subsystem:console  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib &amp;&amp; cd ."
      RC Pass 1: command "rc /foCMakeFiles\cmTC_f5485.dir/manifest.res CMakeFiles\cmTC_f5485.dir/manifest.rc" failed (exit code 0) with the following output:
      The system cannot find the given file
      ninja: build stopped: subcommand failed.
  
    CMake will not be able to correctly generate this project.
  Call Stack (most recent call first):
    CMakeLists.txt:3 (project)
  </code></pre>
  
  <p>I read a lot through the web but my problem was not solved by any proposed solution. What I found so far is a simmilar but maybe outdated <a href="https://stackoverflow.com/questions/46553436/building-with-cmake-ninja-and-clang-on-windows">solution</a> to the same problem which did not work for me, because Ninja was not able to build the executable:</p>
  
  <pre><code>&gt; ninja all
  [1/2] Building CXX object CMakeFiles/minimal.dir/main.cpp.obj
  FAILED: CMakeFiles/minimal.dir/main.cpp.obj
  C:\PROGRA~1\LLVM\bin\clang-cl.exe     -MD -MT CMakeFiles/minimal.dir/main.cpp.obj -MF CMakeFiles\minimal.dir\main.cpp.obj.d -o CMakeFiles/minimal.dir/main.cpp.obj -c ../main.cpp
  clang-cl.exe: warning: unknown argument ignored in clang-cl: '-MF' [-Wunknown-argument]
  clang-cl.exe: error: no such file or directory: 'CMakeFiles/minimal.dir/main.cpp.obj'
  clang-cl.exe: error: no such file or directory: 'CMakeFiles\minimal.dir\main.cpp.obj.d'
  ninja: build stopped: subcommand failed.
  </code></pre>
  
  <p>Before this error CMake configured properly except that all compilers ABI info detection failed - but CMake resumed without error. There are <a href="https://stackoverflow.com/questions/22585874/building-c-project-on-windows-with-cmake-clang-and-ninja">some</a> <a href="https://stackoverflow.com/questions/41237300/clang-and-cmake-on-windows">other</a> questions out there which did not help either.</p>
  
  <p>The official <a href="https://clang.llvm.org/docs/UsersManual.html#clang-cl" rel="noreferrer">documentation</a> states it is quite simple but in fact it is not.</p>
  
  <p><strong>So:</strong> How do I build a <em>simple</em> C++ project using CMake with the Ninja generator and Clang as the compiler? I try to avoid the installation of Visual Studio but it would be great if generated binaries are compatible with MSVC build binaries.</p>
  
  <p><strong>Versions:</strong></p>
  
  <ul>
  <li>CMake 3.12.2</li>
  <li>Ninja 1.8.2</li>
  <li>Clang 7.0.0</li>
  </ul>
  
  <hr>
  
  <p><strong>Example:</strong> Here is the minial example which I am working with:</p>
  
  <p><em>CMakeLists.txt</em></p>
  
  <pre><code>cmake_minimum_required(VERSION 3.12)
  project(minimal)
  add_executable(${PROJECT_NAME} main.cpp)
  </code></pre>
  
  <p><em>main.cpp</em></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(void)
  {
    printf("Hello World!\n");
    return 0;
  }
  </code></pre>