bilke / cmake-modules

Additional CMake functionality. Most of the modules are from Ryan Pavlik (https://github.com/rpavlik/cmake-modules)
Boost Software License 1.0
542 stars 215 forks source link

CodeCoverage.cmake - difficulties using it to cover shared libraries rather than the main program #53

Open jmp75 opened 4 years ago

jmp75 commented 4 years ago

Using this version of CodeCoverage.cmake.

I wanted to use CodeCoverage.cmake to extract test coverage information in a context where I have a main test executable but want coverage for a shared library it links against.

The functions setup_target_for_coverage_gcovr_blah have an argument BASE_DIRECTORY but whether trying to use relative paths or absolute paths I just could not get it to work as expected. There is/was a bug such that only the main executable can end up in the code coverage report. Even with that fixed, base_directory appears to be relative the cmake build directory rather than the calling cmakelists.txt.

I've implemented something that works with BASE_DIRECTORY relative to the directory of the calling CMakeLists.txt file. The provisional changes are in this commit

I may submit a PR but I am not sure this is the intended behavior. Also it intersects with the pending pull request 51 related to issue #50 and will try to include these changes before a PR.

wuzhuobin commented 3 years ago

i encounter same problems the BASE_DIRECTORY is not working expectedly. I think the problem is the L212 the if(${Coverage_BASE_DIRECTORY}) should be changed to if(Coverage_BASE_DIRECTORY) Same as L310 and L382