exclude source when compiling

Hi,

I have spent this afternoon googling but I just can't find an answer.
My problem is that I am trying to create a library that will work on Arduino boards, esp, and on Linux (maybe even stm and so on in the future).

I have the following folder and files structure:
library/

  • examples/ (with Arduino examples)
  • all other Arduino files (library.json, license etc)
  • src/
  • src/arduinoWrapper/ (with Arduino specific code)
  • src/linuxWrapper/ (with code that runs on Linux platform)
  • src/{ all src files} (with common code which is the the main logic)

When I compile with my own makefile created for Linux everything compiles and it is working.
When I try to compile through Arduino IDE, it tries to compile c++ libraries like spdlog and arrrgh which are ofc not compilable. The files are not included and I just do not know what to do.

I can not modify Arduino include paths, and I can not find an option to exclude those files.
I could do #ifndef ARDUINO in all files, but I really do not like this approach.
I would also like to avoid having another repo that will contain other wrappers.

(deleted)

spycatcher2k:
OK - Now read your post and point out exactly where you asked any questions!

Also , Why not, it's a perfectly sound and tested method.

Hi,
You are right. I did not ask a question, but I think that it is obvious that I am asking for a help from a way that I have described a problem. :slight_smile:

I would like to avoid #ifndef ARDUINO because I am using some external libs like arrrgh and spdlog and that would mean I have to fork them and change them in order to supply them with my repo.

(deleted)

Where are arrrgh and spdlog?

pert:
Where are arrrgh and spdlog?

Library for logging:

Library for argument parsing:

spycatcher2k:
Unless the include was wrapped in a ifdef!

Includes in main.ino files are wrapped in an ifdef. The issue is in source globbing I would say. It tries to compile all .cpp files even though their headers are not included anywhere

I meant to ask: where in the file system are those libraries?

pert:
I meant to ask: where in the file system are those libraries?

Ahh.. Sorry. It was too early for me :frowning:

They are inside my repo as git submodules

If you take a look at my folder structure in the original post they would be inside src/linuxWrapper/lib

Would it be possible for you to install those libraries somewhere outside of the src folder? That would prevent the source files from being automatically compiled and the solution of doing conditional #includes of those libraries would then work fine.

pert:
Would it be possible for you to install those libraries somewhere outside of the src folder? That would prevent the source files from being automatically compiled and the solution of doing conditional #includes of those libraries would then work fine.

It would. I will play around with different paths. Is only src folder included or are files in library folder included?

With the 1.5 Arduino library format (library.properties file in the library root folder, source files under the src subfolder), only the contents of the src folder are compiled.

pert:
With the 1.5 Arduino library format (library.properties file in the library root folder, source files under the src subfolder), only the contents of the src folder are compiled.

Thank You very much for this info. Tested it today and it is working :smiley:

You're welcome. I'm glad to hear it's working now. Enjoy!
Per