Giter Site home page Giter Site logo

arduino-cmake / arduino-cmake-ng Goto Github PK

View Code? Open in Web Editor NEW
134.0 12.0 37.0 3.45 MB

CMake-Based framework for Arduino platforms

License: MIT License

CMake 99.16% Dockerfile 0.62% Shell 0.22%
arduino cmake build build-tool build-system make ninja arduino-platform arduino-ide cmake-toolchain

arduino-cmake-ng's Introduction

Arduino-CMake NG

AppVeyorTravis CI

Arduino-CMake is a framework which allows developers to write Arduino-based programs using any tool that supports cmake. Arduino-based? There are many other frameworks out there built upon Arduino's base, such as ESP32, and we respect that (Note that it doesn't mean we support it yet).
In other words, developers can use their favorite IDEs or text editors on their favorite OS to develop Arduino programs!

Wait - Hasn't it been possible all this time? Apparently not. You can read more about it in the Motivation section.

Note to new users: The master branch is used for active development only, so if you seek to simply use the framework then you should head to the releases section instead!

Important Notice

This project is dead and is no longer maintained! You can find more info here.
However, there's a new framework named Arduino-CMake-Toolchain that took the basis of this project and continued it very well - Please use it!

Features

Arduino-CMake should1 do almost2 anything that the Arduino IDE does!

What's supported?

  • Developing Arduino programs in any IDE or text editor
  • Arduino Programs - Executables
  • Uploading/Flashing programs to hardware boards
  • Libraries
    • Arduino native libraries, built-in with most of the SDKs (such as Blink)
    • 3rd Party libraries
    • User libraries
  • Arduino example programs
    • Arduino library example programs
  • Arduino sketches (.ino files)
    • Conversion of sketch files to .cpp source files
    • Resolving libraries used by a sketch file
    • Generating required function prototypes/signatures in converted sources
  • 3rd Party platforms (such as ESP32, pinoccio, etc.)
  • Programmers and bootloaders
  • Serial Connection (e.g. for monitoring)
  • Completely customizing the build process per user's requirements
    • Setting custom build flags
    • Using user-generated build recipes

It's also worth mentioning that Arduino-CMake is cross platform and works out-of-the-box on every OS that support CMake and Arduino.

1 The framework is still a WIP, meaning there are some missing features.
2 The Arduino IDE supports several concepts which make writing code easier but are completely unprofessional. Our framework is not willing to encourage such poor coding standards, and thus doesn't support them. These will be mentioned throughout the documentation.

Usage

A very basic example of how Arduino-CMake can be used is listed below:

# Define CMake's minimum version (must-do) and the project's name and supported languages
cmake_minimum_required(VERSION 3.8.2)
project(Hello_World)

# Call a framework utility function, passing it information about the hardware board that will be used - This function returns a structure known only to the framework
get_board_id(board_id nano atmega328)

# Create an executable suitable for Arduino using CMake-style target-creation
add_arduino_executable(Hello_World ${board_id} helloWorld.cpp)
# Upload the created target through a connected Serial Port (Where your board is connected to)
upload_arduino_target(Hello_World "${board_id}" COM3)

You should then call CMake (either through cmd, cmake-gui or an IDE if it supports that), passing it the argument -DCMAKE_TOOLCHAIN_FILE=[project_path]/cmake/Arduino-Toolchain.cmake where [project_path] is substituted by the project's full path. This is what allows cmake to use our framework.

That's it! It's super simple, yet super extensible :)

Motivation

Everyone has their favorite IDE or text editor, and would like to continue using it as long as they can. Upon encountering a framework that doesn't support it - We get frustrated. Unfortunately that's often the case with the Arduino framework, as it offers a custom toolchain that makes it uncomfortable to use outside the dedicated Arduino IDE.

Arduino-CMake solves it by creating a framework leveraging all of Arduino's features, including its' custom toolchain, by adding a single dependency - The CMake build system.

Project Roots

The original project started back in 2011 by queezythegreat and had been actively developed until 2014, when it had been abandoned due to unknown reasons. Since then more than 150 (!) forks have emerged, leading to a "chaos" in the Arduino-CMake sphere. The most important moment however was in 2017, when a combined effort by JonasProgrammer and MrPointer has brought new life to the project in the face of the arduino-cmake organization. And yet, it still had its own problems, leading once again to an abandoned state.

Then, in 2018, an extreme effort has been made and the project has been completely rewritten (mostly by MrPointer) with a few very clear goals in mind:

  • Platform-Independent - The framework shouldn't assume it works only with the basic Arduino platform, as there are many others out there. Any platform that confront to the design of the basic Arduino SDK is appropriate for use. An example of such a platform is ESP32.
  • Modern CMake - All previous projects/forks have been using the fairly old CMake 2.8. CMake itself has transitioned much from version 2 to 3, benefiting from a whole lot of new exciting features. Even the official package managers support CMake 3 versions, so there's no excuse to not use it.
  • Modern Arduino SDK - The Arduino SDK, much like CMake, has also undergone several major changes during the years, especially with version 1.6. The Arduino SDK has only recently got stable, and that's why we recommend always having the latest version installed, although we do have some minimum requirements for the framework to even work. You can find them at the Requirements section.

How it works

Arduino programs are simply C/C++ programs which take advantage of a framework which allows them to run on specific hardware devices. It means that those programs need to be compiled somehow. Back in the "old days" developers used compilers such as gcc directly from the command line. Then came build-tools such as make. Then came CMake. Most of the modern build systems today are managed by CMake and most of the modern IDEs know that and take advantage of it. But what's really useful in CMake, at least regarding our Arduino world, is the ability to cross-compile with a toolchain. The Arduino SDK, which one usually downloads together with the Arduino IDE, is actually also a toolchain, as it includes the required compilation & linkage tools for cross-compiling. Analyzing the SDK allows us to build a framework using this toolchain, and also all of Arduino's other cool features such as libraries, examples, etc.

What is NG

NG stands for "New Generation". Inferred from the written above, it can easily be understood why the project has this name. However, if you don't think this name is good enough or it confuses you - Feel free to propose a name of your own, we're open for offers :)

Requirements

The following list is the basic requirements of the framework in order to use it:

  • Windows, OS X or Linux (BSD support is currently unknown, use at your own risk)
  • CMake Version 3.8 or Higher
  • Arduino-Based SDK compatible with Arduino SDK Version:
    • 1.8.2 or Higher on Microsoft Windows
    • 1.6.10 or Higher on Linux and Apple OS X

Installation

First, make sure to download the latest release of the framework.
Further instructions can be found in the Installation Wiki page.

Documentation

The entire documentation of the project is hosted on GitHub using Wiki pages.

Contributing

The project has strict contributing guidelines which can be found in the Contributing File.

License

MIT © 2018 Arduino-CMake

arduino-cmake-ng's People

Contributors

glowmouse avatar jeandet avatar mrpointer avatar ooxi avatar taoyuan avatar tellowkrinkle avatar toshi38-sony avatar wgrs33 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduino-cmake-ng's Issues

Newbie: need some hand holding.

First attempt at using cmake. Errors. My project root CmakeLists.txt:

cmake_minimum_required(VERSION 3.2)
project(blink C CXX ASM)
get_board_id(board_id nano atmega328)
add_arduino_executable(blink ${board_id} src/main.cpp)
upload_arduino_target(blink "${board_id}" /dev/ttyACM0)

Q1: where do I find _documentation for get_board_id. I have googled and googled. What should I be passing for an Elegoo Uno R3?

Now to the make process

rgr@development-nuc  ~/development/arduino/Blink-PlatformIO/build   master ● ?  cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/Arduino-Toolchain.cmake ..
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- The ASM compiler identification is GNU
-- Found assembler: /home/rgr/development/arduino/arduinoSDK/hardware/tools/avr/bin/avr-gcc
-- Arduino SDK version 1.8.8: /home/rgr/development/arduino/arduinoSDK
-- Determined Platform Header: /home/rgr/development/arduino/arduinoSDK/hardware/arduino/avr/cores/arduino/Arduino.h
-- Arduino SDK version 1.8.8: /home/rgr/development/arduino/arduinoSDK
-- Determined Platform Header: /home/rgr/development/arduino/arduinoSDK/hardware/arduino/avr/cores/arduino/Arduino.h
-- Check for working C compiler: /home/rgr/development/arduino/arduinoSDK/hardware/tools/avr/bin/avr-gcc
-- Check for working C compiler: /home/rgr/development/arduino/arduinoSDK/hardware/tools/avr/bin/avr-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Arduino SDK version 1.8.8: /home/rgr/development/arduino/arduinoSDK
-- Determined Platform Header: /home/rgr/development/arduino/arduinoSDK/hardware/arduino/avr/cores/arduino/Arduino.h
-- Check for working CXX compiler: /home/rgr/development/arduino/arduinoSDK/hardware/tools/avr/bin/avr-g++
-- Check for working CXX compiler: /home/rgr/development/arduino/arduinoSDK/hardware/tools/avr/bin/avr-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at cmake/Platform/Other/TargetFlagsManager.cmake:67 (set_target_compile_flags):
set_target_compile_flags Function invoked with incorrect arguments for
function named: set_target_compile_flags
Call Stack (most recent call first):
cmake/Platform/Targets/ExecutableTarget.cmake:17 (set_executable_target_flags)
CMakeLists.txt:16 (add_arduino_executable)

CMake Error at CMakeLists.txt:19 (upload_arduino_target):
Unknown CMake command "upload_arduino_target".

Thats it. Where do I go from here. I can find nothing at all in google and this CMakesList was lifted from the first page in the Wiki.

Many thanks for helping me out of the quagmire I find myself in! ;)

Install for library depending on platform

Hello,

