Differing code for Particle Dev and Web IDE

I’ve just started work on a project which uses the RCSwitch library.

In the web IDE, the library is included thus:

#include "RCSwitch/RCSwitch.h"

But since Particle Dev wants a flattened structure, I have to include it without the directory:

#include "RCSwitch.h"

Otherwise, the compiler is unable to locate the file. I need to collaborate with someone else who uses the web IDE, so I need the same code to work on both Particle Dev and the web IDE. (And regardless, isn’t this a pretty basic requirement anyway?) Is there a way for me to get this to work?

Edit: Since I’m using GitHub for this project, it would probably be a good idea to use the former syntax ("RCSwitch/RCSwitch.h"), since then I can have those files in a directory in the repo and .gitignore them.

That is a long standing proposal of mine but was always dismissed because library support will get improved since 2014 :wink:

The easiest and quickest would have been since then to just have Build set a #define _PARTICLE_BUILD_ (or such) and wrap your include in something like this

#if defined(_PARTICLE_BUILD_)
# include "lib/lib.h"
#else
# include "lib.h"
#endif

But since Build doesn’t do that, I’ve just added a first line to my projects

#define _PARTICLE_BUILD_   // or x_PARTICLE_BUILD_

So with one letter added/removed you quickly get yourself sorted (since Particle didn’t want that extra work but rather has us to adapt)

2 Likes

Alright, thanks for the workaround :slight_smile: