0

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.

Antonio
  • 19,451
  • 13
  • 99
  • 197
Arno Moonen
  • 1,134
  • 2
  • 10
  • 28
  • Regarding `find` and `cmake`, please take a look [here](http://stackoverflow.com/a/34995590/2436175). The fact that you can use `find` like that make me think that you have something like [msys](http://www.mingw.org/wiki/msys) installed. – Antonio May 26 '16 at 12:22
  • As I mentioned I'm using MinGW. I also have the MSYS packages installed. – Arno Moonen May 26 '16 at 13:04
  • As you can see in my comment on the accepted answer, I have a solution that involves standard Windows tools now. – Arno Moonen May 27 '16 at 07:12
  • The question is already answered. "Shipping it with your project" is the solution I used. – Arno Moonen May 27 '16 at 07:53
  • Maybe the problem can be addressed in a cleaner way. There is a [guide on cmake website](https://cmake.org/Wiki/CTest:Coverage), and also this [very similar question](http://stackoverflow.com/questions/13116488/detailed-guide-on-using-gcov-with-cmake-cdash). – Antonio May 27 '16 at 12:23

1 Answers1

0

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.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
  • Ended up using a batch file and a bash file (selected based on the host OS) that is called during the build. In batch it's not too hard too accomplish the behavior I wanted and the bash file basically contains what I mentioned in my question. – Arno Moonen May 26 '16 at 12:00