# How to use target\_compile\_options only for Debug build?

**URL:** https://discourse.cmake.org/t/how-to-use-target-compile-options-only-for-debug-build/2388
**Category:** Usage
**Created:** [December 17, 2020, 12:12pm UTC](https://discourse.cmake.org/t/how-to-use-target-compile-options-only-for-debug-build/2388 "2020-12-17T12:12:49Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![DavidA](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davida/32/128_2.png) [@DavidA](https://discourse.cmake.org/u/DavidA)
#### Post date: [December 17, 2020, 12:12pm UTC](https://discourse.cmake.org/t/how-to-use-target-compile-options-only-for-debug-build/2388/1 "2020-12-17T12:12:50Z")

</div>

I want to add gcc compiler option -Og for Debug builds only.

I have tried:

```
add_compile_options("$<$<CONFIG:DEBUG>:-Og>")

```

but that does not seem to work.

I believe target\_compile\_options is preferred. How would I use that to only affect debug builds?

---

<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: [December 17, 2020, 12:14pm UTC](https://discourse.cmake.org/t/how-to-use-target-compile-options-only-for-debug-build/2388/2 "2020-12-17T12:14:50Z")

</div>

Normally, the configuration name is `Debug`, not `DEBUG`, so you probably want this:

```
add_compile_options("$<$<CONFIG:Debug>:-Og>")
```

---

<div class="post-metadata">

### Author: ![DavidA](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davida/32/128_2.png) [@DavidA](https://discourse.cmake.org/u/DavidA)
#### Post date: [December 17, 2020, 1:05pm UTC](https://discourse.cmake.org/t/how-to-use-target-compile-options-only-for-debug-build/2388/3 "2020-12-17T13:05:45Z")

</div>

Thank you

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [December 17, 2020, 3:44pm UTC](https://discourse.cmake.org/t/how-to-use-target-compile-options-only-for-debug-build/2388/4 "2020-12-17T15:44:35Z")

</div>

That contradicts the documentation that explicitly states that this comparison is case-insensitive!

---

<div class="post-metadata">

### Author: ![DavidA](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davida/32/128_2.png) [@DavidA](https://discourse.cmake.org/u/DavidA)
#### Post date: [December 17, 2020, 3:53pm UTC](https://discourse.cmake.org/t/how-to-use-target-compile-options-only-for-debug-build/2388/5 "2020-12-17T15:53:31Z")

</div>

Then I think I must have made some other error. Anyway, it’s working now. Thank you both for your comments. There seem to be several ways of doing some things in CMake and it’s not always easy to know which to use.
