Is there a way to detect target for use in #ifdef at compile time?

I’m building for the nanoatmega328 and megaatmega2560. While they share all the same libraries, the pinouts are different.

I could do the following:

[env:nanoatmega328]
build_flags = -D TARGET_NANO -D DEBUG_MODE=1 -D USE_NEOPIXEL_LEDS -D USE_U8GLIB_GRAPHICS -Wno-unknown-pragmas
[env:megaatmega2560]
build_flags = -D TARGET_MEGA -D DEBUG_MODE=1 -D USE_NEOPIXEL_LEDS -D USE_U8GLIB_GRAPHICS -Wno-unknown-pragmas

And then in code somewhere

#ifdef TARGET_NANO
    #define INT_PIN    2
#endif
#ifdef TARGET_MEGA
    #define INT_PIN    19
#endif

But wouldn’t it be cool if I could detect the build environment directly, e.g:

#ifdef nanoatmega328
    #define INT_PIN    2
#endif
#ifdef megaatmega2560
    #define INT_PIN    19
#endif

Can this be done? Does platformio generate target-specific defines (e.g. “env_nanoatmega328” that can be detected?

Thanks

Sure, just run in verbose mode via pio run --verbose and take a look at all macros. You will find specific macro per board.

For those following, I added --verbose to my platformio.ini env, e.g.:

[env:nanoatmega328]
build_flags = --verbose -D TARGET_NANO -D DEBUG_MODE=1
etc....

Lots of lines during build, but looking at the following:

COLLECT_GCC_OPTIONS=‘-o’ ‘.pioenvs/nanoatmega328/FrameworkArduino/Stream.o’
‘-c’ ‘-fno-exceptions’ ‘-fno-threadsafe-statics’ ‘-fpermissive’ ‘-std=gnu++11’ ‘-g’ ‘-Os’
‘-Wall’ ‘-ffunction-sections’ ‘-fdata-sections’ ‘-flto’ ‘-v’ ‘-Wno-unknown-pragmas’
‘-D’ ‘F_CPU=16000000L’ ‘-D’ ‘PLATFORMIO=30400’ ‘-D’ ‘ARDUINO_ARCH_AVR’
‘-D’ ‘ARDUINO_AVR_NANO’ ‘-D’ ‘TARGET_NANO’ ‘-D’ ‘DEBUG_MODE=1’ ‘-D’

So it looks like for the nanoatmega328 ARDUINO_AVR_NANO is being defined and for the atmega2560 ARDUINO_AVR_MEGA2560

Thanks!!!