I would create a library (let's say libArduino) using SD and Servo, and link to this lib in a separated executable, but I get the following error CMake Error: install(EXPORT "libarduino-targets" ...) includes target "libarduino" which requires target "servoLib" that is not in the export set.

how can I add to the export set the required files ?

Thanks,

Unsupported header-only libraries when using 'find' API

Currently there's no support for header-only libraries, especially when using the find_library API.
The reason for this is that the find_library fails if it doesn't finds any source files, however, that's always the case for header-only libraries, and can be marked as "false-positive".

Solution would be simply to pass an option to the function - HEADER_ONLY, which will hint the framework to ignore sources.

Edit: CMake can't compile nor link header-only libraries, and must use the INTERFACE keyword instead. This leads to a far more complicated solution, which will probably require a separate function.

Document board discovery, get_board_id() parameters

I can't figure out, and don't see in docs, information about how to figure out what the correct identifiers are for get_board_id, or how to list the available parameters.

It would be really useful to have a function, like the print_board_list() function in the old queezythegreat repo.

Automate deployment from AppVeyor to GitHub Releases

Although the configuration already exists in appveyor.yml, we don't quite understand how to properly activate it, as it publishes a release only on a tagged build.

The goal here is to figure out exactly which build trigger the tagged event to deploy a release.

Compiler flags aren't properly expanded

OS: Linux
Distribution (Linux Only): Ubuntu
OS Version: 18.04
Platform: Arduino Micro
Platform SDK Version: 1.8.7

I've modified /examples/hello-world/CMakeFiles.txt as below for my Arduino Micro, and then I tried to build this, but it failed with the following build errors.

cmake_minimum_required(VERSION 3.8.2)

project(Hello_World)
get_board_id(board_id micro atmega32u4)

add_arduino_executable(Hello_World ${board_id} helloWorld.cpp)

Error:

[  3%] Building CXX object CMakeFiles/micro_core_lib.dir/home/foriequal0/bin/arduino-1.8.7/hardware/arduino/avr/cores/arduino/USBCore.cpp.obj
/home/foriequal0/bin/arduino-1.8.7/hardware/tools/avr/bin/avr-g++   -I/home/foriequal0/bin/arduino-1.8.7/hardware/arduino/avr/cores/arduino -I/home/foriequal0/bin/arduino-1.8.7/hardware/arduino/avr/variants/micro  -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10807 "-DARDUINO_AVR_MICRO " -o CMakeFiles/micro_core_lib.dir/home/foriequal0/bin/arduino-1.8.7/hardware/arduino/avr/cores/arduino/USBCore.cpp.obj -c /home/foriequal0/bin/arduino-1.8.7/hardware/arduino/avr/cores/arduino/USBCore.cpp
In file included from /home/foriequal0/bin/arduino-1.8.7/hardware/arduino/avr/cores/arduino/USBAPI.h:44:0,
                 from /home/foriequal0/bin/arduino-1.8.7/hardware/arduino/avr/cores/arduino/USBCore.cpp:20:
/home/foriequal0/bin/arduino-1.8.7/hardware/arduino/avr/cores/arduino/USBCore.cpp:73:29: error: 'USB_VID' was not declared in this scope
  D_DEVICE(0xEF,0x02,0x01,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,ISERIAL,1);
                             ^
/home/foriequal0/bin/arduino-1.8.7/hardware/arduino/avr/cores/arduino/USBCore.h:267:61: note: in definition of macro 'D_DEVICE'
  { 18, 1, USB_VERSION, _class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs }
                                                             ^
/home/foriequal0/bin/arduino-1.8.7/hardware/arduino/avr/cores/arduino/USBCore.cpp:73:37: error: 'USB_PID' was not declared in this scope
  D_DEVICE(0xEF,0x02,0x01,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,ISERIAL,1);
                                     ^
/home/foriequal0/bin/arduino-1.8.7/hardware/arduino/avr/cores/arduino/USBCore.h:267:66: note: in definition of macro 'D_DEVICE'
  { 18, 1, USB_VERSION, _class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs }
                                                                  ^
CMakeFiles/micro_core_lib.dir/build.make:497: recipe for target 'CMakeFiles/micro_core_lib.dir/home/foriequal0/bin/arduino-1.8.7/hardware/arduino/avr/cores/arduino/USBCore.cpp.obj' failed

Recipe should be expanded with the board_id

I've tracked down this error.

avr-g++   -I/home/foriequal0/bin/arduino-1.8.7/hardware/arduino/avr/cores/arduino -I/home/foriequal0/bin/arduino-1.8.7/hardware/arduino/avr/variants/micro  -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10807 "-DARDUINO_AVR_MICRO " -o CMakeFiles/micro_core_lib.dir/home/foriequal0/bin/arduino-1.8.7/hardware/arduino/avr/cores/arduino/USBCore.cpp.obj -c /home/foriequal0/bin/arduino-1.8.7/hardware/arduino/avr/cores/arduino/USBCore.cpp

This compiler invocation command is an expansion of following recipe.

# arduino-1.8.7/hardware/arduino/avr/platforms.txt
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} (...) {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"                                                                               

And placeholder {build.extra_flags} should be overriden by following definition.
refer: https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification#boardstxt

# arduino-1.8.7/hardware/arduino/avr/board.txt
micro.build.extra_flags={build.usb_flags}

And finally {build.usb_flags} should be expanded by following definition.

# arduino-1.8.7/hardware/arduino/avr/platforms.txt
build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}'

But recipe.cpp.o.pattern is expanded without the board id which used to override {build.extra_flags}
Refer: https://github.com/arduino-cmake/Arduino-CMake-NG/blob/v0.6/cmake/Platform/Properties/PropertiesReader.cmake#L14

This leads to the expansion of recipe.cpp.o.pattern doesn't contains {build.extra_flags} or {micro.build.extra_flags}

I've commented that line to fix this issue, expecting later expansion should handle them with the board id, then retried a build, but I encountered the second issue.

The expansion is not recursive

Let's look at the recipie again.

# arduino-1.8.7/hardware/arduino/avr/platforms.txt
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags}  ...

It contains {compiler.cpp.flags}, and it is defined as follows.

# arduino-1.8.7/hardware/arduino/avr/platforms.txt
compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -std=gnu++11  (...)

compiler.warning_flags is defined as follows.

# arduino-1.8.7/hardware/arduino/avr/platforms.txt
compiler.warning_flags=-w

But the expansion of recipe.cpp.o.pattern stops at the first level, this leads to an incorrect command.

avr-g++ (...) -c -g -Os {compiler.warning_flags} -std=gnu++11 -fpermissive (...)

