# Default compile definition: how to get rid of those

**URL:** https://discourse.cmake.org/t/default-compile-definition-how-to-get-rid-of-those/3744
**Category:** Usage
**Tags:** gen:ninja
**Created:** [July 13, 2021, 3:03pm UTC](https://discourse.cmake.org/t/default-compile-definition-how-to-get-rid-of-those/3744 "2021-07-13T15:03:07Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![serge](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/5f8ce5/32.png) [@serge](https://discourse.cmake.org/u/serge)
#### Post date: [July 13, 2021, 3:03pm UTC](https://discourse.cmake.org/t/default-compile-definition-how-to-get-rid-of-those/3744/1 "2021-07-13T15:03:07Z")

</div>

Hello guys,

I am using cmake generator ninja to build my project.  
cmake / ninja adds a compile definition: -DNDEBUG automatically and it breaks the build.

What is the method to get rid of this default specifically and any in general?  
This happens also for compile options and linker options.  
what is the recommended way to stay in control of those?

Thanks,  
Serge

---

<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: [July 13, 2021, 3:15pm UTC](https://discourse.cmake.org/t/default-compile-definition-how-to-get-rid-of-those/3744/2 "2021-07-13T15:15:11Z")

</div>

Why does `-DNDEBUG` break your build? This is a standards-defined preprocessor symbol that changes the behavior of the `assert` macro. If you really want to remove it, you’ll have to `string(REPLACE)` on the `_FLAGS` variables.

---

<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: [July 13, 2021, 6:26pm UTC](https://discourse.cmake.org/t/default-compile-definition-how-to-get-rid-of-those/3744/3 "2021-07-13T18:26:19Z")

</div>

As Ben already said, this is a define from the C Standard which should not break your build.

But if your project was never built as a Release, only for Debugging purposes, then switching the `CMAKE_BUILD_TYPE` to `Debug` helps.

[https://cmake.org/cmake/help/latest/variable/CMAKE\_BUILD\_TYPE.html](https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html)

---

<div class="post-metadata">

### Author: ![serge](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/5f8ce5/32.png) [@serge](https://discourse.cmake.org/u/serge)
#### Post date: [July 14, 2021, 6:00am UTC](https://discourse.cmake.org/t/default-compile-definition-how-to-get-rid-of-those/3744/4 "2021-07-14T06:00:57Z")

</div>

Thanks Ben / Joseph,

I agree NDEBUG should not break the build but it does and the reason is quite complicated as we are replacing and rebuilding standard libraries taken from another package and this could be challenging of getting into the root cause of the build break.  
Can you elaborate a little bit about string(REPLACE) - do you mean resetting CMAKE\_\<CXX/C\>\_FLAGS\_RELEASE since I could not see that this affects the compile command and its -D options.

Thanks,  
Serge

---

<div class="post-metadata">

### Author: ![serge](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/5f8ce5/32.png) [@serge](https://discourse.cmake.org/u/serge)
#### Post date: [July 14, 2021, 6:44am UTC](https://discourse.cmake.org/t/default-compile-definition-how-to-get-rid-of-those/3744/5 "2021-07-14T06:44:13Z")

</div>

Taking back what I said above: setting CMAKE\_CXX\_FLAGS\_RELEASE to -O3 (instead of ‘-O3 -NDEBUG’ which was the default) solved the problem.  
I somehow last week tried to do something similar and it did not help.  
Probably a mixup.

Thanks for your help,  
Serge

---

<div class="post-metadata">

### Author: ![krischik](https://discourse.cmake.org/user_avatar/discourse.cmake.org/krischik/32/2842_2.png) [@krischik](https://discourse.cmake.org/u/krischik)
#### Post date: [October 17, 2022, 3:15pm UTC](https://discourse.cmake.org/t/default-compile-definition-how-to-get-rid-of-those/3744/6 "2022-10-17T15:15:47Z")

</div>

Excellent question. Tho answer the „should work“ statements: I for example don’t use GNU C so any gnu options are in the way. And yes I have one toolchain file. But the default compiler options are still there.

---

<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: [October 17, 2022, 8:40pm UTC](https://discourse.cmake.org/t/default-compile-definition-how-to-get-rid-of-those/3744/7 "2022-10-17T20:40:49Z")

</div>

Hello Martin,  
The defaults depend on the compiler/target environment detected. They differ e.g. for MSVC and GNUC and others.  
If you have a specific problem please create your own thread and explain your environment (which compiler, which target) and what specific problem you have.

---

<div class="post-metadata">

### Author: ![krischik](https://discourse.cmake.org/user_avatar/discourse.cmake.org/krischik/32/2842_2.png) [@krischik](https://discourse.cmake.org/u/krischik)
#### Post date: [October 18, 2022, 6:06am UTC](https://discourse.cmake.org/t/default-compile-definition-how-to-get-rid-of-those/3744/8 "2022-10-18T06:06:22Z")

</div>

Well, I have „my own thread“ over on StackOverflow:

> <https://stackoverflow.com/questions/74098302/how-to-remove-all-default-compiler-options-from-cmake>

It’s an unsupported compiler so I have to use a custom toolchain file. But despite having a toolchain file compiler options pop out of nowhere.

> The defaults depend on the compiler/target environment detected.

This is probably the problem. There is nothing useful to detect. CMake should just use what’s in the toolchain file.

I can copy paste the thread over here of you think that would be helpful.

---

<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: [October 19, 2022, 12:49am UTC](https://discourse.cmake.org/t/default-compile-definition-how-to-get-rid-of-those/3744/9 "2022-10-19T00:49:24Z")

</div>

I see at least two problems

- the toolchain file expects `cl65` as assembler, compiler and linker executable, you did use `as65` and `cc65`
- the command line arguments are specified as one single argument (e.g. by using a single string where a list was expected): the error message should only contain e.g. `-xc` and not the rest
- about `-xc`: I don’t think this was added by CMake, can’t find it in the source code.

Perhaps I should resurrect my old cc65 branch which I have lying around.

---

<div class="post-metadata">

### Author: ![krischik](https://discourse.cmake.org/user_avatar/discourse.cmake.org/krischik/32/2842_2.png) [@krischik](https://discourse.cmake.org/u/krischik)
#### Post date: [October 19, 2022, 5:55am UTC](https://discourse.cmake.org/t/default-compile-definition-how-to-get-rid-of-those/3744/10 "2022-10-19T05:55:17Z")

</div>

1. Good observation. That was an artefact from some experimenting I made. Reversed it and didn’t make a difference
2. Quick test. Correct. I thought that this was just a case of bad english.
3. Then it was most likely added by CLion.

Two and three suggest a problem in CLion. Let’s see:

```auto
cmake --toolchain Library/cc65-toolchain.cmake -S . -B cmake-build-release 
-- The ASM compiler identification is cc65
-- Found assembler: /opt/local/bin/cl65
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Warning: Did not find file Compiler/cc65-ASM
> CMAKE_ASM_COMPILER: /opt/local/bin/cl65
> CMAKE_C_COMPILER: /opt/local/bin/cl65
> CMAKE_AR: /opt/local/bin/ar65
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/Shared/Work/Projects/6502Tutorial/Atari/cmake-build-release

```

Of course I tried this before and it didn’t work. I guess there were multiple problems some of which I fixed and now all problems left are CLion. Which is annoying as I the only reason I do this is to have CLion support.

I’ll open a [forum post at JetBrains](https://intellij-support.jetbrains.com/hc/en-us/community/posts/8170260720402-Faulty-command-line-options-when-cross-compiling). Thanks for the help.
