CMake with Arduino

Hi everyone!
I'm new here, but I've been using Arduino for a long time now.
This year I followed a programming course about C at my University and I learnt how to use CMake to compile programs.
I came here to ask you if there's a way to use it together with Arduino, bypassing the Arduino IDE.
I searched a lot on the Internet, but the guides I found aren't much helpful.
Could someone suggest me a good guide or point me in the right direction?
I can work both on Linux (Ubuntu) and Windows.

Which microcontroller do you want to target?

Arduino Mega

Hi here is a link for you on creating cmake files for Arduino.

cmake and Arduino

1 Like

Here's what I use:

It uses modern target-based CMake, using toolchain files to select different boards.
The CMakeLists file for a simple “blink” example looks like this:

The Arduino core files are compiled into a library in cmake/arduino_core.cmake.
The executable is converted into a .HEX file using cmake/arduino_hex.cmake, and this .HEX file is uploaded using avrdude in cmake/arduino_upload.cmake.

The board-specific options are in the toolchain files, e.g. cmake/toolchain/uno.toolchain.cmake. You can take these settings straight from ArduinoCore-avr/boards.txt.

It doesn't do anything fancy, but it works just fine, and it is simple enough to understand and modify yourself: it's just 160 lines of CMake scripting.

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.