(it still conatins {compiler.warning_flags}

I think _resolve_recipe_property function doesn't expand recursively.
refer: https://github.com/arduino-cmake/Arduino-CMake-NG/blob/v0.6/cmake/Platform/Properties/RecipePropertyValueResolver.cmake#L16

C-files in Arduino libraries. Not enough compilation flags.

OS: Linux
Distribution: Xubuntu
OS Version: 16.04
Platform: Arduino Mega
Platform SDK Version: 1.8.5
Arduino-CMake-NG: cbfebf9

CMake options:

-DCMAKE_TOOLCHAIN_FILE=/home/petro/install/arduino-cmake/cmake/Arduino-Toolchain.cmake -DARDUINO_SDK_PATH=/home/petro/install/arduino-1.8.5

I use arduino-timer-api library in my project, and its source-code is written in C, not in C++, as three libraries, which you use in arduino-library example. And there are some problems to build it. That's what I found:

  1. If not architectures set in library.properties library file, I have no -DARDUINO_ARCH_AVR definition for avr-gcc, if compile library C-files. If I specify avr for arch:
    architecutres=avr,pic32,sam
    this flag is in place.
  2. I try to convert C-files into C++. It was a perfect cure in my case. Here is the difference between compilation commands.

Compiling C++

/home/petro/install/arduino-1.8.5/hardware/tools/avr/bin/avr-g++
-DARDUINO_ARCH_AVR
-I/home/petro/install/arduino-1.8.5/libraries/Arduino-timer-api/src
-I/home/petro/install/arduino-1.8.5/hardware/arduino/avr/cores/arduino
-I/home/petro/install/arduino-1.8.5/hardware/arduino/avr/variants/mega
-c
-g
-Os
-w
-std=gnu++11
-fpermissive
-fno-exceptions
-ffunction-sections
-fdata-sections
-fno-threadsafe-statics
-MMD
-flto
-mmcu=atmega2560
-DF_CPU=16000000L
-DARDUINO=10805
"-DARDUINO_AVR_MEGA2560
"
-o
CMakeFiles/timer_api_lib.dir/home/petro/install/arduino-1.8.5/libraries/Arduino-timer-api/src/avr/timer_setup.cpp.obj
-c
/home/petro/install/arduino-1.8.5/libraries/Arduino-timer-api/src/avr/timer_setup.cpp

Compiling C

/home/petro/install/arduino-1.8.5/hardware/tools/avr/bin/avr-gcc
-DARDUINO_ARCH_AVR
-I/home/petro/install/arduino-1.8.5/libraries/Arduino-timer-api/src
-I/home/petro/install/arduino-1.8.5/hardware/arduino/avr/cores/arduino
-I/home/petro/install/arduino-1.8.5/hardware/arduino/avr/variants/mega
-o
CMakeFiles/timer_api_lib.dir/home/petro/install/arduino-1.8.5/libraries/Arduino-timer-api/src/avr/timer_setup.c.obj
-c
/home/petro/install/arduino-1.8.5/libraries/Arduino-timer-api/src/avr/timer_setup.c
  1. If I just add missing flags to my CMakeLists.txt, arduino-timer-api library and the whole project also builds successfully (may be not totally correctly):
add_definitions(-DARDUINO_ARCH_AVR -DARDUINO_AVR_MEGA2560 -DARDUINO=10802 -DF_CPU=16000000L)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmcu=atmega2560")

SuperThnx for your tool!

Failing build when using 3rd Party libraries

Originally reported by @machadolab in #15:

While troubleshooting, I also came across an issue with library naming. I have several popular arduino libs installed from Adafruit that have library names that do not conform to the arduino_compliant_library_name that Arduino-CMake-NG generates - for example Adafruit_NeoPixel and Adafruit_NeoMatrix are both converted to Adafruit_Neopixel and Adafruit_Neomatrix when the library directory is looked up.
The 3rd party library way did not work because the library uses arduino code and it looks like none of the arduino CFLAGs are passed to the building of the library. For example, I tried to define a user library for Adafruit_NeoPixel like so:

set(Adafruit_NeoPixel_Path /path/to/sketchbook/libraries/Adafruit_NeoPixel)
add_library(Adafruit_NeoPixel_lib STATIC ${Adafruit_NeoPixel_Path}/Adafruit_NeoPixel.cpp)
target_include_directories(Adafruit_NeoPixel_lib PUBLIC ${Adafruit_NeoPixel_Path})
link_arduino_library(Hello_World Adafruit_NeoPixel_lib ${board_id})

and get the build error:

In file included from /Users/machado/Dropbox/Arduino/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp:34:0:
/Users/machado/Dropbox/Arduino/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.h:25:23: fatal error: WProgram.h: No such file or directory
  #include <WProgram.h>
                       ^
compilation terminated.
make[3]: *** [CMakeFiles/Adafruit_NeoPixel_lib.dir/Users/machado/Dropbox/Arduino/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp.obj] Error 1
make[2]: *** [CMakeFiles/Adafruit_NeoPixel_lib.dir/all] Error 2
make[1]: *** [CMakeFiles/Hello_World.dir/rule] Error 2
make: *** [Hello_World] Error 2

Because the define ARDUINO is not present and therefore it falls back to looking for WProgram.h.

To summarize, here's a list of the key issues:

  • Arduino-Compliant Name as suggested by the framework isn't really compliant and doesn't work in all cases - only for built-in libraries
  • It seems that User/Custom/3rd Party Libraries that resemble an Arduino Library don't inherit the build flags a typical Arduino library should have

upload_arduino_target does not work (avrdude problem?)

Hello out there,

I am trying to upload my hex file via SPI - having the latest avrdude version and latest Arduino SDK version - sure this looks more like an avrdude problem ... But is there a way to specify an own configuration file for avrdude?

This works like a charme for me - how could I do this as upload target?

avrdude -c linuxspi -p m328p -P /dev/spidev1.0 -v -U flash:w:controller-arduino.hex

I am getting

-- Arduino SDK version 1.8.8: /opt/arduino/arduino-1.8.8
-- Determined Platform Header: /opt/arduino/arduino-1.8.8/hardware/arduino/avr/cores/arduino/Arduino.h
-- Arduino SDK version 1.8.8: /opt/arduino/arduino-1.8.8
-- Determined Platform Header: /opt/arduino/arduino-1.8.8/hardware/arduino/avr/cores/arduino/Arduino.h
-- Arduino SDK version 1.8.8: /opt/arduino/arduino-1.8.8
-- Determined Platform Header: /opt/arduino/arduino-1.8.8/hardware/arduino/avr/cores/arduino/Arduino.h
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/tmp.LL6xRi9W6k/build
[ 86%] Built target nano_atmega328_core_lib
[ 93%] Built target SPI
[ 96%] Linking CXX executable controller-arduino.elf
Generating EEP image
Generating HEX image
Calculating controller-arduino size
Firmware Size: [Program: 1922 bytes 5.9% ] [Data: 184 bytes 9.0% ] on atmega328p
EEPROM Size: [Program: 0 bytes 0.0% ] [Data: 0 bytes 0.0% ] on atmega328p

Uploading controller-arduino target

avrdude: Version 6.1-svn-20130917, compiled on Dec 31 2018 at 14:06:08
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/opt/arduino/arduino-1.8.8/hardware/tools/avr/etc/avrdude.conf"
avrdude: syntax error at /opt/arduino/arduino-1.8.8/hardware/tools/avr/etc/avrdude.conf:1095
CMakeFiles/controller-arduino.dir/build.make:86: recipe for target 'controller-arduino.elf' failed
make[2]: *** [controller-arduino.elf] Error 1
make[2]: *** Deleting file 'controller-arduino.elf'
CMakeFiles/Makefile2:73: recipe for target 'CMakeFiles/controller-arduino.dir/all' failed
make[1]: *** [CMakeFiles/controller-arduino.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

cmake_minimum_required(VERSION 3.2)

#set(ARDUINO_SDK_PATH /opt/arduino/arduino-linux-1.8.5)
set(ARDUINO_SDK_PATH /opt/arduino/arduino-1.8.8)

set(CMAKE_TOOLCHAIN_FILE /opt/arduino/Arduino-Toolchain.cmake)
#set(ARDUINO_DEFAULT_PORT /dev/ttyUSB0)  # Default Port, when not specified
#set(ARDUINO_DEFAULT_BOARD pro)          # Default Board ID, when not specified
#
#set(ARDUINO_BOARD_NAME "ProMini3V328")


# fully optimize debug code
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O2")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O2")

set(CMAKE_CXX_FLAGS "-std=c++11")

project(controller-arduino C CXX ASM)

#generate_arduino_firmware(controller-arduino
#        SRCS src/main.cpp include/queue.h
#        include/com.h src/com.cpp
#        include/util.h src/util.cpp
#        include/process.h src/process.cpp
#        include/clock.h src/clock.cpp
#        BOARD mega)
#
get_board_id(board_id nano atmega328)
add_arduino_executable(controller-arduino ${board_id} src/main.cpp)
link_platform_library(controller-arduino SPI ${board_id})

upload_arduino_target(controller-arduino "${board_id}" SPI)

Inconsistent platform libraries API

Based on the amount of related issues opened lately, and a general feedback from community - It seems that the current API of platform libraries isn't clear enough, and inconsistent with the API of other types of libraries.

The biggest problem is that the general library API is based on finding them, then linking them to a target, just as one would do in "ordinary" CMake.
However, since platform libraries are essential to Arduino development and their location is known once the entire platform is found - Logically, they don't seem to be needed to be found, thus requiring users only to link them to targets.
This, as it turns out, is not so "logical" afterwards, and should be addressed differently.

Edit: It appears that there's a serious lack of support for direct usage of platform libraries.
While these can be perfectly used by other libraries, such as 3rd party libs, users can't use them directly as part of their application now - It should be addressed immediately.

Platform libraries can be linked to cmake targets using the link_platform_library function.

Undefined reference to countPulseASM when using pulseIn function

OS: macOS
OS Version: 10.14.2
Platform: Arduino
Platform SDK Version: [Arduino SDK version 1.8.8]

When trying to use the built in "pulseIn" function, I receive an undefined reference to `countPulseASM'

Build Output:

====================[ Build | auto_car | Default ]==============================
/usr/local/bin/cmake --build /Users/Dominic/Desktop/auto-car/build --target auto_car -- -j 4
[ 92%] Built target mega_atmega2560_core_lib
[ 96%] Linking CXX executable auto_car.elf
/var/folders/vh/n3x031n547v4qhvxs1p_wtf00000gn/T//ccNcSGia.ltrans0.ltrans.o: In function `pulseIn':
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/wiring_pulse.c:46: undefined reference to `countPulseASM'
collect2: error: ld returned 1 exit status
make[3]: *** [auto_car.elf] Error 1
make[2]: *** [CMakeFiles/auto_car.dir/all] Error 2
make[1]: *** [CMakeFiles/auto_car.dir/rule] Error 2
make: *** [auto_car] Error 2

CMakeLists.txt:

cmake_minimum_required(VERSION 3.13.3)
project(auto_car LANGUAGES C CXX)

get_board_id(board_id mega atmega2560)

add_arduino_executable(auto_car ${board_id} src/auto_car.cpp)

Source file:

#include <Arduino.h>

#define PIN 14

void setup()
{
    // Setup
}

void loop()
{
    pulseIn(PIN, HIGH, 40000);
}

I believe this might be related to issue 364 in the Arduino-Makefile community and issue 23 from the original Arduino CMake Build System.

Help would be appreciated, thanks!

Toolchain can't find avrdude

Hi,

OS: Ubuntu 18.04LTS & Arch Linux (kernel 4.19)

I'm having the same issue on Arch & Ubuntu
I installed all the dependencies listed in the wiki. I made sure that avrdude is installed with:

# which avrdude
/usr/bin/avrdude

then I went into the examples folder and created a build directory:

cd Arduino-CMake-NG/examples
mkdir build && cd build

The problem is that when running:

cmake -DCMAKE_TOOLCHAIN_FILE=../../cmake/Arduino-Toolchain.cmake ..

I get the following error:

-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- The ASM compiler identification is GNU
-- Found assembler: /usr/share/arduino/hardware/tools/avr/bin/avr-gcc
CMake Error at /home/tobante/Developer/LightControl/Arduino-CMake-NG/cmake/Platform/System/AvrToolsFinder.cmake:43 (message):
  avrdude program is required by the toolchain but can't be found
Call Stack (most recent call first):
  /home/tobante/Developer/LightControl/Arduino-CMake-NG/cmake/Platform/System/BuildSystemInitializer.cmake:11 (find_tool_avrdude_configuration)
  /home/tobante/Developer/LightControl/Arduino-CMake-NG/cmake/Platform/System/BuildSystemInitializer.cmake:22 (find_required_platform_tools)
  /home/tobante/Developer/LightControl/Arduino-CMake-NG/cmake/Platform/Arduino.cmake:34 (initialize_build_system)
  /usr/share/cmake-3.10/Modules/CMakeSystemSpecificInformation.cmake:26 (include)
  CMakeLists.txt:3 (project)


-- Configuring incomplete, errors occurred!
See also "/home/tobante/Developer/LightControl/Arduino-CMake-NG/examples/build/CMakeFiles/CMakeOutput.log".

Not finding arduino-installed sketchbook libs that use 1.0 library format

It looks like the new code finds the 1.5 libs just fine. Thanks!!

But I've tried 3 different libs that use the old 1.0 format (no src/ directory) and none of them can be found. Here is an example using the EnableInterrupt library:

(as an aside, there seems be a problem again finding the arduino SDK on OSX. I had to set the system environment variable ARDUINO_SDK_PATH in order for it to work (but there is still funny log output with NOTFOUND in the output). (I'll open another bug for this).

CMakeLists.txt library entry:

find_arduino_library(EnableInterrupt EnableInterrupt ${board_id})
link_arduino_library(Hello_World EnableInterrupt ${board_id})

Result:

-- Arduino SDK version 1.8.3: ARDUINO_SDK_PATH-NOTFOUND
-- Determined Platform Header: /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h
-- Arduino SDK version 1.8.3: ARDUINO_SDK_PATH-NOTFOUND
-- Determined Platform Header: /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h
-- Arduino SDK version 1.8.3: ARDUINO_SDK_PATH-NOTFOUND
-- Determined Platform Header: /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h
CMake Error at cmake/Platform/Targets/ArduinoLibraryTarget.cmake:136 (message):
  Couldn't find any source files for the Enableinterrupt library
Call Stack (most recent call first):
  CMakeLists.txt:28 (find_arduino_library)


CMake Error at cmake/Platform/Targets/ArduinoLibraryTarget.cmake:162 (message):
  Library target doesn't exist - It must be created first!
Call Stack (most recent call first):
  CMakeLists.txt:29 (link_arduino_library)


-- Configuring incomplete, errors occurred!
See also "/Users/machado/tmp/MyProject/CMakeFiles/CMakeOutput.log".

Found libraries can't be linked before creating the CoreLib

It leads to an unexpected behavior where a user can only partially find libraries before using them in a custom target, be it a library or an executable.

It casts doubt on the way CoreLibs are created today, i.e. as part of creating a user target.
It'll probably be wiser to create them as part of a setup function, such as get_board_id, which must be called in order for the framework to behave correctly. This function will of course be renamed if CoreLib creation will be embedded in it.

Since it's a big change which directly affects the API, it'll probably be wiser to integrate it into v0.7, and not just as a patch.

Unable to use arduino libraries installed by library manager

I have tried both the Built-in/Arduino Libraries way and User/3rd Party Libraries way (as per the wiki documentation) to try and use a library that is installed with the Arduino IDE library manager.

The first way does not work because it looks like Arduino-CMake-NG only searches the main Arduino libraries that come with the IDE software and not the user installed libraries that are installed into the Sketchbook location using the library manager.

Provide means to override every Arduino-bound tool

Currently there are many elements in the framework which depend directly on Arduino specific tools, which don't always match those used by custom platforms.
One example is the avrdude uploading tool, which is used by Arduino but not by ESP32.

All such elements should have the ability to be "overridden" by a user-provided value, or, if possible, by a value stated in the platform.txt file.

Support for external boards

I tried your CMake toolchain and it works really nice for AVR based systems! However (just as you told in the documentation) it does not work for other boards.

Is there a roadmap on supporting other boards? My use case is the Adafruit nRF52

On Linux, if the PATH includes $ARDUINO_SDK_PATH, examples fail to make

On Linux, if the PATH includes $ARDUINO_SDK_PATH, examples fail to make

To reproduce:

  1. Add $ARDUINO_SDK_PATH to the linux PATH. This is something you might do if you still want to run the default arduino sdk.
  2. from $ARUINDO_SDK_PATH/build, run cmake -D CMAKE_TOOLCHAIN_FILE="../cmake/Arduino-Toolchain.cmake" ../examples
  3. run make

The error I see is

[ 35%] Building CXX object arduino-library/CMakeFiles/Ethernet.dir/home/andrew/software/arduino-sdk/arduino-1.8.7/libraries/Ethernet/src/Dhcp.cpp.obj
In file included from /home/andrew/software/arduino-sdk/arduino-1.8.7/libraries/Ethernet/src/Dhcp.cpp:7:0:
/home/andrew/software/arduino-sdk/arduino-1.8.7/libraries/Ethernet/src/utility/w5100.h:18:17: fatal error: SPI.h: No such file or directory

I have a fix that I'll pull request. Disclaimer - I'm new to CMAKE and Ardunino-CMake. I don't know if my fix is the best way to do this.

Cache Arduino SDK in Travis-CI builds

Travis-CI has the ability to cache downloaded packages between builds to save some time and network traffic.
We should use it to cache the Arduino SDK, as downloading and installing it takes most of the build's traffic and time.

Problem with linking Wire lib

I have build problem with project using Wire lib:

CMakeLists.txt

cmake_minimum_required(VERSION 3.8)

set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/Arduino-Toolchain.cmake)

project(lcd LANGUAGES C CXX ASM)

get_board_id(board_id mega atmega2560)

add_arduino_executable(lcd ${board_id} src/lcd.cpp)

find_arduino_library(crystal LiquidCrystal_I2C ${board_id} 3RD_PARTY)
link_arduino_library(lcd crystal ${board_id})

src/lcd.cpp

#include <Arduino.h>

#include <LiquidCrystal_I2C.h>

#define LCD_ADDRESS     0x27
#define LCD_COLUMNS     20
#define LCD_ROWS        4

LiquidCrystal_I2C lcd(LCD_ADDRESS, LCD_COLUMNS, LCD_ROWS);

void setup() {
    Serial.begin(9600);
    lcd.begin(LCD_COLUMNS, LCD_ROWS);
    lcd.clear();
}

void loop() {
}

Library LiquidCrystal_I2C use Wire library and it should be linked to executable, but there is an linking error:

  • make
Scanning dependencies of target mega_atmega2560_core_lib
[  3%] Building C object CMakeFiles/mega_atmega2560_core_lib.dir/opt/arduino/hardware/arduino/avr/cores/arduino/WInterrupts.c.obj
[  6%] Building C object CMakeFiles/mega_atmega2560_core_lib.dir/opt/arduino/hardware/arduino/avr/cores/arduino/hooks.c.obj
[  9%] Building C object CMakeFiles/mega_atmega2560_core_lib.dir/opt/arduino/hardware/arduino/avr/cores/arduino/wiring.c.obj
[ 12%] Building C object CMakeFiles/mega_atmega2560_core_lib.dir/opt/arduino/hardware/arduino/avr/cores/arduino/wiring_analog.c.obj
[ 15%] Building C object CMakeFiles/mega_atmega2560_core_lib.dir/opt/arduino/hardware/arduino/avr/cores/arduino/wiring_digital.c.obj
[ 18%] Building C object CMakeFiles/mega_atmega2560_core_lib.dir/opt/arduino/hardware/arduino/avr/cores/arduino/wiring_pulse.c.obj
[ 21%] Building C object CMakeFiles/mega_atmega2560_core_lib.dir/opt/arduino/hardware/arduino/avr/cores/arduino/wiring_shift.c.obj
[ 25%] Building CXX object CMakeFiles/mega_atmega2560_core_lib.dir/opt/arduino/hardware/arduino/avr/cores/arduino/CDC.cpp.obj
[ 28%] Building CXX object CMakeFiles/mega_atmega2560_core_lib.dir/opt/arduino/hardware/arduino/avr/cores/arduino/HardwareSerial.cpp.obj
[ 31%] Building CXX object CMakeFiles/mega_atmega2560_core_lib.dir/opt/arduino/hardware/arduino/avr/cores/arduino/HardwareSerial0.cpp.obj
[ 34%] Building CXX object CMakeFiles/mega_atmega2560_core_lib.dir/opt/arduino/hardware/arduino/avr/cores/arduino/HardwareSerial1.cpp.obj
[ 37%] Building CXX object CMakeFiles/mega_atmega2560_core_lib.dir/opt/arduino/hardware/arduino/avr/cores/arduino/HardwareSerial2.cpp.obj
[ 40%] Building CXX object CMakeFiles/mega_atmega2560_core_lib.dir/opt/arduino/hardware/arduino/avr/cores/arduino/HardwareSerial3.cpp.obj
[ 43%] Building CXX object CMakeFiles/mega_atmega2560_core_lib.dir/opt/arduino/hardware/arduino/avr/cores/arduino/IPAddress.cpp.obj
[ 46%] Building CXX object CMakeFiles/mega_atmega2560_core_lib.dir/opt/arduino/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp.obj
[ 50%] Building CXX object CMakeFiles/mega_atmega2560_core_lib.dir/opt/arduino/hardware/arduino/avr/cores/arduino/Print.cpp.obj
[ 53%] Building CXX object CMakeFiles/mega_atmega2560_core_lib.dir/opt/arduino/hardware/arduino/avr/cores/arduino/Stream.cpp.obj
[ 56%] Building CXX object CMakeFiles/mega_atmega2560_core_lib.dir/opt/arduino/hardware/arduino/avr/cores/arduino/Tone.cpp.obj
[ 59%] Building CXX object CMakeFiles/mega_atmega2560_core_lib.dir/opt/arduino/hardware/arduino/avr/cores/arduino/USBCore.cpp.obj
[ 62%] Building CXX object CMakeFiles/mega_atmega2560_core_lib.dir/opt/arduino/hardware/arduino/avr/cores/arduino/WMath.cpp.obj
[ 65%] Building CXX object CMakeFiles/mega_atmega2560_core_lib.dir/opt/arduino/hardware/arduino/avr/cores/arduino/WString.cpp.obj
[ 68%] Building CXX object CMakeFiles/mega_atmega2560_core_lib.dir/opt/arduino/hardware/arduino/avr/cores/arduino/abi.cpp.obj
[ 71%] Building CXX object CMakeFiles/mega_atmega2560_core_lib.dir/opt/arduino/hardware/arduino/avr/cores/arduino/main.cpp.obj
[ 75%] Building CXX object CMakeFiles/mega_atmega2560_core_lib.dir/opt/arduino/hardware/arduino/avr/cores/arduino/new.cpp.obj
[ 78%] Building ASM object CMakeFiles/mega_atmega2560_core_lib.dir/opt/arduino/hardware/arduino/avr/cores/arduino/wiring_pulse.S.obj
[ 81%] Linking CXX static library libmega_atmega2560_core_lib.a
[ 81%] Built target mega_atmega2560_core_lib
Scanning dependencies of target Wire
[ 84%] Building CXX object CMakeFiles/Wire.dir/opt/arduino/hardware/arduino/avr/libraries/Wire/src/Wire.cpp.obj
[ 87%] Linking CXX static library libWire.a
[ 87%] Built target Wire
Scanning dependencies of target crystal
[ 90%] Building CXX object CMakeFiles/crystal.dir/libraries/LiquidCrystal_I2C/LiquidCrystal_I2C.cpp.obj
[ 93%] Linking CXX static library libcrystal.a
[ 93%] Built target crystal
Scanning dependencies of target lcd
[ 96%] Building CXX object CMakeFiles/lcd.dir/src/lcd.cpp.obj
[100%] Linking CXX executable lcd.elf
/tmp/ccNGShVI.ltrans0.ltrans.o: In function `write':
/opt/arduino/hardware/arduino/avr/libraries/Wire/src/Wire.cpp:228: undefined reference to `twi_transmit'
/opt/arduino/hardware/arduino/avr/libraries/Wire/src/Wire.cpp:210: undefined reference to `twi_transmit'
/tmp/ccNGShVI.ltrans0.ltrans.o: In function `endTransmission':
/opt/arduino/hardware/arduino/avr/libraries/Wire/src/Wire.cpp:173: undefined reference to `twi_writeTo'
collect2: error: ld returned 1 exit status
CMakeFiles/lcd.dir/build.make:98: recipe for target 'lcd.elf' failed
make[2]: *** [lcd.elf] Error 1
CMakeFiles/Makefile2:144: recipe for target 'CMakeFiles/lcd.dir/all' failed
make[1]: *** [CMakeFiles/lcd.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

All files are available at https://github.com/andrzejo/cmake-test

Include library header from another library

Hello, I can't understand where problem.
I prepared example project https://github.com/ustisha/CMake

OS: Windows 10
Platform: Arduino
Platform SDK Version: [Arduino SDK version 1.8.8]
IDE: CLion
MinGW: 5.0
CMake: Bundled 3.13.2

Libararies is

Main problem is

In file included from C:\Arduino\CMake\test1\libraries\DallasTemperature\DallasTemperature.cpp:6:0:
C:\Arduino\CMake\test1\libraries\DallasTemperature\DallasTemperature.h:25:21: fatal error: OneWire.h: No such file or directory
compilation terminated.

When i change include in test1/libraries/DallasTemperature/DallasTemperature.h from <OneWire.h> to #include <../OneWire/OneWire.h> compile success. Should I change it? Will be great if i can use libraries wihtout changes (as is)

Missing ARDUINO_ARCH_<ARCH> define

Looks like the makefiles generated do not include the ARDUINO_ARCH_AVR define that is needed by some libs. I looked at the raw arduino ide build commands and they seem to have it.

/Applications/arduino.app/Contents/Java/hardware/tools/avr/bin/avr-g++   -I/Users/machado/Dropbox/Arduino/libraries/Adafruit_GFX -I/Users/machado/Dropbox/Arduino/libraries/Adafruit_GFX/Fonts -I/Users/machado/Dropbox/Arduino/libraries/Adafruit_NeoMatrix -I/Users/machado/Dropbox/Arduino/libraries/Adafruit_NeoPixel -I/Users/machado/Dropbox/Arduino/libraries/Adafruit_SSD1306 -I/Users/machado/Dropbox/Arduino/libraries/Arduino-SerialCommand -I/Users/machado/Dropbox/Arduino/libraries/ArduinoNunchuk -I/Users/machado/Dropbox/Arduino/libraries/EnableInterrupt -I/Users/machado/Dropbox/Arduino/libraries/EnableInterrupt/utility -I/Users/machado/Dropbox/Arduino/libraries/FastAPI_LED -I/Users/machado/Dropbox/Arduino/libraries/Keypad/src -I/Users/machado/Dropbox/Arduino/libraries/MFRC522/src -I/Users/machado/Dropbox/Arduino/libraries/MPU9250 -I/Users/machado/Dropbox/Arduino/libraries/MQTT/src -I/Users/machado/Dropbox/Arduino/libraries/MQTT/src/lib -I/Users/machado/Dropbox/Arduino/libraries/PinChangeInterrupt/src -I/Users/machado/Dropbox/Arduino/libraries/Skywriter -I/Users/machado/Dropbox/Arduino/libraries/TimerOne -I/Users/machado/Dropbox/Arduino/libraries/TimerOne/config -I/Users/machado/Dropbox/Arduino/libraries/Zumo32U4 -I/Users/machado/Dropbox/Arduino/libraries/grbl -I/Applications/arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino -I/Applications/arduino.app/Contents/Java/hardware/arduino/avr/variants/standard -I/Applications/arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/src -I/Applications/arduino.app/Contents/Java/hardware/arduino/avr/libraries/Wire/src -I/Applications/arduino.app/Contents/Java/hardware/arduino/avr/libraries/eeprom/src  -g   -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10803 "-DARDUINO_AVR_UNO " -o CMakeFiles/Skywriter.dir/Users/machado/Dropbox/Arduino/libraries/PinChangeInterrupt/src/PinChangeInterrupt.cpp.obj -c /Users/machado/Dropbox/Arduino/libraries/PinChangeInterrupt/src/PinChangeInterrupt.cpp
In file included from /Users/machado/Dropbox/Arduino/libraries/PinChangeInterrupt/src/PinChangeInterrupt.cpp:24:0:
/Users/machado/Dropbox/Arduino/libraries/PinChangeInterrupt/src/PinChangeInterrupt.h:33:2: error: #error This library can only be used with AVR
 #error This library can only be used with AVR
  ^
make[2]: *** [CMakeFiles/Skywriter.dir/Users/machado/Dropbox/Arduino/libraries/PinChangeInterrupt/src/PinChangeInterrupt.cpp.obj] Error 1
make[1]: *** [CMakeFiles/Skywriter.dir/all] Error 2
make: *** [all] Error 2

Take new approach to automatically find Arduino SDK path

The current approach attempts to find a program named arduino, which apparently not always resides under the real SDK path, but in a different path instead. See #13 for that.

A quick fix has been integrated in #14, which also suggested to take a new approach:
We should seek the lib/version.txt file as it always resides under the real SDK path, on all platforms.

Arduino SDK not automatically detected on OSX

CMake Error at cmake/Platform/Other/ArduinoSDKSeeker.cmake:32 (message):
  Couldn't find Arduino SDK path - Is it in a non-standard location?

  If so, please set the ARDUINO_SDK_PATH CMake-Variable
Call Stack (most recent call first):
  cmake/Arduino-Toolchain.cmake:66 (find_arduino_sdk)
  /Applications/CMake.app/Contents/share/cmake-3.12/Modules/CMakeDetermineSystem.cmake:91 (include)
  CMakeLists.txt:3 (project)


-- Configuring incomplete, errors occurred!
See also "/Users/machado/tmp/MyProject/CMakeFiles/CMakeOutput.log".

When I set the system environment variable ARDUINO_SDK_PATH to /Applications/Arduino.app/Contents/Java it is able to finish cmake, but there is some strange output:

-- Arduino SDK version 1.8.3: ARDUINO_SDK_PATH-NOTFOUND
-- Determined Platform Header: /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h
-- Arduino SDK version 1.8.3: ARDUINO_SDK_PATH-NOTFOUND
-- Determined Platform Header: /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h
-- Arduino SDK version 1.8.3: ARDUINO_SDK_PATH-NOTFOUND
-- Determined Platform Header: /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/machado/tmp/MyProject

Build tries to build all .c files of a library which might not have all the dependent headers available

When using the find_arduino_library/link_arduino_library to include a library from my arduino sketchbook location, it looks like the build is trying to grab all .c files that are in the library. Sometimes libraries include tools or example code that might depend on headers that are not on the system, leading to a failed build, even though the code/headers for the library itself are just fine.

For example, I am using the Adafruit_GFX library that includes a font utility that depends on some freetype libs. The actual Adafruit_GFX lib does not depend on the font utility, its just there in case you want to use it, but since the utility cannot be built on my system (freetype headers unavailable) it causes my project build to fail:

[ 34%] Building C object CMakeFiles/Skywriter.dir/Users/machado/Dropbox/Arduino/libraries/Adafruit_GFX/fontconvert/fontconvert.c.obj
/Applications/arduino.app/Contents/Java/hardware/tools/avr/bin/avr-gcc  -I/Users/machado/Dropbox/Arduino/libraries/Adafruit_GFX -I/Users/machado/Dropbox/Arduino/libraries/Adafruit_GFX/Fonts -I/Users/machado/Dropbox/Arduino/libraries/Adafruit_NeoMatrix -I/Users/machado/Dropbox/Arduino/libraries/Adafruit_NeoPixel -I/Users/machado/Dropbox/Arduino/libraries/Adafruit_SSD1306 -I/Users/machado/Dropbox/Arduino/libraries/Arduino-SerialCommand -I/Users/machado/Dropbox/Arduino/libraries/ArduinoNunchuk -I/Users/machado/Dropbox/Arduino/libraries/EnableInterrupt -I/Users/machado/Dropbox/Arduino/libraries/EnableInterrupt/utility -I/Users/machado/Dropbox/Arduino/libraries/FastAPI_LED -I/Users/machado/Dropbox/Arduino/libraries/Keypad/src -I/Users/machado/Dropbox/Arduino/libraries/MFRC522/src -I/Users/machado/Dropbox/Arduino/libraries/MPU9250 -I/Users/machado/Dropbox/Arduino/libraries/MQTT/src -I/Users/machado/Dropbox/Arduino/libraries/MQTT/src/lib -I/Users/machado/Dropbox/Arduino/libraries/PinChangeInterrupt/src -I/Users/machado/Dropbox/Arduino/libraries/Skywriter -I/Users/machado/Dropbox/Arduino/libraries/TimerOne -I/Users/machado/Dropbox/Arduino/libraries/TimerOne/config -I/Users/machado/Dropbox/Arduino/libraries/Zumo32U4 -I/Users/machado/Dropbox/Arduino/libraries/grbl -I/Applications/arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino -I/Applications/arduino.app/Contents/Java/hardware/arduino/avr/variants/standard -I/Applications/arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/src -I/Applications/arduino.app/Contents/Java/hardware/arduino/avr/libraries/Wire/src -I/Applications/arduino.app/Contents/Java/hardware/arduino/avr/libraries/eeprom/src  -g   -o CMakeFiles/Skywriter.dir/Users/machado/Dropbox/Arduino/libraries/Adafruit_GFX/fontconvert/fontconvert.c.obj   -c /Users/machado/Dropbox/Arduino/libraries/Adafruit_GFX/fontconvert/fontconvert.c
/Users/machado/Dropbox/Arduino/libraries/Adafruit_GFX/fontconvert/fontconvert.c:23:22: fatal error: ft2build.h: No such file or directory
 #include <ft2build.h>
                      ^
compilation terminated.
make[2]: *** [CMakeFiles/Skywriter.dir/Users/machado/Dropbox/Arduino/libraries/Adafruit_GFX/fontconvert/fontconvert.c.obj] Error 1
make[1]: *** [CMakeFiles/Skywriter.dir/all] Error 2
make: *** [all] Error 2

Arduino CMake cannot find build chain for new project on OSX

  • Already have Arduino IDE 1.8.3 installed in /Applications
  • git cloned Arduino-CMake-NG to /Users/machado/git/Arduino-CMake-NG
  • Created ~/tmp/MyProject with the following:

CMakeLists.txt:

# Define CMake's minimum version (must-do) and the project's name and supported languages
cmake_minimum_required(VERSION 3.8)
project(Hello_World LANGUAGES C CXX ASM)

# Call a framework utility function, passing it information about the hardware board that will
# be used - This function returns a structure known only to the framework
get_board_id(board_id uno)

# Create an executable suitable for the Arduino firmware using CMake-style target-creation
add_arduino_executable(Hello_World ${board_id} helloWorld.cpp)
# Upload the created target through a connected Serial Port (Where your board is connected to)
#upload_arduino_target(Hello_World "${board_id}" [PORT])

helloWorld.cpp:

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO 
  it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
  the correct LED pin independent of which board is used.
  If you want to know what pin the on-board LED is connected to on your Arduino model, check
  the Technical Specs of your board  at https://www.arduino.cc/en/Main/Products
  
  This example code is in the public domain.

  modified 8 May 2014
  by Scott Fitzgerald
  
  modified 2 Sep 2016
  by Arturo Guadalupi
  
  modified 8 Sep 2016
  by Colby Newman
*/


// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

And then tried to build:

[machado@mbp ~/tmp/MyProject]$ cmake -DCMAKE_TOOLCHAIN_FILE=/Users/machado/git/Arduino-CMake-NG/cmake/Arduino-Toolchain.cmake
-- The C compiler identification is AppleClang 9.1.0.9020039
-- The CXX compiler identification is AppleClang 9.1.0.9020039
-- The ASM compiler identification is AppleClang
-- Didn't find assembler
CMake Error at /Users/machado/git/Arduino-CMake-NG/cmake/Platform/System/AvrToolsFinder.cmake:11 (message):
  avr-objcopy program is required by the toolchain but can't be found
Call Stack (most recent call first):
  /Users/machado/git/Arduino-CMake-NG/cmake/Platform/System/BuildSystemInitializer.cmake:8 (find_tool_avr_objcopy)
  /Users/machado/git/Arduino-CMake-NG/cmake/Platform/System/BuildSystemInitializer.cmake:21 (find_required_platform_tools)
  /Users/machado/git/Arduino-CMake-NG/cmake/Platform/Arduino.cmake:34 (initialize_build_system)
  /Applications/CMake.app/Contents/share/cmake-3.12/Modules/CMakeSystemSpecificInformation.cmake:26 (include)
  CMakeLists.txt:3 (project)


CMake Error at CMakeLists.txt:3 (project):
  No CMAKE_ASM_COMPILER could be found.

  Tell CMake where to find the compiler by setting either the environment
  variable "ASM" or the CMake cache entry CMAKE_ASM_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.


-- Configuring incomplete, errors occurred!
See also "/Users/machado/tmp/MyProject/CMakeFiles/CMakeOutput.log".

Add ability to use custom build tools

Currently the only supported build tool is avr-gcc, which is used by the native Arduino SDK.
Other platforms however, such as the ESP32, use different build tools (xtensa in the case of ESP32).
These should also be supported.

One way to allow this is to give the user the ability to pass the name/pattern of the build tool to the framework, which will use it in the Toolchain file when finding all required build tools (such as compilers).
Another option is to add support specifically for ESP32, since it's a very different platform, but that's probably not the preferred option as it's not robust enough.

Edit: Depends on #12.

Generate function prototypes when converting sketches

The Arduino Build-Process Specification specifies:

Prototypes are generated for all function definitions in .ino files that don't already have prototypes. In some rare cases prototype generation may fail for some functions. To work around this, you can provide your own prototypes for these functions.

In their terminology, prototypes are simply function declarations, or signatures.
For example, given the following sketch file:

void setup()
{
    foo(5, 1);
}

void loop() {}

void foo(int pin, int iterations) 
{
    // Do something with arguments
}

The following prototype/declaration will be generated above the setup function in the converted source:

void foo(int pin, int iterations);

This is necessary for a source file to be valid and compile as required - Otherwise the compiler will complain it can't find declarations for the function symbol (foo in our example).

RegisterHardwarePlatform doesn't work

Previous versions of Arduino CMAKE had an API you could use to supply your own distribution of the Arduino embedded software. It looks like pieces of this have made it into this new version, but the functionality is missing. It would be nice if this API was added back in.

Undefined reference error when linking 3rd party libraries.

OS: macOS
OS Version: 10.14.2
Platform: Arduino
Platform SDK Version: [Arduino SDK version 1.8.8]

When trying to link 3rd party libraries into my project, every time I instantiate an object I receive this error.

====================[ Build | auto_car | Default ]==============================
/usr/local/bin/cmake --build /Users/Dominic/Projects/Code/AutoCar/build --target auto_car -- -j 4
[ 75%] Built target mega_atmega2560_core_lib
[ 78%] Built target adafruit_bno055
[ 81%] Built target adafruit_sensor
[ 90%] Built target Wire
[ 93%] Built target adafruit_vl53l0x
[ 96%] Linking CXX executable auto_car.elf
/var/folders/vh/n3x031n547v4qhvxs1p_wtf00000gn/T//ccSQ9BRK.ltrans0.ltrans.o: In function `__static_initialization_and_destruction_0':
/Users/Dominic/Projects/Code/AutoCar/src/auto_car.cpp:9: undefined reference to `Adafruit_BNO055::Adafruit_BNO055(long, unsigned char)'
/var/folders/vh/n3x031n547v4qhvxs1p_wtf00000gn/T//ccSQ9BRK.ltrans0.ltrans.o: In function `setup':
/Users/Dominic/Projects/Code/AutoCar/src/auto_car.cpp:16: undefined reference to `Adafruit_VL53L0X::begin(unsigned char, bool, TwoWire*)'
/Users/Dominic/Projects/Code/AutoCar/src/auto_car.cpp:20: undefined reference to `Adafruit_BNO055::begin(Adafruit_BNO055::adafruit_bno055_opmode_t)'
collect2: error: ld returned 1 exit status
make[3]: *** [auto_car.elf] Error 1
make[2]: *** [CMakeFiles/auto_car.dir/all] Error 2
make[1]: *** [CMakeFiles/auto_car.dir/rule] Error 2
make: *** [auto_car] Error 2

My CMakeLists.txt file is as such.

cmake_minimum_required(VERSION 3.13.3)
project(auto_car LANGUAGES C CXX)

set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/Arduino-Toolchain.cmake)

get_board_id(board_id mega atmega2560)

add_arduino_executable(auto_car ${board_id} src/auto_car.cpp)

link_platform_library(auto_car Wire ${board_id})

add_arduino_library(adafruit_sensor ${board_id} libs/Adafruit_Sensor/src/Adafruit_Sensor.h)
add_arduino_library(adafruit_bno055 ${board_id} libs/Adafruit_BNO055/src/Adafruit_BNO055.h)
add_arduino_library(adafruit_vl53l0x ${board_id} libs/Adafruit_VL53L0X/src/Adafruit_VL53L0X.h)

link_arduino_library(auto_car adafruit_sensor ${board_id})
link_arduino_library(auto_car adafruit_bno055 ${board_id})
link_arduino_library(auto_car adafruit_vl53l0x ${board_id})

And the source file is as such.

#include <Arduino.h>

#include <Adafruit_BNO055.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_VL53L0X.h>

#define BAUD_RATE 9600

Adafruit_BNO055 imuSensor = Adafruit_BNO055(55);
Adafruit_VL53L0X lidarSensor = Adafruit_VL53L0X();

void setup()
{
    Serial.begin(BAUD_RATE);

    if (!lidarSensor.begin()) {
        Serial.println("Error: Lidar sensor is not setup properly.");
    }

    if (!imuSensor.begin()) {
        Serial.println("Error: IMU sensor is not setup properly.");
    }
}

void loop()
{
    // Loop
}

The project can be cloned here. I have already tried moving the header/cpp files of the libraries used directly into the properly named folder without the src subdirectory folder. The object instantiation is as given by the examples in the libraries themselves. I've also tried passing the toolchain as a command line argument. Any help would be much appreciated.

Thanks!

Unable to use more than one source file in a program

The #25 PR unveiled a critical bug where an Arduino program created with add_arduino_executable can't have more than one source files.
The reason for this is that the function attempted to be very similar to CMake's add_executable, however, the CMake function is actually an internal function written in C++, while our function is pure CMake.
It creates a situation where variable arguments in a function can't be "just passed", but instead need to be parsed, preferably by CMake's internal cmake_parse_arguments function.

A PR with a fix should be available soon.

Infer which libraries to use based on #includes

Hi,

I'm trying to use this tool-chain to build my complex Arduino project with multiple sources and custom libraries. I have a folder apart from the SDK's sketchbook where I store all the custom libraries I created along the past years, and are used across different projects... However, when I try to compile my project with this framework, it doesn't automatically find these libraries in this folder, though it is sym-linked to a "libraries" folder on the CMake project root... If I manually link them using "find_arduino_library" and "link_arduino_library" it finds them and compiles them, however I have numerous libraries and this manually linking becomes cumbersome... is there an automatic way of doing this?

Apart from this, very nice work developing and maintaining this project! Thank you for your time!

Regards,
Alexandre

Failure to create library without sources

A library should be able to be created without sources at first, passing them later using CMake's target_sources function.

Currently, calling the add_arduino_library function without passing any sources simply fails CMake.

Add support for Travis-CI

Currently only the AppVeyor CI is officially supported, which covers Windows builds.
Travis-CI should be supported as well to cover both Linux and OS X builds.

Add Programmers support

Add ability to use platform's programmers.
This should be done through a public API function.

Refactor upload API

Currently the upload API requires users to comment-out the upload function if they simply intend to build their project, otherwise the build will fail as it depends on the upload target.
This is a really bad and inconvenient API, thus it should be changed.

The old arduino-cmake project defined a target for uploading, which users could then build whenever they need to upload their code besides building it.
Similar approach should be taken here.

Problem with ARDUINO_CMAKE_PLATFORM_PROPERTIES_FILE_PATH-NOTFOUND when building Hello_World

I am a newby and try to get the HelloWorld-example up and running. I run Ubuntu (Windows Subsystem for Linux) and I cloned the CMake-NG repo and created a CMakeLists.txt file as follows:

cmake_minimum_required(VERSION 3.8.2)
project(Hello_World)
get_board_id(board_id nano atmega328)
add_arduino_executable(Hello_World ${board_id} helloWorld.cpp)

When I call cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/Arduino-CMake-NG/cmake/Arduino-Toolchain.cmake .. I get the following:

-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Arduino SDK version 2:1.0.5+dfsg2-4
: /usr/share/arduino
-- Determined Platform Header:
CMake Error at cmake/Arduino-CMake-NG/cmake/Platform/Properties/PropertiesReader.cmake:25 (file):
  file STRINGS file
  "/home/userx/Workspaces/arduino/playground/ARDUINO_CMAKE_PLATFORM_PROPERTIES_FILE_PATH-NOTFOUND"
  cannot be read.
Call Stack (most recent call first):
  cmake/Arduino-CMake-NG/cmake/Platform/System/PlatformInitializer.cmake:26 (read_properties_from_file)
  cmake/Arduino-CMake-NG/cmake/Platform/System/PlatformInitializer.cmake:60 (initialize_platform_properties)
  cmake/Arduino-CMake-NG/cmake/Platform/System/BuildSystemInitializer.cmake:31 (initialize_arduino_platform)
  cmake/Arduino-CMake-NG/cmake/Platform/Arduino.cmake:34 (initialize_build_system)
  /usr/share/cmake-3.12/Modules/CMakeSystemSpecificInformation.cmake:26 (include)
  CMakeLists.txt:3 (project)


-- Arduino SDK version 2:1.0.5+dfsg2-4
: /usr/share/arduino
-- Determined Platform Header:
CMake Error at cmake/Arduino-CMake-NG/cmake/Platform/Properties/PropertiesReader.cmake:25 (file):
  file STRINGS file
  "/home/userx/Workspaces/arduino/playground/ARDUINO_CMAKE_PLATFORM_PROPERTIES_FILE_PATH-NOTFOUND"
  cannot be read.
Call Stack (most recent call first):
  cmake/Arduino-CMake-NG/cmake/Platform/System/PlatformInitializer.cmake:26 (read_properties_from_file)
  cmake/Arduino-CMake-NG/cmake/Platform/System/PlatformInitializer.cmake:60 (initialize_platform_properties)
  cmake/Arduino-CMake-NG/cmake/Platform/System/BuildSystemInitializer.cmake:31 (initialize_arduino_platform)
  cmake/Arduino-CMake-NG/cmake/Platform/Arduino.cmake:34 (initialize_build_system)
  /usr/share/cmake-3.12/Modules/CMakeCInformation.cmake:66 (include)
  CMakeLists.txt:3 (project)

-- Check for working C compiler: /usr/share/arduino/hardware/tools/avr/bin/avr-gcc
CMake Error at /home/userx/Workspaces/arduino/playground/cmake/Arduino-CMake-NG/cmake/Platform/Properties/PropertiesReader.cmake:25 (file):
  file STRINGS file
  "/home/userx/Workspaces/arduino/playground/bin/CMakeFiles/CMakeTmp/ARDUINO_CMAKE_PLATFORM_PROPERTIES_FILE_PATH-NOTFOUND"
  cannot be read.
Call Stack (most recent call first):
  /home/userx/Workspaces/arduino/playground/cmake/Arduino-CMake-NG/cmake/Platform/System/PlatformInitializer.cmake:26 (read_properties_from_file)
  /home/userx/Workspaces/arduino/playground/cmake/Arduino-CMake-NG/cmake/Platform/System/PlatformInitializer.cmake:60 (initialize_platform_properties)
  /home/userx/Workspaces/arduino/playground/cmake/Arduino-CMake-NG/cmake/Platform/System/BuildSystemInitializer.cmake:31 (initialize_arduino_platform)
  /home/userx/Workspaces/arduino/playground/cmake/Arduino-CMake-NG/cmake/Platform/Arduino.cmake:34 (initialize_build_system)
  /usr/share/cmake-3.12/Modules/CMakeSystemSpecificInformation.cmake:26 (include)
  /home/userx/Workspaces/arduino/playground/bin/CMakeFiles/CMakeTmp/CMakeLists.txt:3 (project)


CMake Error at /home/userx/Workspaces/arduino/playground/cmake/Arduino-CMake-NG/cmake/Platform/Properties/PropertiesReader.cmake:25 (file):
  file STRINGS file
  "/home/userx/Workspaces/arduino/playground/bin/CMakeFiles/CMakeTmp/ARDUINO_CMAKE_PLATFORM_PROPERTIES_FILE_PATH-NOTFOUND"
  cannot be read.
Call Stack (most recent call first):
  /home/userx/Workspaces/arduino/playground/cmake/Arduino-CMake-NG/cmake/Platform/System/PlatformInitializer.cmake:26 (read_properties_from_file)
  /home/userx/Workspaces/arduino/playground/cmake/Arduino-CMake-NG/cmake/Platform/System/PlatformInitializer.cmake:60 (initialize_platform_properties)
  /home/userx/Workspaces/arduino/playground/cmake/Arduino-CMake-NG/cmake/Platform/System/BuildSystemInitializer.cmake:31 (initialize_arduino_platform)
  /home/userx/Workspaces/arduino/playground/cmake/Arduino-CMake-NG/cmake/Platform/Arduino.cmake:34 (initialize_build_system)
  /usr/share/cmake-3.12/Modules/CMakeCInformation.cmake:66 (include)
  /home/userx/Workspaces/arduino/playground/bin/CMakeFiles/CMakeTmp/CMakeLists.txt:3 (project)


CMake Warning:
  Value of ARDUINO_CMAKE_SDK_VERSION contained a newline; truncating


CMake Warning:
  Value of ARDUINO_CMAKE_SDK_VERSION_PATCH contained a newline; truncating


CMake Warning:
  Value of runtime_ide_version contained a newline; truncating


CMake Error at /usr/share/cmake-3.12/Modules/CMakeTestCCompiler.cmake:37 (try_compile):
  Failed to configure test project build system.
Call Stack (most recent call first):
  CMakeLists.txt:3 (project)


-- Configuring incomplete, errors occurred!
See also "/home/userx/Workspaces/arduino/playground/bin/CMakeFiles/CMakeOutput.log".
CMake Warning:
  Value of ARDUINO_CMAKE_SDK_VERSION contained a newline; truncating


CMake Warning:
  Value of ARDUINO_CMAKE_SDK_VERSION_PATCH contained a newline; truncating


CMake Warning:
  Value of runtime_ide_version contained a newline; truncating

My cmake version is 3.12.1.

Any help is appreciated and many thanks beforehand.

Cache Arduino SDK in AppVeyor builds

AppVeyor has the ability to cache downloaded packages between builds to save some time and network traffic.
We should use it to cache the Arduino SDK, as downloading and installing it takes most of the build's traffic and time.

SPI library not found

Hello,
I have a library that uses the Arduino SPI library.
After realising #include<SPI.h> doesn't work i tried adding it maually by adding
find_arduino_library(spi_lib SPI ${board_id})
link_arduino_library(main spi_lib ${board_id})
but I just got the error:
CMake Error at cmake/Platform/Libraries/LibrariesFinder.cmake:38 (message):
Couldn't find library named Spi

So how do i use the SPI library located at:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI

Problem when with determining link language.

OS: Linux
Distribution: Ubuntu
OS Version: 18.04.1
Platform: Arduino
Platform SDK Version: [Arduino SDK version 1.8.8]

I get this error when trying to generate Makefile. Not sure how to debug it.

/home/thor/bin/clion-2018.2.4/bin/cmake/linux/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=cmake/Arduino-Toolchain.cmake -G "CodeBlocks - Unix Makefiles" /home/thor/Documents/from-scratch/software/webcam/arduino/encoder
-- Arduino SDK version 1.8.8: /home/thor/bin/arduino
-- Determined Platform Header: /home/thor/bin/arduino/hardware/arduino/avr/cores/arduino/Arduino.h
-- Arduino SDK version 1.8.8: /home/thor/bin/arduino
-- Determined Platform Header: /home/thor/bin/arduino/hardware/arduino/avr/cores/arduino/Arduino.h
-- Arduino SDK version 1.8.8: /home/thor/bin/arduino
-- Determined Platform Header: /home/thor/bin/arduino/hardware/arduino/avr/cores/arduino/Arduino.h
-- Configuring done
CMake Error: Cannot determine link language for target "nano_atmega328old_core_lib".
CMake Error: CMake can not determine linker language for target: nano_atmega328old_core_lib
-- Generating done
-- Build files have been written to: /home/thor/Documents/from-scratch/software/webcam/arduino/encoder/cmake-build-debug

My CMakeLists.txt file:

cmake_minimum_required(VERSION 3.8.2)

project(e2)

# Call a framework utility function, passing it information about the hardware board that will be used - This function returns a structure known only to the framework
get_board_id(board_id nano atmega328old)

# Create an executable suitable for Arduino using CMake-style target-creation
add_arduino_executable(e2 ${board_id} encoder.cpp)
# Upload the created target through a connected Serial Port (Where your board is connected to)
upload_arduino_target(e2 "${board_id}" /dev/ttyUSB0)

CLion integration not working (include error)

Hello,

I tried to create a new CLion project and copied the 0.6 release at my project.

This is my CMakeLists.txt:

cmake_minimum_required(VERSION 3.12)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/Arduino-Toolchain.cmake)
project(Arduino LANGUAGES C)

