Skip to content

Instantly share code, notes, and snippets.

@antonagestam
Forked from adrien-f/CMakeLists.txt
Created February 14, 2017 23:28
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save antonagestam/d279491ca5b5b31e73f278280c447013 to your computer and use it in GitHub Desktop.
CLion and Arduino via Platform.io

CLion and Arduino via Platform.IO

Hi guys !

Here's my quick guide to set up CLion to work with the Arduino (and others) platforms. Once you get the gist (pun) of it, you should be fine !

Get Platform.IO

Follow the instructions here

Create a new project

# Create new folder YourProject
mkdir YourProject
platformio init -b uno -d YourProject

This will populate the folder YourProject with a src and lib folder.

Get the arduino libs

You should have somewhere on your drive the Arduino core library, on Windows I've found it in C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino. Copy its contents to the lib folder of your project along with the CMakeLists.txt file

Write your sourcecode

If you start having more than one file in your src folder, you'll need to add them to the src CMake file.

Read the Manual

CMake is a bit tricky to get at first, but it's a really powerful tool, and cross platform. With this setup you'll be able to develop on Windows and as well on Linux and OSX.

CLion

Open CLion and select "Import Project from Sources" and pick your newly created project. Once in the IDE, create a new Run configuration:

You will need to find the platformio executable and set it.

Enjoy !

cmake_minimum_required(VERSION 3.2)
project(YourProject)
add_subdirectory(src)
add_subdirectory(lib)
# Put this CMakeLists.txt in the lib folder (don't forget to rename it)
# Feel free to add others .h and .c to the list
add_library(arduino_core
Arduino.h
Print.cpp
HardwareSerial.h
wiring.c
wiring_shift.c
WInterrupts.c
wiring_analog.c
wiring_digital.c
WMath.cpp
wiring_pulse.c)
#
# Project Configuration File
#
# A detailed documentation with the EXAMPLES is located here:
# http://docs.platformio.org/en/latest/projectconf.html
#
# A sign `#` at the beginning of the line indicates a comment
# Comment lines are ignored.
# Simple and base environment
# [env:mybaseenv]
# platform = %INSTALLED_PLATFORM_NAME_HERE%
# framework =
# board =
#
# Automatic targets - enable auto-uploading
# targets = upload
[env:autogen_uno]
platform = atmelavr
framework = arduino
board = uno
targets = upload
upload_port = COM3 # Change your port here
# Put this CMakeLists.txt in the src folder (don't forget to rename it)
include_directories(../libs)
link_directories(../libs)
link_libraries(arduino_core)
add_executable(YourProject main.cpp)
// Put this file in src/main.cpp
#include "Arduino.h"
void setup() {
pinMode(13, OUTPUT);
}
void loop()
{
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment