Arduino Cmake

Arduino

EDIT: This issue appears to be cause by a problem with rosserial not being able to find custom messages that are defined in the same package as the firmware. There is an issue on the rosserial github repo about this. The error below was an artifact of this problem. Since this seems to be a specific issue with rosserial, and they are aware of it, I'm going to close this question.

I have a script running on an arduino that uses custom messages, and it has worked successfully while being compiled and uploaded with the Arduino IDE. However, now I am attempting to use the CMake build system, and when running catkin_make I get an error that some includes in the pre-generated message header cannot be found:

Jun 17, 2020 CMake-Based framework for Arduino platforms arduino cmake build ninja arduino-ide build-tool make CMake MIT 30 123 21 (2 issues need help) 3 Updated Jun 17, 2020. How to use ArduinoJson with CMake? This page explains how to include the ArduinoJson library in your CMake project. Method 1: using the FetchContent module If you use CMake 3.14 or above, you can use the built-in FetchContent module.

Linux Environment

My arduino script first includes Arduino.h, then ros.h, then my message. The top of the generated message header is as follows:

It appears that the arduino target isn't being linked against the C++ standard libraries and can't find string, vector, or map. This is only for the arduino script, all my other executables using these messages build successfully.

A few interesting things:

  • Initially this was building successfully, but after cleaning my workspace by deleting the devel and build folders I get this error
  • If I build this from within the CLion IDE there are no errors and the arduino script is built successfully
Arduino CmakeArduino Cmake

Any ideas what I could be missing here? It is very strange that the catkin build fails while the CLion build succeeds.

Based on every example I have found I believe both of my CMakeLists are correct, but I will post them anyways. Here is the relevant sections of my CMakeLists.txt in my package directory:

And here is the CMakeLists.txt in the arduino folder:

editretagflag offensivereopenmergedelete

Closed for the following reason question is not relevant or outdated by Steven_Daniluk
close date 2017-01-16 12:07:14.758932

Comments

Did you find a solution to this? I am experiencing the same issue.

A workaround is to build the messages for rosserial_arduino and your arduino script, separately from the rest of your package. In the package's CMakeLists.txt remove 'ALL' from rosserial_add_client_target(arduino my_script_name ALL), this will prevent CMake from automatically building the script.

Arduino Cmake

To build everything, first run catkin_make, this will build the rest of your package. The from your workspace run rosserial_arduino make_libraries build/my_package to build the messages, then catkin_make my_package_arduino_my_script_name to build your script. Change the names accordingly.

I’ve been stuck for a few days on porting a Clion (Arduino cmake) project for use with Clion and PlatformIO.

Arduino Cmake Tutorial

After much back and forth, I think I found my first issue – it appears that PlatformIO’s “build_flags” are the only thing the preprocessor pays attention to.

For instance, in my CMakeLists.txt file I may have:

add_definitions(-DUSE_NEOPIXEL_LEDS)`

This is confirmed when I have cmake message out the COMPILE_DEFINITIONS. This was working very well under CLion with Arduino CMake.

However, after lots of trial and error, under platformIO 3.4.0b12 (CLion 2017 1.3 / CMake 3.7) the following include guard code was not working:

Build

Arduino Cmake

I even put the add_definitions() call in various places in the CMakeLists.txt file, to no avail.

Arduino Cmake Toolchain

Finally, I stumbled upon a topic on the Dependency Manager and found that by using:

Installing 'pico-arduino' With CMake - Phil Schatzmann

Now the include guard works.

And now I have questions and there seems to be very little documentation.

Getting Started

  1. What is the relationship between cmake and platformIO?
  2. Can platformIO’s build_flags derive from cmake in some way?
  3. Does platformIO have anything similar to cmake’s option() method followed by if/endif? Or is the preferred method to simply setup multiple environments with the different build settings already built up?
  4. How come build_flags does not work in the [common] section in platformio.ini ?