How to use target_compile_options only for Debug build?

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

I have tried:


but that does not seem to work.

I believe target_compile_options is preferred. How would I use that to only affect debug builds?

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


Thank you

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

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.