2021-08-31 12:20:16 -07:00
# if coverage reports are not enabled, skip all of this
if ( NOT LLVM_BUILD_INSTRUMENTED_COVERAGE )
return ( )
endif ( )
file ( TO_NATIVE_PATH
" $ { L L V M _ S O U R C E _ D I R } / u t i l s / p r e p a r e - c o d e - c o v e r a g e - a r t i f a c t . p y "
P R E P A R E _ C O D E _ C O V _ A R T I F A C T )
# llvm-cov and llvm-profdata need to match the host compiler. They can either be
# explicitly provided by the user, or we will look them up based on the install
# location of the C++ compiler.
get_filename_component ( COMPILER_DIRECTORY ${ CMAKE_CXX_COMPILER } DIRECTORY )
find_program ( LLVM_COV "llvm-cov" ${ COMPILER_DIRECTORY } NO_DEFAULT_PATH )
find_program ( LLVM_PROFDATA "llvm-profdata" ${ COMPILER_DIRECTORY } NO_DEFAULT_PATH )
if ( NOT LLVM_COV OR NOT LLVM_PROFDATA )
message ( WARNING "Could not find code coverage tools, skipping generating targets. You may explicitly specify LLVM_COV and LLVM_PROFDATA to work around this warning." )
return ( )
endif ( )
set ( LLVM_CODE_COVERAGE_TARGETS "" CACHE STRING "Targets to run code coverage on (defaults to all exported targets if empty)" )
mark_as_advanced ( LLVM_CODE_COVERAGE_TARGETS )
if ( NOT LLVM_CODE_COVERAGE_TARGETS )
# by default run the coverage report across all the exports provided
get_property ( COV_TARGETS GLOBAL PROPERTY LLVM_EXPORTS )
endif ( )
file ( TO_NATIVE_PATH
" $ { C M A K E _ B I N A R Y _ D I R } / r e p o r t / "
R E P O R T _ D I R )
foreach ( target ${ LLVM_CODE_COVERAGE_TARGETS } ${ COV_TARGETS } )
get_target_property ( target_type ${ target } TYPE )
if ( "${target_type}" STREQUAL "SHARED_LIBRARY" OR "${target_type}" STREQUAL "EXECUTABLE" )
list ( APPEND coverage_binaries $< TARGET_FILE:${target} > )
endif ( )
endforeach ( )
set ( LLVM_COVERAGE_SOURCE_DIRS "" CACHE STRING "Source directories to restrict coverage reports to." )
mark_as_advanced ( LLVM_COVERAGE_SOURCE_DIRS )
foreach ( dir ${ LLVM_COVERAGE_SOURCE_DIRS } )
list ( APPEND restrict_flags -restrict ${ dir } )
endforeach ( )
# Utility target to clear out profile data.
2022-11-14 10:28:36 -06:00
# This isn't connected to any dependencies because it is a bit finicky to get
2021-08-31 12:20:16 -07:00
# working exactly how a user might want.
add_custom_target ( clear-profile-data
C O M M A N D $ { C M A K E _ C O M M A N D } - E
r e m o v e _ d i r e c t o r y $ { L L V M _ P R O F I L E _ D A T A _ D I R } )
# This currently only works for LLVM, but could be expanded to work for all
# sub-projects. The current limitation is based on not having a good way to
# automaticall plumb through the targets that we want to run coverage against.
add_custom_target ( generate-coverage-report
C O M M A N D $ { P y t h o n 3 _ E X E C U T A B L E } $ { P R E P A R E _ C O D E _ C O V _ A R T I F A C T }
$ { L L V M _ P R O F D A T A } $ { L L V M _ C O V } $ { L L V M _ P R O F I L E _ D A T A _ D I R }
$ { R E P O R T _ D I R } $ { c o v e r a g e _ b i n a r i e s }
- - u n i f i e d - r e p o r t $ { r e s t r i c t _ f l a g s }
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ B I N A R Y _ D I R }
D E P E N D S c h e c k - l l v m ) # Run tests