title: Using gcov with CMake step by step
body: <p>I'm trying to run gcov on a project i'm working on, using <a href="https://github.com/bilke/cmake-modules/blob/master/CodeCoverage.cmake" rel="nofollow noreferrer">this guide</a>.</p>
  
  <p>I followed the instruction on the guide and read a lot of posts, including the <a href="https://stackoverflow.com/questions/13116488/detailed-guide-on-using-gcov-with-cmake-cdash">detailed guide</a> on this site.</p>
  
  <p>But I can't make it work.</p>
  
  <p>The steps I followed are:</p>
  
  <ol>
  <li><p>My main <code>CMakeLists.txt</code> of my project is inside a folder called <code>cmake</code>. Inside this folder I created another folder called <code>CMakeModules</code> and put the <code>CodeCoverage.cmake</code> file inside.</p></li>
  <li><p>I added this code to my CMakeLists.txt:</p>
  
  <pre><code>set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules)
  if(CMAKE_COMPILER_IS_GNUCXX)
  include(CodeCoverage)
  APPEND_COVERAGE_COMPILER_FLAGS()
  SETUP_TARGET_FOR_COVERAGE(NAME coverage 
  EXECUTABLE 
  DEPENDENCIES coverage)
  endif()
  </code></pre></li>
  <li><p>I compiled using the commands:</p>
  
  <pre><code>cmake -DCMAKE_BUILD_TYPE=DEBUG ../cmake
  # (I'm compiling from a subfolder of the master folder)
  
  make
  
  make coverage
  </code></pre></li>
  <li><p>I have an error when I run <code>make coverage</code> command:</p>
  
  <pre><code>[100%] Resetting code coverage counters to zero.
  Processing code coverage counters and generating report.
  
  Errno architecture (x86_64-linux-thread-multi-4.6.4-301.fc24.x86_64) does not match executable architecture (x86_64-linux-thread-multi-4.12.9-300.fc26.x86_64) at /usr/lib64/perl5/Errno.pm line 11.
  
  Compilation failed in require at /usr/share/perl5/vendor_perl/File/Temp.pm line 17.
  
  BEGIN failed--compilation aborted at /usr/share/perl5/vendor_perl/File/Temp.pm line 17.
  
  Compilation failed in require at /usr/bin/lcov line 66.
  
  BEGIN failed--compilation aborted at /usr/bin/lcov line 66.
  
  CMakeFiles/coverage.dir/build.make:57: set di istruzioni per l'obiettivo "CMakeFiles/coverage" non riuscito
  
  make[3]: *** [CMakeFiles/coverage] Error 255
  
  CMakeFiles/Makefile2:178: set di istruzioni per l'obiettivo "CMakeFiles/coverage.dir/all" non riuscito
  
  make[2]: *** [CMakeFiles/coverage.dir/all] Errore 2
  CMakeFiles/Makefile2:185: set di istruzioni per l'obiettivo "CMakeFiles/coverage.dir/rule" non riuscito
  
  make[1]: *** [CMakeFiles/coverage.dir/rule] Errore 2
  
  Makefile:214: set di istruzioni per l'obiettivo "coverage" non riuscito
  make: *** [coverage] Errore 2
  </code></pre></li>
  </ol>
  
  <p>My questions are:</p>
  
  <p>Exactly what should I put into the EXECUTABLE slot? The path to the executable that starts the program?</p>
  
  <p>The Setup of the program can be done just by that line I wrote?</p>
  
  <p>I already tried the solution from other threads on this site, but I can't anything that suggest me how to make this work.</p>