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 Reply Children
  • Hi Geoff

    I have contacted the developers to see if they have an idea why you can't see this. We seem to have mostly the same extensions enabled as well. In addition to the ones you listed I have the C/C++ Extension pack and Themes as well as GNU Linker Map files extension, but AFAIK neither of these provide this "save config as preset" option.

    I'll let you know when I hear back from our devs on this. Thank you for your patience! In the meantime you can check out the documentation on saving configs as a preset available here: https://nrfconnect.github.io/vscode-nrf-connect/guides/build_config.html#how-to-save-a-build-configuration-as-a-preset Maybe you're able to run it from the VS code command line instead.

    Best regards,

    Simon

  • Thanks Simon.  I have looked at that page before, thought I was going crazy trying to find that option! Looks like it is exactly what I want though.  Makes a nice JSON file I can put into the repo for future devs to recreate the build env.  I also have those same extensions, full listing below.

  • Hi

    I just got word from one of the developers that the Save Configuration As Preset action is not available on sysbuild and TFM builds, which is likely the difference between mine and your projects.

    Best regards,

    Simon

  • Thanks Simon.  Not a sysbuild and also not a board with _ns base - thats TFM isnt it?  It is a nRF5340 project and it does use a custom board but it is based on your nrf5340dk_nrf5340_cpuapp with just devicetree changes. 

    HOWEVER, I just loaded an old project (one of your examples) from many months ago that was last built using a different version of the extensions and SDK and I CAN see the Save Configuration option!  But the extension was asking to pristine build as it is stale and after that the option is gone, no other changes.  Is it possible my IDE/projects have some kind of stale setting in it? My setup has been through several SDK and extenstion updates by this point (currently on SDK 2.4.1).

    To confirm I just made a brand new project+build (non _ns and non sysbuild) using one of your examples against nrf5340dk_nrf5340_cpuapp and no Save Configuratiton option, so don't think it is as simple as not working with sysbuild and TFM.

  • Hi Geoff

    That sounds strange indeed. Just to make sure, your projects don't have this config (or any of its dependencies) enabled by chance, do they? CONFIG_BUILD_WITH_TFM, as TFM is indeed non-secure samples, but are not limited to just those.

    It could also be something with your Visual Studio Code or SDK setup. If so I'd recommend trying to uninstall the extensions, VS Code, and remove the SDK from the toolchain manager before reinstalling to see if that helps. Alternatively if you have another computer you can install a fresh SDK and VSCode instance and see if you have the same issue with your project(s) there.

    Best regards,

    Simon

Related