embeddedartistry / arduino-printf

Add printf support to the Arduino SDK
MIT License
91 stars 15 forks source link

Refactor library to move extras/ files back into src/ #40

Open phillipjohnston opened 2 years ago

phillipjohnston commented 2 years ago

From #37:

Second, the library's .cpp file includes the printf.c file directly in order to supply default compile-time configuration options (e.g., to make it suitable for AVR targets). Including the printf.c source file in the src tree causes the Arduino IDE to automatically compile the files a second time, generating multiple definition errors at link time. Moving to the extras folder gave me a pattern that worked to achieve the goals above (at least with the Arduino IDE, CMake, and Meson builds) and passes the Arduino library linter that is run to determine whether your library can be included in the library manager. (All my headaches are caused by the "helpful" features like auto-compiling source files or auto-deleting "unnecessary" folders to save space or configuration options 😅).

After this recent filing, I looked into refactoring the Arduino library code to use the recently provided configuration header support in printf.c to supply the default options, but its inclusion is dependent on another preprocessor definition instead of something like __has_include, so I cannot get around it without updating the upstream library. Ideally, I will work with the maintainer to get these changes rolled in (ideal scenario), otherwise I will have to deviate further on my own fork or in this library. One of those will happen, but not in the next few weeks, so again a stopgap would be welcome.