Defines for env when editing

I am using vscode. I have two platforms define, one is an esp32 and the other is an emulator. I am using #defines to include or exclude certain code in my source depending on the platform.

I have two questions.
1st when editing how does the editor determine which path on an ifdef or ifndef to use? Is it based on the default env, the last build, what?

2nd are any -D automatically defined for a given platform. I know I can add -D in the build options for that env but I’m really asking if there are any defines that platformio does automatically.


Ok, Just dawned on me to do a verbose build and see what was being passed. So I answered my 2nd question. The only thing I see if -DPLATFORMIO=40304 which I assume is the verison of platformio.

1 Like

Hi! :slight_smile:

Seems to be based on the last build. Never checked to see if default_envs overrides this, but I suspect not, as it can specify more than one environment, so wouldn’t be very useful.

PlatformIO adds it’s own version number (as you noticed from the verbose build), plus any required defines such as ARDUINO_ARCH_AVR or ESP8266 and ARDUINO_ARCH_ESP8266 to properly mimic those cores, as well as the board name ARDUINO_ESP8266_WEMOS_D1MINI and any other configuration defines that are standard to that a given core/framework. No environment specific defines unfortunately AFAIK, so there’s no handy preexisting define you can use to detect which environment is being compiled. You add that yourself via the build_flags if you need it.

1 Like