get_board_id(board_id mega atmega2560)
add_arduino_executable(${PROJECT_NAME} ${board_id} main.c)
upload_arduino_target(${PROJECT_NAME} "${board_id}" COM3)

My folder structure is:
Arduino (CLion project root)

  • cmake (contains the whole 0.6 release)
  • CMakeLists.txt
  • main.c

Unfortunately I get this error.

/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" /Users/jens/Downloads/Arduino
CMake Error at cmake/Arduino-Toolchain.cmake:1 (include):
  include could not find load file:

    Platform/Other/ArduinoSDKSeeker.cmake
Call Stack (most recent call first):
  /Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.12/Modules/CMakeDetermineSystem.cmake:94 (include)
  CMakeLists.txt:3 (project)


CMake Error at cmake/Arduino-Toolchain.cmake:66 (find_arduino_sdk):
  Unknown CMake command "find_arduino_sdk".
Call Stack (most recent call first):
  /Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.12/Modules/CMakeDetermineSystem.cmake:94 (include)
  CMakeLists.txt:3 (project)


CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!

[Finished]

I couldn't find any solution on github. I already tried a cmake command line parameter instead of the set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/Arduino-Toolchain.cmake). This didn't help. I also tried different relative and absolute paths without success.

Can anyone help me?

Thank you :)

