I'm currently trying to use Gcov and Gcovr from CMake on Windows using MinGW. Compiling the files with the right flags works like a charm. However, CLion uses an out-of-source build which Gcov does not understand.
On Linux I used the following to copy all the *.gcda
and *.gcno
to the CMAKE_SOURCE_DIR
from CMAKE_BINARY_DIR
subfolders:
set(GCOV_DATA_DIR "${CMAKE_SOURCE_DIR}/gcov_data")
add_custom_target(prepare_coverage
# Copy necessary files to CMAKE_SOURCE_DIR
COMMAND ${CMAKE_COMMAND} -E make_directory ${GCOV_DATA_DIR}
COMMAND find ${CMAKE_BINARY_DIR} -name \"*.gcda\" -o -name \"*.gcno\" | xargs -l -i cp {} "${GCOV_DATA_DIR}"
)
Note that test binaries are executed in CMAKE_BINARY_DIR
.
This works pretty well and I can call Gcovr with some additional flags afterwards to get a nice report.
However, on Windows I do not have xargs
(I was already supprised that find
did work).
To make this CMake command platform-independent I'm looking for a way to make CMake find and copy/move the files during build time (similar to making the directory).
Can anyone tell me if this is possible and how I should do this? Of course I can always install additional programs or scripts, but I'd rather solve this within CMake instead of having to instruct all the developers to install different tools.
If you don't use CMAKE_RUNTIME_OUTPUT_PATH
in your project, then .gcda
and .gcno
files are created in the directory with executable, so you may compute this directory with $<TARGET_FILE_DIR:tgt>
generator-expression.
Because you know names of source files, you may compute absolute paths of all gcov-related files, and generate appropriate copiing commands without find
.
Another approach could be writting xargs-like program/script by yourself, shipping it with your project, and using it in COMMAND
. So
... but I'd rather solve this within CMake instead of having to instruct all the developers to install different tools.
wouldn't be a problem.