How change #define device platform

Hello! I’m developing a program for ESP32. I use an external library in which there is a check of the following definitions:

#if defined(ESP8266) || defined(ESP32)
#define
#define
#elif defined(STM32_DEVICE)
#define
#elif defined(SIM800)
#else
#define
Question: where in the Platformio settings is #define ESP32 and how can I change this definition to its own value, for example SIM800

The particular ESP32 define is added in the python script controlling the build process for the espressif32 platform:

    CPPDEFINES=[
        "ESP32", "ESP_PLATFORM", ("F_CPU", "$BOARD_F_CPU"), "HAVE_CONFIG_H",
        ("MBEDTLS_CONFIG_FILE", '\\"mbedtls/esp_config.h\\"')
],

See platform-espressif32/main.py at develop · platformio/platform-espressif32 · GitHub. This is done for all devices on the ESP32 platform.

Then, each device is again described by a board JSON file in which additional defines can be added. E.g., the esp32dev.json:

  "build": {
    "core": "esp32",
    "extra_flags": "-DARDUINO_ESP32_DEV",
...

See platform-espressif32/esp32dev.json at develop · platformio/platform-espressif32 · GitHub.

I think what you want is to add a specific #define in a build environment in your platformio.ino file. You can do that by utilizing the build_flags section (docs), e.g. by having a platformio.ini like:

; build environment settings for a nodemcu board
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
; additional compiler flags. define the SIM800 macro for this type of build
build_flags =
	-D SIM800
; other flags..

My platformio.ini:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
build_flags = -D SIM800

I added the flag build_flags = -D SIM800
However, the program is compiled for ESP32, this I see when debugging

Yes, the firmware is compiled for an ESP32 because that’s the board and platform you’ve given it? The build_flags just defines the macro SIM800. And that doesn’t work? Try adding a piece of code like

#ifdef SIM800
#error "SIM800 was defined"
#else
#error "SIM800 was NOT defined"
#endif

The compilation should fail giving you telling you in the “error” message whether it was defined or not.

Yes, in this case the compilation happens with an error:

src\main.h:5:2: error: #error “SIM800 was defined”
#error “SIM800 was defined”
^
*** [.pioenvs\esp32dev\src\main.cpp.o] Error 1
[ERROR] Took 10.94 seconds

Good, that means that the macro definition works as intended. But you’re still having problems beyond that?

Understood! My mistake. It was really necessary to register build_flags = -D SIM800.
Thank you so much!