# Coverage tool for cmake

**URL:** https://discourse.cmake.org/t/coverage-tool-for-cmake/10643
**Category:** Usage
**Tags:** tool:cmake
**Created:** [April 12, 2024, 4:27am UTC](https://discourse.cmake.org/t/coverage-tool-for-cmake/10643 "2024-04-12T04:27:22Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![pkiran](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/dc4da7/32.png) [@pkiran](https://discourse.cmake.org/u/pkiran)
#### Post date: [April 12, 2024, 4:27am UTC](https://discourse.cmake.org/t/coverage-tool-for-cmake/10643/1 "2024-04-12T04:27:23Z")

</div>

Hello,

We have a lot of lines of code in cmake, maintained by multiple teams. I was wondering if there is some kind of a coverage tool for cmake itself, which helps to identify dead code.

Thanks

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [April 12, 2024, 9:41am UTC](https://discourse.cmake.org/t/coverage-tool-for-cmake/10643/2 "2024-04-12T09:41:25Z")

</div>

IMHO: this is not realy needed.

`pip install gcovr`

see for config file example [gcovr.cfg](https://github.com/cpp-best-practices/cmake_template/blob/main/gcovr.cfg)

---

<div class="post-metadata">

### Author: ![pkiran](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/dc4da7/32.png) [@pkiran](https://discourse.cmake.org/u/pkiran)
#### Post date: [April 12, 2024, 9:47am UTC](https://discourse.cmake.org/t/coverage-tool-for-cmake/10643/3 "2024-04-12T09:47:38Z")

</div>

Thanks for the reply.

I was just wondering if there are tools to identify dead cmake code and prevents code rot. I think it will be useful in some cases.

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [April 13, 2024, 9:52am UTC](https://discourse.cmake.org/t/coverage-tool-for-cmake/10643/4 "2024-04-13T09:52:19Z")

</div>

> **[GitHub - StableCoder/cmake-scripts: Easy-to-add enhancements for any C/C++...](https://github.com/StableCoder/cmake-scripts)**
>
> Easy-to-add enhancements for any C/C++ CMake project. Including AFL fuzzing, code-coverage, Thread/Address/Leak/Address/Undefined sanitizer instrumentation, compilation of GLSL shaders and more. -...

---

<div class="post-metadata">

### Author: ![pkiran](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/dc4da7/32.png) [@pkiran](https://discourse.cmake.org/u/pkiran)
#### Post date: [April 13, 2024, 3:17pm UTC](https://discourse.cmake.org/t/coverage-tool-for-cmake/10643/5 "2024-04-13T15:17:49Z")

</div>

Thanks for the link, it’s useful.

Maybe I was not being clear enough, just like there is gcov for C/C++, coverage.py for python, jacoco for java, I was wondering if there is such a tool for cmake language.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [April 17, 2024, 7:17pm UTC](https://discourse.cmake.org/t/coverage-tool-for-cmake/10643/6 "2024-04-17T19:17:06Z")

</div>

> [@pkiran](#):
>
> I was wondering if there is some kind of a coverage tool for cmake itself, which helps to identify dead code.

There isn’t. I suppose one could be built out of `--trace` or `--trace-expand` output though. However, results over all configurations of interest would really be needed to avoid removing Windows support code because only coverage from Linux is considered.

---

<div class="post-metadata">

### Author: ![pkiran](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/dc4da7/32.png) [@pkiran](https://discourse.cmake.org/u/pkiran)
#### Post date: [May 17, 2024, 1:47pm UTC](https://discourse.cmake.org/t/coverage-tool-for-cmake/10643/7 "2024-05-17T13:47:43Z")

</div>

thanks for the response, even just for linux, it could be useful. Just an idea.
