I’ve been stuck for a few days on porting a Clion (Arduino cmake) project for use with Clion and PlatformIO.
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:
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:
#ifdef USE_NEOPIXEL_LEDS #include "Adafruit_NeoPixel.h" #endif #ifdef USE_WS2801_LEDS #include "Adafruit_WS2801.h" #endif
I even put the add_definitions() call in various places in the CMakeLists.txt file, to no avail.
Finally, I stumbled upon a topic on the Dependency Manager and found that by using:
[env:nanoatmega328] build_flags = -D USE_NEOPIXEL_LEDS -D platform = atmelavr board = nanoatmega328 framework = arduino
Now the include guard works.
And now I have questions and there seems to be very little documentation.
- What is the relationship between cmake and platformIO?
- Can platformIO’s build_flags derive from cmake in some way?
- 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?
- How come build_flags does not work in the [common] section in platformio.ini ?