Document platform library usage

This type of libraries is currently missing from documentation.

This is required since their API is different than other libraries - they should be simply linked with their name, there's no need to find them and assign them to a target first.

Using additional board manager json files

I think I have a similar issue to #50 I'm a bit new to the arduino ecosystem so not sure exactly how this is supposed to work. That said I have a link https://dl.espressif.com/dl/package_esp32_index.json that I add to the Additional Boards Manager URLs field in Arduino IDE. This (based on a little bit of poking around) links eventually to https://github.com/espressif/arduino-esp32/blob/master/boards.txt which of course has the board that I need to find with get_board_id.

So the question is how am I supposed to access this?

  • Should I copy this into my boards.txt?
  • Install via IDE (doesn't seem to get found by cmake)
  • Other?

And follow up question, should we consider adding another function like add_additional_board_manager that downloads this file (and w/e else is needed to support) such that get_board_id would then just work?

An unfortunate series of roadblocks in a multiproject configuration

I have some issues using a multi-project structure for my project. In general, I have a root CMakeLists.txt with common configuration, from which I add subdirectories where my subprojects live. These subprojects are one executable (the main program) and a custom arduino library. The library is not packaged, and is developed as a part of the project.

I've hit a number of issues, worked around a couple, and finally hit a roadblock. These are the problems I hit:

  1. get_board_id fails if called before a project() call, preventing it from being used in the root file without creating a fake project with an `Unknown CMake command" fault.
/home/jarl/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/183.4139.25/bin/cmake/linux/bin/cmake -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" /home/jarl/Programming/Plantbuddy
CMake Error at CMakeLists.txt:11 (get_board_id):
  Unknown CMake command "get_board_id".


-- Configuring incomplete, errors occurred!

[Finished]
  1. find_arduino_library fails if called before an add_arduino_executable or add_arduino_library, preventing it from being used in the root file. Instead, it must be used in a subdirectory, making it unclear which libraries are available to which targets, and in what order to load them.
/home/jarl/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/183.4139.25/bin/cmake/linux/bin/cmake -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" /home/jarl/Programming/Plantbuddy
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Arduino SDK version 1.8.1: /opt/arduino-1.8.1
-- Determined Platform Header: /opt/arduino-1.8.1/hardware/arduino/avr/cores/arduino/Arduino.h
-- Arduino SDK version 1.8.1: /opt/arduino-1.8.1
-- Determined Platform Header: /opt/arduino-1.8.1/hardware/arduino/avr/cores/arduino/Arduino.h
-- Check for working C compiler: /opt/arduino-1.8.1/hardware/tools/avr/bin/avr-gcc
-- Check for working C compiler: /opt/arduino-1.8.1/hardware/tools/avr/bin/avr-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Arduino SDK version 1.8.1: /opt/arduino-1.8.1
-- Determined Platform Header: /opt/arduino-1.8.1/hardware/arduino/avr/cores/arduino/Arduino.h
-- Check for working CXX compiler: /opt/arduino-1.8.1/hardware/tools/avr/bin/avr-g++
-- Check for working CXX compiler: /opt/arduino-1.8.1/hardware/tools/avr/bin/avr-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at cmake/Platform/Targets/ArduinoCMakeLibraryTarget.cmake:60 (get_target_property):
  get_target_property() called with non-existent target "uno_core_lib".
Call Stack (most recent call first):
  cmake/Platform/Targets/PlatformLibraryTarget.cmake:63 (_link_arduino_cmake_library)
  cmake/Platform/Targets/ArduinoLibraryTarget.cmake:29 (link_platform_library)
  cmake/Platform/Libraries/LibrariesFinder.cmake:77 (add_arduino_library)
  CMakeLists.txt:17 (find_arduino_library)


CMake Error at cmake/Platform/Targets/ArduinoCMakeLibraryTarget.cmake:60 (get_target_property):
  get_target_property() called with non-existent target "uno_core_lib".
Call Stack (most recent call first):
  cmake/Platform/Targets/PlatformLibraryTarget.cmake:63 (_link_arduino_cmake_library)
  cmake/Platform/Targets/ArduinoLibraryTarget.cmake:29 (link_platform_library)
  cmake/Platform/Libraries/LibrariesFinder.cmake:77 (add_arduino_library)
  CMakeLists.txt:17 (find_arduino_library)


CMake Error at cmake/Platform/Targets/ArduinoLibraryTarget.cmake:66 (message):
  Core Library target doesn't exist.  This is bad and should be reported
Call Stack (most recent call first):
  CMakeLists.txt:19 (link_arduino_library)


-- Configuring incomplete, errors occurred!
See also "/home/jarl/Programming/Plantbuddy/cmake-build-debug/CMakeFiles/CMakeOutput.log".

[Finished]
  1. add_arduino_library fails completely if _sources is omitted, preventing target_sources from being used.
/home/jarl/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/183.4139.25/bin/cmake/linux/bin/cmake -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" /home/jarl/Programming/Plantbuddy
-- Arduino SDK version 1.8.1: /opt/arduino-1.8.1
-- Determined Platform Header: /opt/arduino-1.8.1/hardware/arduino/avr/cores/arduino/Arduino.h
-- Arduino SDK version 1.8.1: /opt/arduino-1.8.1
-- Determined Platform Header: /opt/arduino-1.8.1/hardware/arduino/avr/cores/arduino/Arduino.h
-- Arduino SDK version 1.8.1: /opt/arduino-1.8.1
-- Determined Platform Header: /opt/arduino-1.8.1/hardware/arduino/avr/cores/arduino/Arduino.h
CMake Error at cmake/Platform/Utilities/CMakeArgumentsUtils.cmake:21 (list):
  list GET given empty list
Call Stack (most recent call first):
  cmake/Platform/Utilities/CMakeArgumentsUtils.cmake:60 (_consume_reserved_arguments)
  cmake/Platform/Targets/ArduinoLibraryTarget.cmake:11 (parse_sources_arguments)
  microui/CMakeLists.txt:3 (add_arduino_library)


CMake Error at cmake/Platform/Utilities/CMakeArgumentsUtils.cmake:23 (if):
  if given arguments:

    "IN_LIST" "_reserved_options"

  Unknown arguments specified
Call Stack (most recent call first):
  cmake/Platform/Utilities/CMakeArgumentsUtils.cmake:60 (_consume_reserved_arguments)
  cmake/Platform/Targets/ArduinoLibraryTarget.cmake:11 (parse_sources_arguments)
  microui/CMakeLists.txt:3 (add_arduino_library)


-- Configuring incomplete, errors occurred!
See also "/home/jarl/Programming/Plantbuddy/cmake-build-debug/CMakeFiles/CMakeOutput.log".

[Finished]
  1. find_arduino_library fails once more if called after add_arduino_library with explicit source specification, with the same error as 2.

  2. Removing the libraries altogether to continue results in find_arduino_library failing when the executable attempts to link to it, due to it not being able to find the target.

The full source for the project scaffolding is available here: https://github.com/Nihlus/plantbuddy
Each problem stage has its own branch, so they can be individually inspected. In each branch succeeding roadblock-1, the workaround has been applied. roadblock-1 can be considered the ideal setup.

Any help with this would be much appreciated. I love being able to use CMake & CLion for my arduino projects, and in single-project mode, I haven't had any issues at all.

$<COMPILE_LANGUAGE:...> Unknown language - RASPBIAN

Hi,
my OS is Raspbian stretch
0 - I followed the steps into the "installation":

sudo apt-get install gcc-avr
sudo apt-get install binutils-avr
sudo apt-get install avr-libc 
sudo apt-get install avrdude

and installed arduino 1.8.7 from the arm tarball.
I installed cmake 3.8.2 from sources
1 - donwloaded Arduino-CMake-NG and extracted it in /home/pi
2 - cd ~/Arduino-CMake-NG-master/examples/blink-example
3 - cmake -DCMAKE_TOOLCHAIN_FILE=/home/pi/Arduino-CMake-NG-master/cmake/Arduino-Toolchain.cmake .
This is the output:

pi@raspberrypi:~/Arduino-CMake-NG-master/examples/blink-example $ cmake -DCMAKE_TOOLCHAIN_FILE=/home/pi/Arduino-CMake-NG-master/cmake/Arduino-Toolchain.cmake .
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Arduino SDK version 1.8.7: /usr/share/arduino
-- Determined Platform Header: /usr/share/arduino/hardware/arduino/avr/cores/arduino/Arduino.h
-- Arduino SDK version 1.8.7: /usr/share/arduino
-- Determined Platform Header: /usr/share/arduino/hardware/arduino/avr/cores/arduino/Arduino.h
-- Check for working C compiler: /usr/share/arduino/hardware/tools/avr/bin/avr-gcc
-- Check for working C compiler: /usr/share/arduino/hardware/tools/avr/bin/avr-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Arduino SDK version 1.8.7: /usr/share/arduino
-- Determined Platform Header: /usr/share/arduino/hardware/arduino/avr/cores/arduino/Arduino.h
-- Check for working CXX compiler: /usr/share/arduino/hardware/tools/avr/bin/avr-g++
-- Check for working CXX compiler: /usr/share/arduino/hardware/tools/avr/bin/avr-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
CMake Error at /home/pi/Arduino-CMake-NG-master/cmake/Platform/Other/TargetFlagsManager.cmake:13 (target_compile_options):
  Error evaluating generator expression:

    $<COMPILE_LANGUAGE:ASM>

  $<COMPILE_LANGUAGE:...> Unknown language.
Call Stack (most recent call first):
  /home/pi/Arduino-CMake-NG-master/cmake/Platform/Other/TargetFlagsManager.cmake:35 (_set_target_language_flags)
  /home/pi/Arduino-CMake-NG-master/cmake/Platform/Targets/CoreLibTarget.cmake:67 (set_compiler_target_flags)
  /home/pi/Arduino-CMake-NG-master/cmake/Platform/Targets/CoreLibTarget.cmake:112 (_set_core_lib_flags)
  /home/pi/Arduino-CMake-NG-master/cmake/Platform/Targets/ExecutableTarget.cmake:15 (add_arduino_core_lib)
  /home/pi/Arduino-CMake-NG-master/cmake/Platform/Targets/ArduinoExampleTarget.cmake:17 (add_arduino_executable)
  CMakeLists.txt:7 (add_arduino_example)


CMake Error at /home/pi/Arduino-CMake-NG-master/cmake/Platform/Other/TargetFlagsManager.cmake:13 (target_compile_options):
  Error evaluating generator expression:

    $<COMPILE_LANGUAGE:ASM>

  $<COMPILE_LANGUAGE:...> Unknown language.
Call Stack (most recent call first):
  /home/pi/Arduino-CMake-NG-master/cmake/Platform/Other/TargetFlagsManager.cmake:35 (_set_target_language_flags)
  /home/pi/Arduino-CMake-NG-master/cmake/Platform/Targets/CoreLibTarget.cmake:67 (set_compiler_target_flags)
  /home/pi/Arduino-CMake-NG-master/cmake/Platform/Targets/CoreLibTarget.cmake:112 (_set_core_lib_flags)
  /home/pi/Arduino-CMake-NG-master/cmake/Platform/Targets/ExecutableTarget.cmake:15 (add_arduino_core_lib)
  /home/pi/Arduino-CMake-NG-master/cmake/Platform/Targets/ArduinoExampleTarget.cmake:17 (add_arduino_executable)
  CMakeLists.txt:7 (add_arduino_example)


CMake Error at /home/pi/Arduino-CMake-NG-master/cmake/Platform/Other/TargetFlagsManager.cmake:13 (target_compile_options):
  Error evaluating generator expression:

    $<COMPILE_LANGUAGE:ASM>

  $<COMPILE_LANGUAGE:...> Unknown language.
Call Stack (most recent call first):
  /home/pi/Arduino-CMake-NG-master/cmake/Platform/Other/TargetFlagsManager.cmake:35 (_set_target_language_flags)
  /home/pi/Arduino-CMake-NG-master/cmake/Platform/Other/TargetFlagsManager.cmake:70 (set_compiler_target_flags)
  /home/pi/Arduino-CMake-NG-master/cmake/Platform/Targets/ExecutableTarget.cmake:17 (set_executable_target_flags)
  /home/pi/Arduino-CMake-NG-master/cmake/Platform/Targets/ArduinoExampleTarget.cmake:17 (add_arduino_executable)
  CMakeLists.txt:7 (add_arduino_example)


CMake Error at /home/pi/Arduino-CMake-NG-master/cmake/Platform/Targets/CoreLibTarget.cmake:116 (target_link_libraries):
  Error evaluating generator expression:

    $<COMPILE_LANGUAGE:ASM>

  $<COMPILE_LANGUAGE:...> Unknown language.
Call Stack (most recent call first):
  /home/pi/Arduino-CMake-NG-master/cmake/Platform/Targets/ExecutableTarget.cmake:15 (add_arduino_core_lib)
  /home/pi/Arduino-CMake-NG-master/cmake/Platform/Targets/ArduinoExampleTarget.cmake:17 (add_arduino_executable)
  CMakeLists.txt:7 (add_arduino_example)


-- Generating done
-- Build files have been written to: /home/pi/Arduino-CMake-NG-master/examples/blink-example

Any ideas about what I did wrong?

Document all CI platform integrations

All CI-CD platform integrations should be documented.
Every platform has to have a separate doc-section.

The docs shall include valuable pieces of information such as what files are used, what's going on inside them and how the organization as a whole is managed on those platforms.

Add platform library example

As a continuation of #66, an example of platform library usage should be added.

Examples currently serve 2 things for the project:

  1. Examples users can look for to grasp a better understanding of the framework's API
  2. Tests for framework - Should one of the examples fail to build, the entire framework is considered failed.

System avrdude is not found

As the avrdude should not be part of the sdk path and is therefore not installed there by the package manager (as the avrdude is usable without the sdk) it needs to be found on its own. The dependencies of this project even list avrdude as a separate package to be installed.

This is related to issue: #53

P.S. I'm on arch linux

undefined reference to `main`

Greetings,

I am going to preface this by saying im not entirely sure if I am doing this right and tried to build one of your example projects to get a better understanding of how this project works

What I have is I created a new c++ project in clion, i have replaced the cmake build file and source file with that of your hello world example and encountered a build-breaking error during linking. ( did reload the cmake project prior to building)

issue:

It appears the linker raises objection if a int main() is not declared, which is to be expected for a native OS application, however Arduino writes to firmware if i am not mistaken. Therefore having a int main() is unnecessary? The example projects also do not reflect the need for an int main()

steps to reproduce:

  1. copy the hello world example to its own directory
  2. attempt to build the hello world project

Contents of CMakeLists.txt

cmake_minimum_required(VERSION 3.8)

project(Hello_World LANGUAGES C CXX ASM)
get_board_id(board_id nano atmega328)

add_arduino_executable(Hello_World ${board_id} helloWorld.cpp)

#upload_arduino_target(Hello_World "${board_id}" COM3)

Contents of helloWorld.cpp

#include <Arduino.h>

void setup()
{
    pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
    digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(1000);                       // wait for a second
    digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
    delay(1000);                       // wait for a second
}

Build log:

D:\programfiles\Jetbrains\apps\CLion\ch-0\182.4505.18\bin\cmake\win\bin\cmake.exe --build D:\Clion\sandbox\arduino_sandbox\cmake-build-debug --target all -- -j 4
Scanning dependencies of target nano_atmega328_core_lib
[ 25%] Building ASM object CMakeFiles/nano_atmega328_core_lib.dir/D_/Program_Files_(x86)/Arduino/hardware/arduino/avr/cores/arduino/wiring_pulse.S.obj
[ 50%] Linking ASM static library libnano_atmega328_core_lib.a
[ 50%] Built target nano_atmega328_core_lib
Scanning dependencies of target Hello_World
[ 75%] Building CXX object CMakeFiles/Hello_World.dir/helloWorld.cpp.obj
[100%] Linking CXX executable Hello_World.elf
d:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr5/crtatmega328p.o:(.init9+0x0): undefined reference to `main'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[2]: *** [Hello_World.elf] Error 1
CMakeFiles\Hello_World.dir\build.make:83: recipe for target 'Hello_World.elf' failed
CMakeFiles\Makefile2:108: recipe for target 'CMakeFiles/Hello_World.dir/all' failed
mingw32-make.exe[1]: *** [CMakeFiles/Hello_World.dir/all] Error 2
mingw32-make.exe: *** [all] Error 2
Makefile:82: recipe for target 'all' failed

additonal cmake arguments added:

as per the wiki i added the following to my cmake build options
-DCMAKE_TOOLCHAIN_FILE=Arduino-CMake-NG/cmake/Arduino-Toolchain.cmake

OS: Windows
Distribution N/A
OS Version: 10
Platform: Arduino
SDK Version: Arduino SDK version 1.8.7

Once again, sorry if this is user error :(

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.