hasselmm / cmake-toolchain-arduino-cli

A CMake toolchain for Arduino entirely based upon Arduino CLI
MIT License
1 stars 0 forks source link
arduino avr cmake cmake-toolchain esp32 esp8266 samd stm32

CMake toolchain for Arduino CLI

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).

Status

This project is in early development. So far nothing more than a fairly successful proof of concept.

Check "ready for public announcement" to see what's missing.

The following Arduino platforms are tested automatically:

Platform Status
Arduino Core for AVR boards Status: AVR
Arduino Core for ESP32 boards Status: ESP32
Arduino Core for ESP8266 boards Status: ESP8266
Arduino Core for SAMD21 boards Status: SAM D
Arduino Core for STM32 boards Status: STM32
ATTinyCore Universal for ATtiny devices Status: ATtiny

Anyway, if you got some spare time, feel free to try out, to test, to give feedback, to contribute.

Usage

General

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.

QtCreator

Setup a new kit

  1. add a new kit to QtCreator
  2. name the new kit, e.g. "Arduino (board name)"
  3. select "Bare Metal Device"
  4. make sure no Qt version is selected
  5. configure CMake's initial configuration

Configure the kit's CMake settings

  1. remove all old settings
  2. select the toolchain: -DCMAKE_TOOLCHAIN_FILE:PATH=/YOUR/PATH/TO/cmake-toolchain-arduino-cli/toolchain/arduino-cli-toolchain.cmake
  3. configure a board: -DARDUINO_BOARD:STRING=esp8266:esp8266:nodemcuv2:baud=512000

Setup a project

Here you go! You are ready to open CMake based Arduino projects in QtCreator.

License

This toolchain file, its related tools, tests, and examples are provided by under the terms of the MIT License.

Credits

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.