Closed ahtsan closed 3 years ago
See this StackOverflow answer.
Thanks for the pointer, but I still can't get it working.
I modified add_custom_target
to something like
add_custom_target(${Coverage_NAME}
COMMAND ${LCOV_CLEAN_CMD}
COMMAND ${LCOV_BASELINE_CMD}
COMMAND ${CMAKE_COMMAND} -E env LD_LIBRARY_PATH=/some/path ${LCOV_EXEC_TESTS_CMD}
COMMAND ${LCOV_CAPTURE_CMD}
COMMAND ${LCOV_BASELINE_COUNT_CMD}
COMMAND ${LCOV_FILTER_CMD}
COMMAND ${LCOV_GEN_HTML_CMD}
and then I run make code_coverage
and got
Capturing coverage data from .
Found gcov version: 7.5.0
Scanning . for .gcno files ...
Found 1 graph files in .
Processing sim_runtime_gazebo9_plugin_UNIT_TEST.cc.gcno
Finished .info-file creation
/usr/bin/cmake -E env LD_LIBRARY_PATH=/some/path/ my_test
No such file or directory
where my_test
is the executable from my tests
In case someone also has this issue, I came up with a workaround.
The issue above is that CMake couldn't find my executable. According to the add_custom_target
documentation,
If neither of the above conditions are met, it is assumed that the command name is a program to be found on the PATH at build time.
so I add the path to the executable to the PATH
environment variable as well, like
add_custom_target(${Coverage_NAME}
COMMAND ${LCOV_CLEAN_CMD}
COMMAND ${LCOV_BASELINE_CMD}
COMMAND ${CMAKE_COMMAND} -E env LD_LIBRARY_PATH=/some/path PATH=/path/to/the/executable ${LCOV_EXEC_TESTS_CMD}
COMMAND ${LCOV_CAPTURE_CMD}
COMMAND ${LCOV_BASELINE_COUNT_CMD}
COMMAND ${LCOV_FILTER_CMD}
COMMAND ${LCOV_GEN_HTML_CMD}
In
add_custom_target
,${LCOV_EXEC_TESTS_CMD}
is resolved to the full path of the executable. However, when I changed the COMMAND to something likeThen
${LCOV_EXEC_TESTS_CMD}
does not get resolved to the full path.