Allow code to make #include
optional
#1650
Labels
topic: build-process
Related to the sketch build process
topic: code
Related to content of the project itself
type: enhancement
Proposed improvement
Describe the request
Code might contain optional functionality dependent on the presence of a library.
It would be nice to have a way to handle this programmatically, based on the presence or absence of the library dependency.
Describe the current behavior
Currently, the user would need to uncomment an
#include
directive for the library to enable such functionality:This is inconvenient and prone to user error.
We would expect to be able to use the
__has_include
preprocessor operator:However, this only works if the header file is present in the compiler's "search path". A library will only be present in the search path if it has already been discovered, so
__has_include (<Foo.h>)
will evaluate asfalse
even if a library containingFoo.h
is installed, unless the library had already been discovered by the sketch build system. Library discovery is done based on#include
directives, and the directive will cause compilation to fail if the library containing the header file is not installed.Describe the solution you'd like
With other setups I would probably do it like:
This actually will work in libraries if someone else explicitly includes it. And can work with other build setups for building Arduino sketches using some other mechanisms such as Makefiles.
Also note: with libraries this does not work if the header file is contained within the sketch folder
That is, if your have a library, that you wish to pass in the user configuration, it won't work to have it try to optionally read some options header file in the sketch (which also would be nice)
Arduino CLI version
Original report
Not specified.
Last verified with
a2eebcd
Operating system
All
Operating system version
Any
Additional context
Related
Issue checklist
The text was updated successfully, but these errors were encountered: