# Problem with set(CMAKE\_COMPILE\_WARNING\_AS\_ERROR OFF)

**URL:** <https://discourse.cmake.org/t/problem-with-set-cmake-compile-warning-as-error-off/15338>\
**Category:** Code\
**Created:** [November 23, 2025, 8:50am UTC](https://discourse.cmake.org/t/problem-with-set-cmake-compile-warning-as-error-off/15338 "2025-11-23T08:50:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![perdrix](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/a8b319/32.png) [@perdrix](https://discourse.cmake.org/u/perdrix)\
**Post date:** [November 23, 2025, 8:50am UTC](https://discourse.cmake.org/t/problem-with-set-cmake-compile-warning-as-error-off/15338/1 "2025-11-23T08:50:53Z")

</div>

CMake version: 3.31.6-msvc6

My top level cmake file says: `set(CMAKE_COMPILE_WARNING_AS_ERROR ON)`  
and a lower level cmake file says: `set(CMAKE_COMPILE_WARNING_AS_ERROR OFF)`

But, when I try to build the project the lower level builds with the MSVC compiler option /WX which forces warnings to be errors which I don’t want to for that particular set of code.

What am I doing wrong please?

---

<div class="post-metadata">

**Author:** ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)\
**Post date:** [November 25, 2025, 9:51am UTC](https://discourse.cmake.org/t/problem-with-set-cmake-compile-warning-as-error-off/15338/2 "2025-11-25T09:51:40Z")

</div>

What applies is the value the variable has at the point a target is created. Are you setting it to `OFF` before creating the relevant target(s)?

---

<div class="post-metadata">

**Author:** ![perdrix](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/a8b319/32.png) [@perdrix](https://discourse.cmake.org/u/perdrix)\
**Post date:** [November 25, 2025, 10:17am UTC](https://discourse.cmake.org/t/problem-with-set-cmake-compile-warning-as-error-off/15338/3 "2025-11-25T10:17:03Z")

</div>

I was setting as the first line in the lower level CMake file. In the end I removed the `set (CMAKE_COMPILE_WARNING_AS_ERROR ON)`from the top level CMake file.

D.
