Skip to content

Link the Arduino component automatically when built as an ESP-IDF component - #344

Merged
lovyan03 merged 1 commit into
m5stack:developfrom
ainyan03:arduino_component_link
Aug 27, 2026
Merged

Link the Arduino component automatically when built as an ESP-IDF component#344
lovyan03 merged 1 commit into
m5stack:developfrom
ainyan03:arduino_component_link

Conversation

@ainyan03

Copy link
Copy Markdown
Contributor

Problem

When arduino-esp32 is used as an ESP-IDF component, its -DARDUINO=... definitions are exported as PUBLIC compile options of the Arduino component, so they only reach components that link against it — the application (main) does, this library did not. The public headers of this library change class layout with ARDUINO (for example config_t has serial_baudrate only under ARDUINO, and the display object it embeds changes size), so the application read the same objects with a layout different from the one the library was compiled with: getPanel() returned null and the first drawing call faulted.

The CMakeLists.txt already carried the fix as a commented-out line (list(APPEND COMPONENT_REQUIRES arduino-esp32)), but a user of the component registry cannot enable it.

Change

After register_component(), look for an Arduino component among the components selected for the build (arduino, arduino-esp32 or espressif__arduino-esp32) and link it PUBLIC, so this library is compiled with the same definitions as the application. Only BUILD_COMPONENTS is consulted: a build that does not contain Arduino, or excludes it with COMPONENTS / EXCLUDE_COMPONENTS, is unaffected. Only APIs available since ESP-IDF 4.x are used. This is the same pattern arduino-esp32 itself uses for its optional dependencies (maybe_add_component).

  • M5UNIFIED_ARDUINO_COMPONENT=<name> selects a differently named Arduino component; M5UNIFIED_ARDUINO_COMPONENT=OFF disables the automatic dependency.
  • Several matching Arduino components in one build is a configuration error (FATAL_ERROR with the variable to set).
  • README: note on using the library with Arduino as an ESP-IDF component.

Note for hybrid projects: once Arduino is part of the build, every component that includes this library's headers now compiles them in Arduino mode, which is what the application already did.

Verification

  • ESP-IDF 5.5.1 + arduino-esp32 3.3.3 as a component, ESP32: without this change getPanel() is null and the panel is never initialised; with it the display works. Setting M5UNIFIED_ARDUINO_COMPONENT=OFF restores the old behaviour, a custom name and an empty value behave as documented.
  • Pure ESP-IDF 5.5.4 and 6.0.2 builds without Arduino: unchanged (no dependency added).
  • CI on the ainyan03 fork is green for this branch.

…ponent

arduino-esp32 publishes its -DARDUINO... definitions as PUBLIC compile
options, so they only reach components that link against it. The public
headers of this library change class layout with ARDUINO (LGFXBase derives
from Print only under ARDUINO, for example), so an application built with
arduino-esp32 as a component read the same objects with a different layout
than this library was compiled with: getPanel() returned null and drawing
faulted. Pick the Arduino component that is already part of the build
(arduino / arduino-esp32 / espressif__arduino-esp32, overridable with
<LIB>_ARDUINO_COMPONENT, OFF to disable) after register_component() and link
it publicly. Only BUILD_COMPONENTS is consulted, so a build that excludes
Arduino is unaffected, and only APIs that exist since ESP-IDF 4.x are used.
@lovyan03
lovyan03 merged commit 746c380 into m5stack:develop Aug 27, 2026
27 checks passed
@ainyan03
ainyan03 deleted the arduino_component_link branch August 27, 2026 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants