Defining preprocessor options using Visual Studio Code

I'm transitioning from SES to Visual Studio Code.

In SES, I can define multiple builds and then define preprocessor options (eg. -DOPTION1) for each build definition

I don't see a way to do this when using the nRF Connect SDK and Visual Studio Code.

(Note:  I know how to specify defines using the CMakeLists.txt file for all builds (using add_definitions(-DOPTION1) , but not on a "per-build" basis).

I'm using the NRF CONNECT extension in Visual Studio Code.

Thanks!

Parents
  • Hi

    Michal is on vacation, so I have taken over this case. We heard back from the developers today, and here's what they suggest:

    First off, the "Extra CMake arguments" are CMake arguments, not preprocessor arguments, so the correct form would be -DCMAKE_C_FLAGS="-DFOO=..." however this is only working until you try to edit to configuration again as this as of today cannot be parsed back from the cmake cache file. So the real solution is to only use -DFOO=... and edit the CMakeLists.txt file to alter CFLAGS depending on the value of FOO, e.g. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FOO}") or something similar along those lines.

    Best regards,

    Simon

  • Thank you.  Can I make a request that CMake present support find its way (back?) into the VS Code extension.  Would be very useful and make it feature equal to a lot of other solutions. :) Thanks again.

    Edit: Sorry cannot mark as solution but feel free to make above solution.

  • Hi Geoff, the feature request has been noted. Regarding your other question, is it the Save Configuration As Preset option you're missing? It is still an option on my end, so I'm not sure I understand what you mean about "what happened to it". Can you please specify.

    Best regards,

    Simon

  • Really? No I don't have it at all, would help greatly with this issue! My build menu looks like this and I have the latest extensions installed.  

Reply Children
No Data
Related