title: Code coverage analysis using CodeCoverage.cmake with multiple targets
body: <p>I have unit-test in my project implemented using <a href="https://www.boost.org/doc/libs/1_44_0/libs/test/doc/html/utf.html" rel="noreferrer">Boost Unit Test Framework</a> and organized into several modules, i.e.:</p>
  
  <pre><code>#define BOOST_TEST_MODULE Connection_test
  
  #ifndef BOOST_TEST_DYN_LINK
  #define BOOST_TEST_DYN_LINK
  #endif
  
  #ifndef BOOST_TEST_NO_MAIN
  #define BOOST_TEST_NO_MAIN
  #endif
  
  #include &lt;boost/test/unit_test.hpp&gt;
  #include &lt;boost/test/output_test_stream.hpp&gt;
  
  #define BOOST_TEST_MODULE Connection_test
  
  
  BOOST_AUTO_TEST_SUITE(Connection_test)
  
      BOOST_AUTO_TEST_CASE(Connection_construction__test) {
  
         ***
      }
  
  BOOST_AUTO_TEST_SUITE_END()
  </code></pre>
  
  <p>And I'm compiling every module as a single executable.</p>
  
  <p>I wanted to use <a href="https://github.com/bilke/cmake-modules/blob/master/CodeCoverage.cmake" rel="noreferrer">CodeCoverage.cmake</a> module to run code-coverage analysis, but I ran into a problem. I'm supposed to specify a test executable by <code>SETUP_TARGET_FOR_COVERAGE_LCOV</code>, but I don't have only one.</p>
  
  <p>Is there any way to setup multiple test executables at once with <code>CodeCoverage.cmake</code>?</p>
  
  <hr>
  
  <h3>EDIT</h3>
  
  <p>I've added tests by <code>add_test()</code> into my root CMakeLists.txt and modified my coverage target like this</p>
  
  <pre><code>include(CTest)
  add_test(NAME constant_neuron_test COMMAND constant_neuron_test)
  add_test(NAME binary_neuron_test COMMAND binary_neuron_test)
  add_test(NAME logistic_neuron_test COMMAND logistic_neuron_test)
  add_test(NAME connectionFunctionGeneral_test COMMAND connectionFunctionGeneral_test)
  add_test(NAME connection_Function_identity_test COMMAND connection_Function_identity_test)
  add_test(NAME neural_network_test COMMAND neural_network_test)
  add_test(NAME dataset_test COMMAND dataset_test)
  add_test(NAME particle_swarm_test COMMAND particle_swarm_test)
  add_test(NAME particle_test COMMAND particle_test)
  add_test(NAME NeuralNetworkSum_test COMMAND NeuralNetworkSum_test)
  add_test(NAME errorfunction_test COMMAND errorfunction_test)
  add_test(NAME DESolver_test COMMAND DESolver_test)
  
  include(CodeCoverage.cmake)
  APPEND_COVERAGE_COMPILER_FLAGS()
  SETUP_TARGET_FOR_COVERAGE_LCOV(
          NAME coverage                 # New target name
          EXECUTABLE ctest -C ${ROOT_DIR}/CTestTestfile.cmake # Executable in PROJECT_BINARY_DIR
          DEPENDENCIES ${Boost_LIBRARIES}         # Dependencies to build first
  )
  </code></pre>
  
  <p><code>ctest</code> itself runs correctly:</p>
  
  <pre><code>Test project /home/martin/4Neuro
        Start  1: constant_neuron_test
   1/12 Test  #1: constant_neuron_test ................   Passed    0.04 sec
        Start  2: binary_neuron_test
   2/12 Test  #2: binary_neuron_test ..................   Passed    0.04 sec
        Start  3: logistic_neuron_test
   3/12 Test  #3: logistic_neuron_test ................   Passed    0.05 sec
        Start  4: connectionFunctionGeneral_test
   4/12 Test  #4: connectionFunctionGeneral_test ......   Passed    0.04 sec
        Start  5: connection_Function_identity_test
   5/12 Test  #5: connection_Function_identity_test ...   Passed    0.04 sec
        Start  6: neural_network_test
   6/12 Test  #6: neural_network_test .................   Passed    0.04 sec
        Start  7: dataset_test
   7/12 Test  #7: dataset_test ........................   Passed    0.04 sec
        Start  8: particle_swarm_test
   8/12 Test  #8: particle_swarm_test .................   Passed    0.04 sec
        Start  9: particle_test
   9/12 Test  #9: particle_test .......................   Passed    0.04 sec
        Start 10: NeuralNetworkSum_test
  10/12 Test #10: NeuralNetworkSum_test ...............   Passed    0.05 sec
        Start 11: errorfunction_test
  11/12 Test #11: errorfunction_test ..................   Passed    0.04 sec
        Start 12: DESolver_test
  12/12 Test #12: DESolver_test .......................   Passed    0.05 sec
  
  100% tests passed, 0 tests failed out of 12
  
  Total Test time (real) =   0.53 sec
  </code></pre>
  
  <p>But when I try to create my coverage report by <code>make coverage</code>, I get this error:</p>
  
  <pre><code>Processing code coverage counters and generating report.
  cd /home/martin/4Neuro/build &amp;&amp; /usr/bin/lcov --gcov-tool /usr/bin/gcov -directory . --zerocounters
  Deleting all .da files in . and subdirectories
  Done.
  cd /home/martin/4Neuro/build &amp;&amp; /usr/bin/lcov --gcov-tool /usr/bin/gcov -c -i -d . -o coverage.base
  Capturing coverage data from .
  Found gcov version: 7.3.0
  Scanning . for .gcno files ...
  geninfo: WARNING: no .gcno files found in . - skipping!
  Finished .info-file creation
  cd /home/martin/4Neuro/build &amp;&amp; ctest -C /home/martin/4Neuro/CTestTestfile.cmake
  Test project /home/martin/4Neuro/build
  No tests were found!!!
  cd /home/martin/4Neuro/build &amp;&amp; /usr/bin/lcov --gcov-tool /usr/bin/gcov --directory . --capture --output-file coverage.info
  Capturing coverage data from .
  Found gcov version: 7.3.0
  Scanning . for .gcda files ...
  geninfo: WARNING: no .gcda files found in . - skipping!
  Finished .info-file creation
  cd /home/martin/4Neuro/build &amp;&amp; /usr/bin/lcov --gcov-tool /usr/bin/gcov -a coverage.base -a coverage.info --output-file coverage.total
  Combining tracefiles.
  Reading tracefile coverage.base
  lcov: ERROR: no valid records found in tracefile coverage.base
  CMakeFiles/coverage.dir/build.make:62: recipe for target 'CMakeFiles/coverage' failed
  make[3]: *** [CMakeFiles/coverage] Error 255
  make[3]: Leaving directory '/home/martin/4Neuro'
  CMakeFiles/Makefile2:70: recipe for target 'CMakeFiles/coverage.dir/all' failed
  make[2]: *** [CMakeFiles/coverage.dir/all] Error 2
  make[2]: Leaving directory '/home/martin/4Neuro'
  CMakeFiles/Makefile2:77: recipe for target 'CMakeFiles/coverage.dir/rule' failed
  make[1]: *** [CMakeFiles/coverage.dir/rule] Error 2
  make[1]: Leaving directory '/home/martin/4Neuro'
  Makefile:132: recipe for target 'coverage' failed
  make: *** [coverage] Error 2
  </code></pre>
  
  <hr>
  
  <h3>EDIT 2</h3>
  
  <p>I've modified my CMakeLists.txt like this</p>
  
  <pre><code>include(CTest)
  enable_testing()
  add_subdirectory(${SRC_DIR} ${PROJECT_BINARY_DIR})
  
  # Adding Unit-tests
  add_test(NAME constant_neuron_test COMMAND constant_neuron_test)
  add_test(NAME binary_neuron_test COMMAND binary_neuron_test)
  add_test(NAME logistic_neuron_test COMMAND logistic_neuron_test)
  add_test(NAME connectionFunctionGeneral_test COMMAND connectionFunctionGeneral_test)
  add_test(NAME connection_Function_identity_test COMMAND connection_Function_identity_test)
  add_test(NAME neural_network_test COMMAND neural_network_test)
  add_test(NAME dataset_test COMMAND dataset_test)
  add_test(NAME particle_swarm_test COMMAND particle_swarm_test)
  add_test(NAME particle_test COMMAND particle_test)
  add_test(NAME NeuralNetworkSum_test COMMAND NeuralNetworkSum_test)
  add_test(NAME errorfunction_test COMMAND errorfunction_test)
  add_test(NAME DESolver_test COMMAND DESolver_test)
  
  include(CodeCoverage.cmake)
  APPEND_COVERAGE_COMPILER_FLAGS()
  SETUP_TARGET_FOR_COVERAGE_LCOV(
          NAME coverage                 # New target name
          EXECUTABLE ctest -j ${n_cores} # Executable in PROJECT_BINARY_DIR
          DEPENDENCIES
              constant_neuron_test
              binary_neuron_test
              logistic_neuron_test
              connectionFunctionGeneral_test
              connection_Function_identity_test
              neural_network_test
              dataset_test
              particle_swarm_test
              particle_test
              NeuralNetworkSum_test
              errorfunction_test
              DESolver_test         # Dependencies to build first
  )
  set(COVERAGE_EXCLUDES 'external_dependencies/*')
  </code></pre>
  
  <p>But, unfortunately, the error persists</p>
  
  <pre><code>cd /home/martin/4Neuro/build &amp;&amp; /usr/bin/lcov --gcov-tool /usr/bin/gcov -c -i -d . -o coverage.base
  Capturing coverage data from .
  Found gcov version: 7.3.0
  Scanning . for .gcno files ...
  geninfo: WARNING: no .gcno files found in . - skipping!
  Finished .info-file creation
  cd /home/martin/4Neuro/build &amp;&amp; ctest -j 3
  Test project /home/martin/4Neuro/build
  No tests were found!!!
  cd /home/martin/4Neuro/build &amp;&amp; /usr/bin/lcov --gcov-tool /usr/bin/gcov --directory . --capture --output-file coverage.info
  Capturing coverage data from .
  Found gcov version: 7.3.0
  Scanning . for .gcda files ...
  geninfo: WARNING: no .gcda files found in . - skipping!
  Finished .info-file creation
  cd /home/martin/4Neuro/build &amp;&amp; /usr/bin/lcov --gcov-tool /usr/bin/gcov -a coverage.base -a coverage.info --output-file coverage.total
  Combining tracefiles.
  Reading tracefile coverage.base
  lcov: ERROR: no valid records found in tracefile coverage.base
  CMakeFiles/coverage.dir/build.make:71: recipe for target 'CMakeFiles/coverage' failed
  make[3]: *** [CMakeFiles/coverage] Error 255
  make[3]: Leaving directory '/home/martin/4Neuro'
  CMakeFiles/Makefile2:81: recipe for target 'CMakeFiles/coverage.dir/all' failed
  make[2]: *** [CMakeFiles/coverage.dir/all] Error 2
  make[2]: Leaving directory '/home/martin/4Neuro'
  CMakeFiles/Makefile2:88: recipe for target 'CMakeFiles/coverage.dir/rule' failed
  make[1]: *** [CMakeFiles/coverage.dir/rule] Error 2
  make[1]: Leaving directory '/home/martin/4Neuro'
  Makefile:132: recipe for target 'coverage' failed
  make: *** [coverage] Error 2
  </code></pre>