Debian Codegraph @

cmake/packages/FindGcov.cmake

raw
1 # Distributed under the original FontForge BSD 3-clause license
2
3 #[=======================================================================[.rst:
4 FindGcov
5 --------
6
7 Checks for gcov/code coverage support.
8
9 Imported Targets
10 ^^^^^^^^^^^^^^^^
11
12 This module defines the following :prop_tgt:`IMPORTED` target:
13
14 ``Gcov::Gcov``
15 An imported target that provides the required compiler flags
16 to generate code coverage data.
17
18 Result Variables
19 ^^^^^^^^^^^^^^^^
20
21 This module will set the following variables in your project:
22
23 ``Gcov_FOUND``
24 true if gcov appears to be functional
25
26 #]=======================================================================]
27
28 if(NOT CMAKE_CONFIGURATION_TYPES AND NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
29 message(WARNING "Set CMAKE_BUILD_TYPE to Debug for accurate code coverage results")
30 endif()
31
32 if(NOT DEFINED Gcov_FOUND)
33 include(CheckCSourceCompiles)
34 include(CMakePushCheckState)
35 cmake_push_check_state(RESET)
36
37 set(Gcov_COMPILE_DEFINITIONS "-g;-O0;-fprofile-arcs;-ftest-coverage" CACHE STRING "Gcov compiler flags")
38 set(Gcov_LIBRARIES "gcov" CACHE STRING "Gcov libraries")
39 set(CMAKE_REQUIRED_FLAGS ${Gcov_COMPILE_DEFINITIONS})
40 set(CMAKE_REQUIRED_LIBRARIES "${Gcov_LIBRARIES}")
41 check_c_source_compiles("int main() {return 0;}" Gcov_FOUND)
42 cmake_pop_check_state()
43 endif()
44
45 find_package_handle_standard_args(
46 Gcov
47 REQUIRED_VARS
48 Gcov_FOUND
49 Gcov_COMPILE_DEFINITIONS
50 Gcov_LIBRARIES
51 )
52
53 if(Gcov_FOUND AND NOT TARGET Gcov::Gcov)
54 add_library(Gcov::Gcov INTERFACE IMPORTED)
55 set_property(TARGET Gcov::Gcov PROPERTY INTERFACE_COMPILE_OPTIONS "${Gcov_COMPILE_DEFINITIONS}")
56 set_property(TARGET Gcov::Gcov PROPERTY INTERFACE_LINK_LIBRARIES "${Gcov_LIBRARIES}")
57 endif()