title: CMake generated Ninja project fails at compiling with GCC
body: <p>I have a cross platform CMake project that works perfectly with <code>make/gcc</code> on Linux and with <code>MSVC</code> on Windows. I wanted to give <code>ninja</code> a try and compare it with <code>make</code>. This is how I am creating the <code>ninja</code> project:</p>
  
  <pre><code>cmake -GNinja ../Source/
  </code></pre>
  
  <p>and then I run </p>
  
  <pre><code>ninja
  </code></pre>
  
  <p>but it fails with this error</p>
  
  <pre><code>/usr/bin/c++ -DmyPreprocessors ... -ImyIncludes ... -g3 -o0 -m32 -MMD -MT CMakeFiles/myProj.dir/myCode.cpp.o -MF CMakeFiles/myProj.dir/myCode.cpp.o.d -o CMakeFiles/myProj.dir/myCode.cpp.o -c /path/to/myCode.cpp 
  
  cc1plus: fatal error: CMakeFiles/myProj.dir/myCode.cpp.d: No such file or directory
  </code></pre>
  
  <p>and when I check <code>CMakeFiles/myProj.dir/</code> there is no <code>myCode.cpp.d</code> file.</p>
  
  <p>But when I change the compiler to <code>clang</code> everything magically works! Ninja starts compiling and then successfully links. </p>
  
  <p>When I run <code>ninja</code> in verbose mode I get the exact same command except the compiler is <code>clang</code> (<code>/usr/bin/c++</code> => <code>/usr/bin/clang++-3.9</code>).</p>
  
  <p>what is going on here?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Here is a sample CMakeLists.txt file that I used to reproduce the same error:</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.5)
  project(randomProj)
  
  set(SOURCE_FILES myFile.cpp)
  
  include_directories(Generic)
  
  set(EXECUTABLE "TEST")
  
  add_executable(${EXECUTABLE} ${SOURCE_FILES})
  set(LIBRARY_SEARCH_PATH ${CMAKE_SOURCE_DIR}/path/to/my/libs)
  
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w -g3 -o0")
  target_link_libraries(${EXECUTABLE}  ${LIBRARIES})
  </code></pre>
  
  <p>and my <code>myFile.cpp</code> is this:</p>
  
  <pre><code>int main(){}
  </code></pre>
  
  <p>I did not specify anything explicitly for <code>gcc</code>. For <code>clang</code> however I just export the <code>CC</code> and <code>CXX</code> flags:</p>
  
  <pre><code>export CC=clang-3.9
  export CXX=clang++-3.9
  </code></pre>
  
  <p>and then I call cmake.</p>