Cross Platform Arduino Code

brtaylor

Well-known member
I use CMake for my internal development. In some cases, I have both a CMake version of a library (i.e. https://github.com/bolderflight/mpu9250) and an Arduino version of the library (https://github.com/bolderflight/mpu9250-arduino). I kind of hate needing to maintain two versions of code and I also think some code I wrote around my CMake build system would be beneficial to the Arduino user base (i.e. https://github.com/bolderflight/mavlink).

I'm trying to figure out how to make it so a single library will play nicely with my CMake build system and Arduino's build system. I could easily add a define within the CMake tooling to switch around CMake paths. But it seems like the limiting factors are:
1. Arduino expects all of my library headers and source files to be within a directory called "src"
2. Arduino expects source files to have a ".cpp" extension

I tried using some indirection by having a header file in src that would point to the real header file and that works, but I couldn't get Arduino to figure out that a ".cc" file was a source file or to include it if it wasn't in "src".

Just reaching out to see if anyone has tried such a thing or if it's really Arduino's way or the highway?
 
Why not turning the issue around?
configure your CMake setup such that it is Arduino compatible.
That is what I do with my makefile setup (using VSCode)
 
Why not turning the issue around?
configure your CMake setup such that it is Arduino compatible.
That is what I do with my makefile setup (using VSCode)

Thanks for the suggestion. I ended up trying this approach on a simple library to start:
https://github.com/bolderflight/circle_buf

If anyone has any suggestions for improvements or feedback, I'd really appreciate it before moving forward with making changes to other libraries.
 
Back
Top