I am working on an Arduino project with other developers. We have a shared git
repository whose folder structure looks like this:
- TopLevelProjectFolder
- Sketch1
- Sketch1.ino
- Sketch2
- Sketch2.ino
- ...
- Utils
- Func1.h
- Func1.cpp
- Func2.h
- Func2.cpp
- ...
Each .ino
sketch file makes use of one or more of the functions defined in the common Utils
directory.
We are using the Arduino IDE to build our executables. I understand that there are two standard ways that I can include custom code in a .ino
file so that the Arduino IDE can find it:
-
Create a
src
folder beneath each sketch folder and manually copy the required utility functions (.cpp
and.h
) fromUtils
to this new folder; then include them in the.ino
files using#include "src/Func1.h"
directives. -
Create a
Utils
folder beneath the machine-specificArduino/Libraries
folder (created during installation of the Arduino IDE) and copy the contents of theUtils
directory in the repo to that folder.
Neither of these is ideal in a multi-developer environment: they each involve manual duplication of files (to the respective target directory) and potential mishaps when updating shared utility functions. I tried to automate copying files from Utils
to the target directory using pre-build hooks defined in platform.local.txt
but they take effect too late in the build process (and in any case this isn't great because platform.local.txt
has to live in the machine-specific installation directory).
What is the recommended way to share common code with a set-up like this?