Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define default #include directives in library metadata #322

Merged
merged 1 commit into from
May 21, 2022
Merged

Define default #include directives in library metadata #322

merged 1 commit into from
May 21, 2022

Conversation

per1234
Copy link
Contributor

@per1234 per1234 commented May 21, 2022

When a library is selected from the Sketch > Include Library menu of the Arduino IDE, #include directives for its header files are added to the sketch.

By default, #include directives for all header files present in the library's root source folder are added. In some cases that is not wanted. For this reason, the Arduino IDE allows the customization of the behavior of this IDE feature via the includes field of the library.properties library metadata file. When this field is defined, the IDE will instead add #include directives for only the files in this comma-separated list:

https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format

"Adafruit NeoPixel" is a library where the default behavior of the Arduino IDE is not appropriate. The reason is the presence of the rp2040_pio.h header in the root source folder. This file contains code specific to the RP2040, and so adding an #include directive for it will result in a compilation error when a board of any other architecture is selected:

https://forum.arduino.cc/t/hardware-pio-h-error/992695

Since the primary Adafruit_NeoPixel.h header contains a conditional #include for that file, there is never a need for the user to have an #include directive for the file added to their sketch along with the one for Adafruit_NeoPixel.h. Correct behavior of the Arduino IDE's "Include Library" feature will be ensured by specifying Adafruit_NeoPixel.h in the includes field of library.properties.

When a library is selected from the "Sketch > Include Library" menu of the Arduino IDE, `#include` directives for its header files are added to the sketch.

By default, #include directives for all header files present in the library's root source folder are added. In some cases that is not wanted. For this reason, the Arduino IDE allows the customization of the behavior of this IDE feature via the `includes` field of the library.properties library metadata file. When this field is defined, the IDE will instead add `#include` directives for only the files in this comma-separated list.

"Adafruit NeoPixel" is a library where the default behavior of the Arduino IDE is not appropriate. The reason is the presence of the rp2040_pio.h header in the root source folder. This file contains code specific to the RP2040, and so adding an `#include` directive for it will result in a compilation error when a board of any other architecture is selected.

Since the primary Adafruit_NeoPixel.h header contains a conditional #include for that file, there is never a need for the user to have an `#include` directive for the file added to their sketch along with the one for Adafruit_NeoPixel.h. Correct behavior of the Arduino IDE's "Include Library" feature will be ensured by specifying Adafruit_NeoPixel.h in the `includes` field of library.properties.
@ladyada ladyada merged commit 6d239e3 into adafruit:master May 21, 2022
@ladyada
Copy link
Member

ladyada commented May 21, 2022

thank you @per1234 have a great weekend!

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