Check during build process for specific board

Hello everybody,

I would like to have me code automatically check if the correct board has been selected for a build:

I know so far that the following is defined by the build process -DARDUINO_BOARD="FEATHER_ESP32"

However my checking code does not work as expected.

#ifndef ARDUINO_BOARD="FEATHER_ESP32"
#ERROR This is for the ESP32 Feather Platform
#endif

If have tried various combinations of ", ", ' ,,, Any suggestions?

Kind regards
Pete

The -D is defining a preprocessor variable to be a string constant. Maybe the compiler can use strcmp() of two string constants as a compile-time constant expression:

#if strcmp(ARDUINO_BOARD, "FEATHER_ESP32") != 0
  #ERROR This is for the ESP32 Feather Platform
#endif

If you want to specifically check whether Tools > Board > Adafruit ESP32 Feather is selected, I would recommend using the ARDUINO_FEATHER_ESP32 macro, which is specifically intended for this type of thing. That allows you to do something like this:

#ifndef ARDUINO_FEATHER_ESP32
  #ERROR This is for the ESP32 Feather Platform
#endif

Thanks guys.

The strcmp did not work out, but the hint with the ARDUINO_FEATHER_ESP32 was perfect. I missed that when browsing the compile options.

Works perfectly.

Kind regards
Pete