CMake and lcov: gcno files not found

10,759

I have figured it out how to use lcov with CMake and bundled everything in a cmake module.

Share:
10,759
杨苏杭
Author by

杨苏杭

Updated on July 06, 2022

Comments

  • 杨苏杭
    杨苏杭 almost 2 years

    I am trying to get code coverage on my CMake based project (which consists of several targets).

    First I generate gcno files with:

    lcov -b . -d . -o coverage.output --capture --initial
    

    The *.gcno are generated in

    build_dir/[target_dir]/CMakeFiles/[target_dir].dir
    

    Then I run my tests which generate *.gcna files in

    build_dir/tests/CMakeFiles/[target_dir].dir
    

    When I now run lcov again:

    lcov -b . -d . -o coverage.output --capture
    

    I get the following error:

    Scanning . for .gcda files ...
    Found 23 data files in .
    Processing Base.dir/DateTools.cpp.gcda
    geninfo: ERROR: build_gcov/tests/CMakeFiles/Base.dir/DateTools.cpp.gcno: could not open file
    

    When I manually move the *.gcno file to the directory where the *.gcda is generated it seems to work.

    Thanks for your help!!!

  • tdihp
    tdihp over 11 years
    Thanks, your way is easier, for gcovr.