Arduino Forum

Development => Suggestions for the Arduino Project => Topic started by: gentoouser on Jul 03, 2011, 10:35 am

Title: Arduino and CMake
Post by: gentoouser on Jul 03, 2011, 10:35 am

I have been working on a project to compile the Arduino code into static libraries using the CMake build system.  This will allow more advanced developers to use any desired development environment, as the Arduino IDE tends to cater to people with little programming experience.  At the moment, it compiles, but there is still a lot to do.

Anyways, I thought I would document and share the details of getting CMake to work with the Arduino boards.  I should mention that I am using avr-gcc on Gentoo Linux, and I have no idea if everything here applies to other operating systems and compilers.

Linker Problems

The linker may complain about unresolved symbols if the __cxa_pure_virtual function is not included.  The function is an error handler that is invoked when a pure virtual function is called.  This should never happen, since it is impossible to instantiate a class that doesn't implement all virtual functions.
Code: [Select]

extern "C" void __cxa_pure_virtual(void) \
{ \

The define makes it easier to add the function to a program.  All that is required is to add
Code: [Select]


at the beginning of the source file.

Gentoo avr-gcc Toolchain Bugs

On Gentoo, there is a bug with avr-gcc.  The error is
Code: [Select]

/usr/libexec/gcc/avr/ld: cannot open linker script file ldscripts/avr5.x: No such file or directory

A workaround is
Code: [Select]

sudo ln -s /usr/lib/binutils/avr/2.21.1/ldscripts /usr/avr/lib/ldscripts

Example CMake Build Files


Code: [Select]

set(ARDUINO_PROCESSOR "atmega328p")

Example CMake build script:

Note that the example script assumes there exists a library called libarduino-core, which is one of the libraries I built.

I forgot to document the F_CPU macro in the arduino-common.cmake file.  It is required by util/delay.h in the AVR libc library.  The functions available allow the specification of microsecond, and millisecond delays directly, using the application-supplied macro F_CPU as the CPU clock frequency (in Hertz).  The macro F_CPU is passed to the compiler in the cmake file.
Code: [Select]