# How do I remove compile options from target

**URL:** https://discourse.cmake.org/t/how-do-i-remove-compile-options-from-target/5965
**Category:** Code
**Tags:** os:windows
**Created:** [June 29, 2022, 7:44pm UTC](https://discourse.cmake.org/t/how-do-i-remove-compile-options-from-target/5965 "2022-06-29T19:44:28Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![jshanab](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jshanab/32/2555_2.png) [@jshanab](https://discourse.cmake.org/u/jshanab)
#### Post date: [June 29, 2022, 7:44pm UTC](https://discourse.cmake.org/t/how-do-i-remove-compile-options-from-target/5965/1 "2022-06-29T19:44:28Z")

</div>

I need to send a build to a code verification service and they require it be built with certain flags.  
I am able to get most with target\_compile\_options but I cannot set it to “Default” like we do in the IDE which has the effect of removing “/RTC1”

How do I REMOVE options?

Is there a class like Public Private Interface Unset or a target\_remove\_compiler\_options.

---

<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: [June 29, 2022, 8:38pm UTC](https://discourse.cmake.org/t/how-do-i-remove-compile-options-from-target/5965/2 "2022-06-29T20:38:42Z")

</div>

Usually you don’t remove them; you should instead not set them in the first place. However, you can go in and work with the backing properties directly (should be `COMPILE_OPTIONS`).

---

<div class="post-metadata">

### Author: ![jshanab](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jshanab/32/2555_2.png) [@jshanab](https://discourse.cmake.org/u/jshanab)
#### Post date: [June 29, 2022, 8:43pm UTC](https://discourse.cmake.org/t/how-do-i-remove-compile-options-from-target/5965/3 "2022-06-29T20:43:24Z")

</div>

I did not set them. CMake must set them as default from their project template.  
To verify I completely removed the build folder after I changed the optimization.  
People have asked for this for years, I see  
I can set it to the values, just not none which would be same as setting to Default in IDE.

---

<div class="post-metadata">

### Author: ![jshanab](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jshanab/32/2555_2.png) [@jshanab](https://discourse.cmake.org/u/jshanab)
#### Post date: [June 29, 2022, 8:58pm UTC](https://discourse.cmake.org/t/how-do-i-remove-compile-options-from-target/5965/4 "2022-06-29T20:58:27Z")

</div>

So hard to sell management on CMake with Roadblocks like this.

To my surprise, COMPILE\_OPTIONS Is empty before and after I try setting. I think it is applied later.

---

<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: [June 30, 2022, 11:58am UTC](https://discourse.cmake.org/t/how-do-i-remove-compile-options-from-target/5965/5 "2022-06-30T11:58:55Z")

</div>

> [@jshanab](#):
>
> CMake must set them as default from their project template.

Oh, the flags? `string(REPLACE)` on `CMAKE_<LANG>_FLAGS_<CONFIG>` and friends is the way to go there. CMake doesn’t have an abstraction for all of the flags (yet?), and doing anything about these flags requires a policy to change at this point, so it is slow going.

---

<div class="post-metadata">

### Author: ![jtxa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jtxa/32/1535_2.png) [@jtxa](https://discourse.cmake.org/u/jtxa)
#### Post date: [June 30, 2022, 9:58pm UTC](https://discourse.cmake.org/t/how-do-i-remove-compile-options-from-target/5965/6 "2022-06-30T21:58:56Z")

</div>

`/RTC1` is just set for the `DEBUG` configuration, so the easiest way could be to build a `RELEASE` instead.  
Do you need an near production or non-optimized build for that service?

---

<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: [July 2, 2022, 9:50pm UTC](https://discourse.cmake.org/t/how-do-i-remove-compile-options-from-target/5965/7 "2022-07-02T21:50:32Z")

</div>

> [@jtxa](#):
>
> `/RTC1` is just set for the `DEBUG` configuration, so the easiest way could be to build a `RELEASE` instead.  
> Do you need an near production or non-optimized build for that service?

Perhaps this relates to this unresolved bug with [RTC1](https://developercommunity2.visualstudio.com/t/Broken-runtime-checks-with-CL-19293013/1503629)? Our company had to remove the RTC1 flag from our debug builds as a result.

> [@jshanab](#):
>
> To my surprise, COMPILE\_OPTIONS Is empty before and after I try setting. I think it is applied later.

RTC1 is being applied to your project via [CMAKE\_LANG\_FLAGS\_DEBUG](https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_FLAGS_DEBUG.html?highlight=cmake_%20lang%20_flags_debug). You will want to modify the variable for both C/C++ most likely.

You can modify the variable from the command line or via your CMake code. Whatever makes sense in your scenario.
