# Fail cmake if there are unused variables defined

**URL:** https://discourse.cmake.org/t/fail-cmake-if-there-are-unused-variables-defined/840
**Category:** Usage
**Created:** [March 21, 2020, 4:54pm UTC](https://discourse.cmake.org/t/fail-cmake-if-there-are-unused-variables-defined/840 "2020-03-21T16:54:57Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![shukron](https://discourse.cmake.org/user_avatar/discourse.cmake.org/shukron/32/436_2.png) [@shukron](https://discourse.cmake.org/u/shukron)
#### Post date: [March 21, 2020, 4:54pm UTC](https://discourse.cmake.org/t/fail-cmake-if-there-are-unused-variables-defined/840/1 "2020-03-21T16:54:57Z")

</div>

Hi all!

I want make cmake fail if there are some unused variables defined.  
Currently I do get a warning, but I couldn’t find a way to cause cmake exit with non-zero return value.

For example, I want the following invocation to fail:

```auto
cmake -S . -B build -DSOME_UNUSED_VAR=ON

```

I tried with both `-Wdev -Werror=dev` but it did not help.

Any ideas?

---

<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: [March 21, 2020, 9:11pm UTC](https://discourse.cmake.org/t/fail-cmake-if-there-are-unused-variables-defined/840/2 "2020-03-21T21:11:29Z")

</div>

The `--warn-unused-*` flags predate the `-Wdev` mechanism. It could be converted over to be `-W` flags with `-Werror=` alternatives for consistency. I know I don’t have time to work on the change, but an issue and/or MR for it would be the place to start.

---

<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: [November 9, 2020, 8:32pm UTC](https://discourse.cmake.org/t/fail-cmake-if-there-are-unused-variables-defined/840/3 "2020-11-09T20:32:43Z")

</div>

I’ve filed [an issue](https://gitlab.kitware.com/cmake/cmake/-/issues/21412).
