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
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(....)