The goal of this script is to generate a Makefile and optionally a QtCreator qmake project for an Arduino sketch.
It generates a Makefile which relies on arduino-cli
, and allows building and running an Arduino project from command line.
It can also generate a qmake project, from which you can edit, build and run the Arduino project.
This can be useful if you prefer working from command line or want to use a non Arduino IDE (e.g. QtCreator)
Several options can be set using some yaml configuration files.
The script works only under Linux. Since it relies on python3
, it should be quite easy to port to a different platform.
The script expects arduino-cli
to belong to your PATH
variable.
The script relies on python3
and the pyyaml
python package.
Create one or several yaml configuration files (check the "variables" paragraph from more information)
A minimal configuration consists of the fqbn
variable.
Launch the script to generate your project files.
Example:
arduino-genmakefile.py --sketch mysketch.ino --config myconf.yaml --makefile Makefile.myconf --qmake mysketch_myconf.pro
The script generates a Makefile with three targets:
Compile the sketch:
make -f <Makefile-path>
Compile and upload the sketch, and run the specified debug command (cf debug_command
variable):
make -f <Makefile-path> run
Clean the build:
make -f <Makefile-path> clean
If you passed the --qmake <path>
option, you can build and run the Arduino project from QtCreator:
- open the generated
.pro
file from QtCreator - select any Qt configuration (it doesn't matter since we'll build using arduino-cli)
- uncheck the
Build Settings/General/Shadow build
option - remove the
Build Settings/Build steps/qmake
step - uncheck the
Run settings/Run/Run in terminal
option (except if you want to run your debug command in a terminal, e.g. when you using minicom as debug command)
You can now use the QtCreator build and run commands.
Note: Along with the .pro
file, a .pri
file with the same prefix is created (cf below).
Note: In order to have better auto-completion and syntax highlighting in QtCreator,
the script attempts to set the HEADERS
, SOURCES
and INCLUDEPATH
qmake variables.
For this, it scans your libs
variable directories.
Additionally, some paths can be added or removed using the qmake_dirs
and qmake_excluded_dirs
variables.
The script also attemps to set the DEFINES
variable to the qmake file by checking the compiler output.
The HEADERS
, SOURCES
, INCLUDEPATH
and DEFINES
variables have no impact on the compilation.
They are used only for syntax highlighting and source code navigation in QtCreator.
The script will try to keep as many relative paths as possible, so that the .pro
and .pri
files can be added to SCM.
Additionnally, when the paths start with ~/
, the ~/
will be expanded to $$HOME
in the qmake files.
Relative paths are added to the .pro
file, while absolute paths are added to the .pri
file.
This can be practical if you wish to add only the .pro
file to SCM.
Several variables can be set in your yaml configuration files.
It is possible to include several configuration files by passing several times the --config
option.
It is also possible to "include" some additional configuration files from a configuration file. (cf configs
variable)
- type: string
- default: none
- description: the "fully qualified board name". All valid fqbns can be obtained with command
arduino-cli board listall
- example value:
fqbn: arduino:sam:arduino_due_x
Note: this is the only mandatory variable.
- type: array of strings
- default:
[]
- description: some additional configuration files to be used
- example value:
configs:
- ~/conf/common-config.yaml
- conf/project-config.yaml
Notes:
- when a path is relative, the directory of the configuration file where it is declared is prepended
- if an array variable is present in several files, the values are merged
- if a scalar variable is present in several files, the last found value is used
- type: array of strings
- default:
[]
- description: additional flags passed to the preprocessor and compiler. It uses the
--build-property compiler.cpp.extra_flags
option ofarduino-cli
- example value:
cflags:
- -Wall
- -I"$(CURDIR)"
- -DNO_PRAGMA_MARK
- -DSERIAL_IFACE=SerialUSB
- '"-DMY_STRING="SOME STRING""'
- type: array of strings
- default:
[]
- description: additional libraries paths. It uses the
--library
option ofarduino-cli
- example value:
libs:
- libs/lib1
- ~/libs/mycommonlib
Note: when a path is relative, the directory of the configuration file where it is declared is prepended
- type: string
- default:
cat $$SERIALPORT
- description: command to be run by the
make run
rule - example value:
debug_command: minicom -D $$SERIALPORT
Note: The SERIALPORT
variable is set internally by the Makefile run target, it will be set to the serial device
matching the attached board with the given fqbn (e.g. /dev/ttyACM0
)
- type: string
- default:
115200
- description: the baudrate to be set before starting the debug command
- example value:
baudrate: 9600
- type: string array
- default:
[]
- description: the list of additional paths to be scanned to add sources to the qmake project
- example value:
qmake_dirs:
- "~/.arduino15/packages/arduino/hardware/sam"
- "~/.arduino15/packages/arduino/tools/arm-none-eabi-gcc"
Note: you'll probably want to use different values here depending on your board. Note: when a path is relative, the directory of the configuration file where it is declared is prepended
- type: string array
- default:
[]
- description: the list of paths to be excluded from
qmake_dirs
. This can be useful if you add a directory with a lot of sources, but want to exclude part of it. - example value:
qmake_exclude_dirs:
- "~/.arduino15/packages/arduino/hardware/avr"
Note: when a path is relative, the directory of the configuration file where it is declared is prepended
The script is uses templates for the Makefile and qmake project, located in the templates
directory.
You can select some different templates using the --makefile-template
and --qmake-template
options.
You can refer to the tests/simple
directory, which contains a sample project.