Zephyr extra build flags

Hi,

I am having major issues trying to do what I think is supposed to be simple.

I am trying to pass extra build files to the zephyr environment to be used in the project build script.

For instance, in zephyr it might be common to so something like

cmake -B build -GNinja -DBOARD=<board> -DBUILD_OPTION=ON

Or similarly using the west meta tool

west build -b <board> -- -DBUILD_OPTION=ON

And this would be available as expected in the project CMakeLists.txt.

I cannot figure out how to do this with PlatformIO.

I thought it should be as simple as:

[settings]
build_flags = -DBUILD_OPTION="OFF"

[env:nrf52840_dk]
platform = nordicnrf52
board = nrf52840_dk
framework = zephyr
build_flags = ${settings.build_flags}

but that is not working, it is invisible to the build script.

I went further and tried to get it added into the environment by using an extra_script and adding it to the global environment. This also did not work. I am very confused by this.

Those flags need to be added to Zephyr’s CMakeLists.txt.

It’s at <project root>/zephyr/CMakeLists.txt.

It needs to be done this way since Zephyr and PIO are separate build systems, and the handoff from PIO to Zephyr does not pass the build_flags defined in your platformio.ini.