4

I already tried a lot of solutions that i founded but none of then work. I'm working on a new code for a project, but this code was touched by a lot of master and doctor degrees that do not care on make it readeable. So there is really bunch of things that is not useful or even used.

Then i head about gcov and lcov, but after i generate .info file and load into lcov html, besides of all my files it just track the main file! Even knowing a lot of other functions and files were used!

(Really sorry for my bad english, im from Manaus, Amazonas - Brazil and not a good english speaker! But ive looked for this answer for like a month trying alot of things but got no luck at all)

My files look like:

    -src/
       -core/
         -Index.cpp/h
         -PostingList.cpp/h
         -PreProcessor.cpp/h
       -methods/
         ...
       -parser/
         ...
       -run/
         ...
       -structures/
         ...
       -utils/
         ...

I got a CMakeFile.txt in project source directory that look like this:

   cmake_minimum_required (VERSION 2.4)
   project (queryProcessor)

   include("${${PROJECT_NAME}_SOURCE_DIR}/globalVariables.cmake")

   include_directories(${INCLUDES})

   link_directories(${LIBS})

   if(COMMAND cmake_policy)
     cmake_policy(SET CMP0003 NEW)
   endif(COMMAND cmake_policy)

   add_subdirectory(src)

   add_executable(QueryProcessor src/run/queryProcessor.cpp)
   target_link_libraries (QueryProcessor libQueryProcessor rt -fprofile-arcs)

   add_definitions(-O2 )

and another on src directory that looks like this:

   aux_source_directory( utils UTILS )
   aux_source_directory( parser PARSER )
   aux_source_directory( methods METHODS )
   aux_source_directory( structures STRUCTURES )
   aux_source_directory( core CORE )
   aux_source_directory( . SRC )
   aux_source_directory( ../../libs-iw/indexer/include UTILS2 )

   add_library( libQueryProcessor ${UTILS} ${UTILS2} ${SRC} ${PARSER} ${METHODS} ${STRUCTURES} ${CORE})

   set(CMAKE_CXX_FLAGS "--coverage")

   include ( ${${PROJECT_NAME}_SOURCE_DIR}/install.cmake )

Any help will be appreciated including suggestions for better CMakeFiles, thanks in advance

  • Have libQueryProcessor object files actually been compiled with proper flags? Use `make clean; make VERBOSE=1` to switch to the verbose mode and carefully inspect compiler and linker invocation flags. – user3159253 Apr 30 '16 at 04:44
  • Also, it's wise to move all compilation flag manipulations _before_ defining a new target or adding a subdirectory. – user3159253 Apr 30 '16 at 04:46
  • Thanks @user3159253! Already move flag manipulations now and readed carefully the verbose output. The only difference from a file to another is when linking the CXX executable it has a -fprofile-arcs argument, Is this the one that in every cpp need to have? – thomaz andrade Apr 30 '16 at 16:51
  • 1
    @thomazandrade You should try [pt.stackoverflow.com](http://pt.stackoverflow.com). It's in Portuguese (em Português). Your English isn't that bad, but I figured you might be more comfortable over there :) – Laurel May 19 '16 at 01:30

1 Answers1

1

Sorry for a delay.

You need to compile every source file in the program with proper options to use gcov. The documentation mentions -fprofile-args -ftest-coverage, but you might want to use other option related to profiling as well.

So you need to append those flags as suggested in How to add linker or compile flag in cmake file? before all target definitions (i.e. somewhere near the beginning of the main CMakeLists.txt) You may want to add an CMake option to control these flags at once:

option(USE_GCOV "Create a GCov-enabled build." OFF)
...
if (USE_GCOV)
  set(GCC_COVERAGE_COMPILE_FLAGS "-fprofile-arcs -ftest-coverage")
  set(GCC_COVERAGE_LINK_FLAGS    "-lgcov")
endif()
set( CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}" )
set( CMAKE_EXE_LINKER_FLAGS  "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}" )
...
add_subdirectory(...)
add_library(....)
add_executable(....)
Community
  • 1
  • 1
user3159253
  • 16,836
  • 3
  • 30
  • 56
  • Really thank you!! Now it works like a charm, the only problem is that it generate .gcda files in a lot of differents folders, but i will look now for a solution! Thanks again!! Have a great week – thomaz andrade May 01 '16 at 17:10
  • Depending on your needs there could be various solutions. You may write a shell script to -rule- collect them all, or you may try to re-structure where your object files get created. You just need to formulate your needs more precisely and ask proper questions ;) – user3159253 May 01 '16 at 20:12