Conditional library inclusion

sounds like a familiar problem :slight_smile:

If the SoftwareSerial library is outside your lib, why not let others control their own version? And you just control lib? You could add a function to your library that passes in a reference or pointer to a Stream object and the library just uses that. Others who use the library must declare SoftwareSerial (of any flavor) or a hardware serial port and pass that in within setup()?

#include "SoftwareSerial.h"  // local, modified copy for project X
SoftwareSerial serial = SoftwareSerial(A0);
#include <lib.h>
...
void setup() {
  libSetSerial( &serial );
  ...
}

Then, inside your library, you have a global

Stream *libSerial;
...
void libSetSerial( Stream *s) {
  libSerial = s;
}

void writeDataString ( char* s, DateTime now) {
  if ( libSerial ) {
    libSerial->print(s);
    libSerial->println(now);
  }
}