# How to fix build warning D9025 (Overriding /GR with /GR-)

**URL:** https://discourse.cmake.org/t/how-to-fix-build-warning-d9025-overriding-gr-with-gr/878
**Category:** Usage
**Tags:** comp:msvc, os:windows, gen:ninja
**Created:** [March 28, 2020, 12:06am UTC](https://discourse.cmake.org/t/how-to-fix-build-warning-d9025-overriding-gr-with-gr/878 "2020-03-28T00:06:36Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ymba9g8j9cjp0wloqf5y/32/1244_2.png) [@YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/u/YMba9g8j9CJp0wLoQf5y)
#### Post date: [March 28, 2020, 12:06am UTC](https://discourse.cmake.org/t/how-to-fix-build-warning-d9025-overriding-gr-with-gr/878/1 "2020-03-28T00:06:36Z")

</div>

My project needs to disable RTTI however I’m getting this build warning.  
This is all I’m doing.

```auto
target_compile_optons(foo_target PRIVATE /GR-)

```

---

<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 28, 2020, 12:43pm UTC](https://discourse.cmake.org/t/how-to-fix-build-warning-d9025-overriding-gr-with-gr/878/2 "2020-03-28T12:43:55Z")

</div>

It looks like CMake passes `/GR` by default for MSVC. You’ll have to remove it from `CMAKE_CXX_FLAGS`.

---

<div class="post-metadata">

### Author: ![anon45792294](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@anon45792294](https://discourse.cmake.org/u/anon45792294)
#### Post date: [March 28, 2020, 8:46pm UTC](https://discourse.cmake.org/t/how-to-fix-build-warning-d9025-overriding-gr-with-gr/878/3 "2020-03-28T20:46:36Z")

</div>

Won’t that effect projects called by add\_subdirectory relying on RTTI @ben.boeckel?

---

<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 29, 2020, 4:56pm UTC](https://discourse.cmake.org/t/how-to-fix-build-warning-d9025-overriding-gr-with-gr/878/4 "2020-03-29T16:56:29Z")

</div>

`CMAKE_CXX_FLAGS` applies to all targets; you’ll have to add it back for RTTI-using targets if you want to remove it for any of them. Fixing this would need RTTI to become a target property like the MSVC stdlib selection did recently.

---

<div class="post-metadata">

### Author: ![anon45792294](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@anon45792294](https://discourse.cmake.org/u/anon45792294)
#### Post date: [March 29, 2020, 8:04pm UTC](https://discourse.cmake.org/t/how-to-fix-build-warning-d9025-overriding-gr-with-gr/878/5 "2020-03-29T20:04:15Z")

</div>

“you’ll have to add it back for RRTI-using targets”

How do you mean? I’m confused about the execution.

Also making RTTI a target property sounds like a good idea.

---

<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 30, 2020, 11:28am UTC](https://discourse.cmake.org/t/how-to-fix-build-warning-d9025-overriding-gr-with-gr/878/6 "2020-03-30T11:28:36Z")

</div>

> [@anon45792294](#):
>
> How do you mean?

Once it is out of the `CMAKE_CXX_FLAGS`, you’ll have to add either `/GR` or `/GR-` to every target (I don’t know what the default behavior is; you may be able to elide that flag setting).

---

<div class="post-metadata">

### Author: ![YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ymba9g8j9cjp0wloqf5y/32/1244_2.png) [@YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/u/YMba9g8j9CJp0wLoQf5y)
#### Post date: [April 2, 2020, 7:14pm UTC](https://discourse.cmake.org/t/how-to-fix-build-warning-d9025-overriding-gr-with-gr/878/7 "2020-04-02T19:14:23Z")

</div>

In case anyone is curious this is what I ended up doing to get rid of this warning:

In ended up doing this string replacement in my top level CMakeLists.txt

As Ben said I was able to elide that flag setting.

I would still prefer RTTI to be a property, but this will do for now.

```auto
string(REPLACE "/GR" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
```

---

<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: [March 13, 2023, 9:22pm UTC](https://discourse.cmake.org/t/how-to-fix-build-warning-d9025-overriding-gr-with-gr/878/8 "2023-03-13T21:22:29Z")

</div>

FWIW this issue has been fixed with newer CMake versions via CMP0117:  
[https://cmake.org/cmake/help/latest/policy/CMP0117.html](https://cmake.org/cmake/help/latest/policy/CMP0117.html)
