How about using CMake to build your Arduino projects?
How about using CMakeLists.txt
files as simple as this?
cmake_minimum_required(VERSION 3.19)
project(CMakeBlink LANGUAGES CXX)
add_executable(CMakeBlink CMakeBlink.ino)
This all can be done using Arduino CLI. This toolchain is fully based upon this really great tool: There are no tricks, no hacks, no manual parsing of obscure text files at undocumented locations. Just the official API and some pretty straight forward CMake. That's the main principle of this toolchain file, and that's what hopefully makes it more robust than any other Arduino toolchain file before (— famous last words).
This project is in early development. So far nothing more than a fairly successful proof of concept.
- There still are plenty of shorcuts and major FIXME comments in the scipts.
- The toolchain only has been successfully tested with the Ninja generator so far.
- CMake's MS-Build generator is known to fail.
- Most importantly one cannot add libraries yet.
- Annoyingly one still needs an
#include <Arduino.h>
in the main sketch. - Many more problems, I guess...
Check "ready for public announcement" to see what's missing.
The following Arduino platforms are tested automatically:
Anyway, if you got some spare time, feel free to try out, to test, to give feedback, to contribute.
In general just configure your project like this:
cmake -S ~/Arduino/YourProject \
--toolchain PATH-TO/arduino-cli-toolchain.cmake \
-D ARDUINO_BOARD=arduino:avr:nano
The parameter ARDUINO_BOARD
is mandatory and provides your device's FQBN to the toolchain.
For more information about the FQBN string, or so called "fully qualified board names" visit the Arduino CLI wiki.
- add a new kit to QtCreator
- name the new kit, e.g. "Arduino (board name)"
- select "Bare Metal Device"
- make sure no Qt version is selected
- configure CMake's initial configuration
- remove all old settings
- select the toolchain:
-DCMAKE_TOOLCHAIN_FILE:PATH=/YOUR/PATH/TO/cmake-toolchain-arduino-cli/toolchain/arduino-cli-toolchain.cmake
- configure a board:
-DARDUINO_BOARD:STRING=esp8266:esp8266:nodemcuv2:baud=512000
Here you go! You are ready to open CMake based Arduino projects in QtCreator.
This toolchain file, its related tools, tests, and examples are provided by under the terms of the MIT License.
This project would not have been possible without all the previous hard work Arduino-CMake-Toolchain. I took good inspiration from it, especially when it comes to making CMake's initial compiler detection accept Arduinos very special binary layout.