Skip to content

Invalid macro name if Arduino is used as a component in esp-idf and the board name contains a dash #7499

Closed
@supcik

Description

@supcik

Board

ttgo-lora32-v1 (and on all boards with a dash in the name)

Device Description

Plain module. This issue is not related to a specific device.

Hardware Configuration

This issue is not related to a specific configuration

Version

latest master (checkout manually)

IDE Name

VS Code

Operating System

macOS 13.0.1

Flash frequency

40 Mhz

PSRAM enabled

no

Upload speed

115200

Description

This problem occurs when arduino-esp32 is used as a component in esp-idf (as described here) and when the name of the board (the "variant") contains a dash (for example ttgo-lora32-v1).

In this case, the CMakeList.txt of arduino-esp32 defines the symbol ARDUINO_${idf_target_caps}_DEV where idf_target_caps is the capitalized board name (or the variant).

When the board name contains a dash (-), the symbol is not valid and the compiler issues plenty of warnings :

<command-line>: warning: ISO C++11 requires whitespace after the macro name

If, inside the C++ code, you want to use conditional compilation, such as :

#ifdef ARDUINO_TTGO-LORA32-V1_DEV
...
#endif

the code still compiles, but it seems to ignore everything starting from the first dash. So it is not possible to distinguish ARDUINO_TTGO-LORA32-V1_DEV from ARDUINO_TTGO-LORA32-V2_DEV. Note that the compiler also issues a warning:

main/main.cpp:3:20: warning: extra tokens at end of #ifdef directive
 #ifdef ARDUINO_TTGO-LORA32-V1_DEV
                    ^

and the clang-format adds spaces around the dashes.

So to my opinion, the dashes should be replaced by underscores for the macro defined by the CMakeList.txt. Something like this:

string(REPLACE "-" "_" idf_target_for_macro "${idf_target_caps}")
target_compile_options(${COMPONENT_TARGET} PUBLIC
    ...
    -DARDUINO_${idf_target_for_macro}_DEV
    ...

... but this is already part of the solution and I will provide a Pull Request for this.

Sketch

#include <Arduino.h>

#ifdef ARDUINO_TTGO-LORA32-V1_DEV
#define DELAY 1000
#endif

void setup() { Serial.begin(115200); }

void loop() {
    Serial.println("Hello World!");
    delay(DELAY);
}

Debug Message

The error messages (warnings) are given in the description.

This warning comes from the command line because of the `-DARDUINO_TTGO-LORA32-V1_DEV` flag :

    <command-line>: warning: ISO C++11 requires whitespace after the macro name

This warning comes when you try to test for the symbol:

    main/main.cpp:3:20: warning: extra tokens at end of #ifdef directive
     #ifdef ARDUINO_TTGO-LORA32-V1_DEV
                        ^

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions