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

CodeCoverage: clang requires llvm-cov #40

Open
CJxD opened this issue Dec 10, 2019 · 1 comment
Open

CodeCoverage: clang requires llvm-cov #40

CJxD opened this issue Dec 10, 2019 · 1 comment

Comments

@CJxD
Copy link

CJxD commented Dec 10, 2019

When using gcov with a project built using Clang, gcov is unable to parse the .gcno files, giving the error: version '402*', prefer 'A92*'.

This seems to be because llvm-cov is required. I've hacked around this myself by doing the following before including CodeCoverage.cmake:

if("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
	find_program(LLVMCOV_PATH llvm-cov)
	if(LLVMCOV_PATH)
		set(GCOV_PATH "${CMAKE_CURRENT_SOURCE_DIR}/llvm-cov.sh")
	endif()
endif()
include(CodeCoverage.cmake)

where llvm-cov.sh is the following (marked with executable permissions):

#!/bin/bash
exec llvm-cov gcov "$@"

Could this be added in with a somewhat less hacky workaround?

@gollth
Copy link

gollth commented May 10, 2022

When you want to use the gcovr_* targets, another way could be to use the --gcov-executable option of gcovr:

include(CodeCoverage)

if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
  set(GCOVR_ADDITIONAL_ARGS --gcov-executable "llvm-cov gcov")
endif()

append_coverage_compiler_flags()

setup_target_for_coverage_gcovr_html(
  NAME       coverage-html
  EXECUTABLE ctest
)

Looking at its help it seems you could also set the GCOV environment variable instead:

$ gcovr --help
GCOV Options:
  The 'gcov' tool turns raw coverage files (.gcda and .gcno) into .gcov
  files that are then processed by gcovr. The gcno files are generated by
  the compiler. The gcda files are generated when the instrumented program
  is executed.

  --gcov-executable GCOV_CMD
                        Use a particular gcov executable. Must match the
                        compiler you are using, e.g. 'llvm-cov gcov' for
                        Clang. Can include additional arguments. Defaults to
                        the GCOV environment variable, or 'gcov': 'gcov'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants