This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Disable optimization of part of the code through CMAKE

Hi,

A simple CMAKE question, somewhat regarding the zephyr build, but pretty essential for someone using JTAG to debug the application:

How does one disable optimization (-Os) for just a few files in the zephyr build?

I quicky tried a few things in the CMakeLists.txt:

- Adding a global target_compile_options(-O0) option => Builds the entire thing (incl zephyr) with O0, causing 200kB flash overflow

- Using target_compile_options(app PRIVATE -O0) => Leads to -O0 option, but this is overridden later in the compile line by -Os again, causing this to be negated

There must be a simple way to overrule Zephyr's overuling of the optimization compile option, and I am hoping somebody can quickly answer me on this.

Thanks!