title: configuring code coverage with cmake
body: <p>I'm on a linux machine, trying to build a project using cmake that does out of source builds. For code coverage, I looked into gcov and followed a simple tutorial that generate appropriate files for a sample <code>helloWorld.cpp</code> program. The only requirement were to compile with <code>-fprofile-arcs -ftest-coverage</code> flags &amp; link with <code>-lgcov</code> flag, which can be done altogether with <code>-coverage</code> flag.</p>
  
  <p>Now here comes the tricky part. I have a <code>CMakeLists.txt</code> wit contents as shown below:</p>
  
  <pre><code>cmake_minimum_required (VERSION 2.8)
  project (SomeName)
  
  SET(GCC_COVERAGE_COMPILE_FLAGS "-g -O0 -coverage -fprofile-arcs -ftest-coverage")
  SET(GCC_COVERAGE_LINK_FLAGS    "-coverage -lgcov")
  SET( CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}" )
  SET( CMAKE_EXE_LINKER_FLAGS  "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}" )
  
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
  
  include_directories(include)
  set(CATCH_HEADER_PATH ${PROJECT_SOURCE_DIR}/test/catch.hpp)
  
  add_executable(runTest ${PROJECT_SOURCE_DIR}/test/test.cpp ${CATCH_HEADER_PATH}) 
  </code></pre>
  
  <p>So I've included appropriate compile time flags as well as linker flags too and appended them correctly. Another thing to note is <code>set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)</code> line which says that executables will be generated inside <strong><code>bin</code></strong> directory. </p>
  
  <p>Now everything works as intended except that coverage files aren't generated properly. I follow these steps :</p>
  
  <pre><code>mkdir build &amp;&amp; cd build
  cmake ..
  make -j4
  ./bin/runTest
  </code></pre>
  
  <p>and no other file is generated inside <strong><code>bin</code></strong> folder. However on more inspection I found out that there is another location <strong><code>build/CMakeFiles/runTest.dir/test</code></strong> where <code>test.cpp.o</code> resides initially and after the final step <code>./bin/runTest</code>, two new files - <code>test.cpp.gcda</code> &amp; <code>test.cpp.gcno</code> are generated.</p>
  
  <p>I've already tried copying <code>test/test.cpp</code> to <strong><code>build/CMakeFiles/runTest.dir/test</code></strong> and running <code>gcov test.cpp</code> but it fails stating - <code>test.gcno:cannot open notes file</code></p>