# Cmake warnings as error

**URL:** https://discourse.cmake.org/t/cmake-warnings-as-error/3960
**Category:** Usage
**Created:** [August 20, 2021, 6:54am UTC](https://discourse.cmake.org/t/cmake-warnings-as-error/3960 "2021-08-20T06:54:04Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![chrilleman](https://discourse.cmake.org/user_avatar/discourse.cmake.org/chrilleman/32/2042_2.png) [@chrilleman](https://discourse.cmake.org/u/chrilleman)
#### Post date: [August 20, 2021, 6:54am UTC](https://discourse.cmake.org/t/cmake-warnings-as-error/3960/1 "2021-08-20T06:54:04Z")

</div>

I am trying to stop cmake from continuing generation if it outputs a warning, i.e. treat all warnings as errors and stop.  
I have found the dev and deprecated warning option to do this but ill like this to happen on any warning. e.g. i have sometimes unused variables/options which outputs a cmake warning, to prevent anyone from passing unused variables to the generation i like to enable such an option.

Anyone know how to do this?

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [August 20, 2021, 4:40pm UTC](https://discourse.cmake.org/t/cmake-warnings-as-error/3960/2 "2021-08-20T16:40:08Z")

</div>

Perhaps you want [CMAKE\_ERROR\_DEPRECATED](https://cmake.org/cmake/help/latest/variable/CMAKE_ERROR_DEPRECATED.html?highlight=cmake_error_deprecated)?

```auto
cmake ... -D CMAKE_ERROR_DEPRECATED=ON

```

---

<div class="post-metadata">

### Author: ![chrilleman](https://discourse.cmake.org/user_avatar/discourse.cmake.org/chrilleman/32/2042_2.png) [@chrilleman](https://discourse.cmake.org/u/chrilleman)
#### Post date: [August 23, 2021, 7:44am UTC](https://discourse.cmake.org/t/cmake-warnings-as-error/3960/3 "2021-08-23T07:44:59Z")

</div>

I am looking for a more general option, something like: CMAKE\_WARN\_AS\_ERROR. the deprecated error/warning only stops on that type. Sometimes you pass an unused variable to cmake and that would output a warning which i like to prevent. if you do:

cmake -DMY\_UNUSED\_VAR=true

it will output

“CMake Warning: Manually-specified variables were not used by the project: MY\_UNUSED\_VAR”

I would like to make that warning an error, any any other CMake Warning.

---

<div class="post-metadata">

### Author: ![EwingKang](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ewingkang/32/2730_2.png) [@EwingKang](https://discourse.cmake.org/u/EwingKang)
#### Post date: [September 1, 2022, 3:27am UTC](https://discourse.cmake.org/t/cmake-warnings-as-error/3960/4 "2022-09-01T03:27:50Z")

</div>

Just registered to this forum for this topic.  
I have exactly the same needs as @chrilleman . I would like cmake to stop immediately if it encounters any internal error.  
This is to prevent erroneous user parameter settings. Our current project has ~20 sub-directires and we have to manage ~40 custom options. Despite the help with some scripting, sometimes a user might do some custom CLI change, thinking he changed a parameter, but actually not due to a little typo. This has happened for more than 3 time for our team. It would be very helpful if I can set the CMakeLists.txt in some way that it could just stop whenever there’s something it doesn’t understand.

---

<div class="post-metadata">

### Author: ![Jan\_Erik\_Knoblauch](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jan_erik_knoblauch/32/3947_2.png) [@Jan\_Erik\_Knoblauch](https://discourse.cmake.org/u/Jan_Erik_Knoblauch)
#### Post date: [December 12, 2023, 1:15pm UTC](https://discourse.cmake.org/t/cmake-warnings-as-error/3960/5 "2023-12-12T13:15:25Z")

</div>

We have also had cases where with circular dependencies with the same files listed as both output and input to a custom command. This gave a warning and unwanted build result. In this case it would have been nice if CMake could stop and not let this pass “unnoticed”…
