Arduino-AVR-CMake
Arduino-AVR-CMake copied to clipboard
Compile Arduino AVR programs using CMake.
Arduino AVR CMake
Compile Arduino AVR programs using CMake.
Instructions
- Clone this repository and open a terminal in the
Arduino-AVR-CMakefolder. - Ensure that the Arduino AVR core is installed correctly, this guide assumes
that the core is in
~/.arduino15/packages/arduino/hardware/avr/1.8.6, that the toolchain is in~/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7, and that avrdude is in~/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17. If this is not the case, change it now incmake/toolchain/avr.toolchain.cmake. - Configure the project using CMake by running the following command:
Customize the port, toolchain file, and build type for your specific configuration.cmake -S. -Bbuild \ -D ARDUINO_PORT=/dev/ttyACM0 \ -D CMAKE_TOOLCHAIN_FILE=cmake/toolchain/uno.toolchain.cmake \ -D CMAKE_BUILD_TYPE=MinSizeRel - Finally, build and upload the example “blink” program:
To compile the program without uploading, you can usecmake --build build -j -t upload-blink
If you're using an Arduino with a native USB interface (e.g. Leonardo), you'll have to press the reset button before uploading. You could automate this by opening its serial port at 1200 baud as part of the upload process.cmake --build build -j -t blink
VSCode
In VSCode, you can select the board you want to use using the
CMake: Select a Kit command from the CMake Tools extension.
Then select the right board as shown in the following image:

To build the sketch, you can either press F7 or click the Build
button in the bottom ribbon or in the CMake side panel. To upload, you can use
the upload-blink utility in the CMake side panel:
