Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Support for lcov/gcov with Ninja #30

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build*
.vscode
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ endif (POLICY CMP0042)
# project information
#
if (${CMAKE_MAJOR_VERSION} EQUAL 3)
project("test" LANGUAGES C Fortran)
project("test" LANGUAGES C)
else ()
project("test" C Fortran)
project("test" C)
endif ()


Expand Down
2 changes: 1 addition & 1 deletion cmake/FindGcov.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function (add_gcov_target TNAME)
add_custom_command(OUTPUT ${TDIR}/${FILE}.gcov
COMMAND ${GCOV_ENV} ${GCOV_BIN} -p ${TDIR}/${FILE}.gcno > ${NULL_DEVICE}
DEPENDS ${TNAME} ${TDIR}/${FILE}.gcno
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)

list(APPEND BUFFER ${TDIR}/${FILE}.gcov)
Expand Down
12 changes: 7 additions & 5 deletions cmake/FindLcov.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ if (GENINFO_BIN AND NOT DEFINED GENINFO_EXTERN_FLAG)
execute_process(COMMAND ${GENINFO_BIN} --help OUTPUT_VARIABLE GENINFO_HELP)
string(REGEX MATCH "external" GENINFO_RES "${GENINFO_HELP}")
if (GENINFO_RES)
set(FLAG "--no-external")
#set(FLAG "--no-external")
endif ()

set(GENINFO_EXTERN_FLAG "${FLAG}"
Expand All @@ -91,6 +91,8 @@ file(MAKE_DIRECTORY ${LCOV_DATA_PATH_CAPTURE})

set(LCOV_REMOVE_PATTERNS "")

#set(BASE_DIRECTORY "--base-directory ${PROJECT_SOURCE_DIR}")

# This function will merge lcov files to a single target file. Additional lcov
# flags may be set with setting LCOV_EXTRA_FLAGS before calling this function.
function (lcov_merge_files OUTFILE ...)
Expand All @@ -107,7 +109,7 @@ function (lcov_merge_files OUTFILE ...)

add_custom_command(OUTPUT "${OUTFILE}"
COMMAND ${LCOV_BIN} --quiet -a ${OUTFILE}.raw --output-file ${OUTFILE}
--base-directory ${PROJECT_SOURCE_DIR} ${LCOV_EXTRA_FLAGS}
${BASE_DIRECTORY} ${LCOV_EXTRA_FLAGS}
COMMAND ${LCOV_BIN} --quiet -r ${OUTFILE} ${LCOV_REMOVE_PATTERNS}
--output-file ${OUTFILE} ${LCOV_EXTRA_FLAGS}
DEPENDS ${OUTFILE}.raw
Expand Down Expand Up @@ -169,7 +171,7 @@ function (lcov_capture_initial_tgt TNAME)
list(APPEND GENINFO_FILES ${OUTFILE})

add_custom_command(OUTPUT ${OUTFILE} COMMAND ${GCOV_ENV} ${GENINFO_BIN}
--quiet --base-directory ${PROJECT_SOURCE_DIR} --initial
--quiet ${BASE_DIRECTORY} --initial
--gcov-tool ${GCOV_BIN} --output-filename ${OUTFILE}
${GENINFO_EXTERN_FLAG} ${TDIR}/${FILE}.gcno
DEPENDS ${TNAME}
Expand Down Expand Up @@ -269,8 +271,8 @@ function (lcov_capture_tgt TNAME)

add_custom_command(OUTPUT ${OUTFILE}
COMMAND test -s "${TDIR}/${FILE}.gcda"
&& ${GCOV_ENV} ${GENINFO_BIN} --quiet --base-directory
${PROJECT_SOURCE_DIR} --gcov-tool ${GCOV_BIN}
&& ${GCOV_ENV} ${GENINFO_BIN} --quiet ${BASE_DIRECTORY}
--gcov-tool ${GCOV_BIN}
--output-filename ${OUTFILE} ${GENINFO_EXTERN_FLAG}
${TDIR}/${FILE}.gcda
|| cp ${OUTFILE}.init ${OUTFILE}
Expand Down
37 changes: 37 additions & 0 deletions run_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh

echo "\n\e[31;7mNinja + Gcov\e[0m"
mkdir build-ninja-gcov
cd build-ninja-gcov
cmake -Wno-dev -DENABLE_COVERAGE=ON -DCMAKE_BUILD_TYPE=Debug -G Ninja ..
ninja -v -j 1
ninja -v -j 1 test
ninja -v -j 1 gcov
cd -

echo "\n\e[31;7mNinja + Lcov\e[0m"
mkdir build-ninja-lcov
cd build-ninja-lcov
cmake -Wno-dev -DENABLE_COVERAGE=ON -DCMAKE_BUILD_TYPE=Debug -G Ninja ..
ninja -v -j 1
ninja -v -j 1 test
ninja -v -j 1 lcov
cd -

echo "\n\e[31;7mMake + Gcov\e[0m"
mkdir build-make-gcov
cd build-make-gcov
cmake -Wno-dev -DENABLE_COVERAGE=ON -DCMAKE_BUILD_TYPE=Debug -G "Unix Makefiles" ..
make
make test
make gcov
cd -

echo "\n\e[31;7mMake + Lcov\e[0m"
mkdir build-make-lcov
cd build-make-lcov
cmake -Wno-dev -DENABLE_COVERAGE=ON -DCMAKE_BUILD_TYPE=Debug -G "Unix Makefiles" ..
make
make test
make lcov
cd -
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@
add_subdirectory(libfoo)
add_subdirectory(bar)
add_subdirectory(libheader)
add_subdirectory(fortran)