-
Notifications
You must be signed in to change notification settings - Fork 12
Creating First Program
Creating a program with Arduino-CMake is ridiculously easy.
First make sure you've fulfilled the requirements for your OS by installing necessary programs. Then download the source/assets and extract them to a directory on your file system.
It's important to understand that Arduino-CMake is simply a cmake toolchain.
What that means to the user is that it should only include a single .cmake
file in his project in order to use Arduino-CMake. However, Arduino-CMake is not that simple and consists of many additional cmake scripts required for it to work, so to fully setup the toolchain you should do one of the followings:
- Copy the directory extracted earlier to your project's directory
- Have the path to the extracted directory "at hand"
Then, you should create a CMakeLists.txt
file in your project's main directory.
A simple example of such file could be:
cmake_minimum_required(VERSION 2.8)
# Include Arduino-CMake Toolchain
set(CMAKE_TOOLCHAIN_FILE [ARDUINO_CMAKE_PATH]/ArduinoToolchain.cmake)
#====================================================================#
# Setup Project #
#====================================================================#
project(MyProject C CXX ASM)
#====================================================================#
# Create Arduino's Executable
#====================================================================#
generate_arduino_firmware(${CMAKE_PROJECT_NAME}
SRCS main.cpp
BOARD uno
PORT /dev/ttyACM0)
Where:
-
[ARDUINO_CMAKE_PATH]
is the path to the extracted directory (Use relative if copied under project). -
SRCS
is a list of source files used by the program. -
main.cpp
is a C++ source file which looks exactly like the main.ini
file used by Arduino IDE. -
BOARD
is the name of the Arduino board used to run the program. -
PORT
is the port at which your Arduino micro-controller is connected to accept uploads.
At last, you should reload CMake's cache using either cmake's built-in tools (See Using CMake Tools) or your IDE. Once reloaded - build the project using make (See Building With Make) or your IDE.
Note: Generating cmake on Windows can be quite hard when doing it manually. Head to the Generating CMake page if your'e having problems.
That's it!