I am trying to build an environment suitable to execute Unit Tests (particularly using Google Tests) with some fake headers. The problem I have is that if the headers used in my code are not on the very first level in /lib/SOME_LIBRARY (e.g. lib/SOME_LIBRARY/core/WString.h), the headers are not found and the compiling process fails.
I tried to include the folder I would like to search in with a wildcard, but that does not work (this is another topic that I were not able to add that build flag using a relative path, only using absolute, otherwise the path were always wrong).
Is there any way to tell the compiler (directly using flags, or indirectly using some platformio.ini directives) to search for the headers recursively in any specific directory and its sub-directories?
it should have a library.json which declares its needed include flags.
These paths have to be added 1-by-1 in the manifest.
A way to work around this would be by using Advanced scripting and manipulating the CPPPATH environment variable with an array that contains the needed paths – the time needed to write this logic in Python and verify it would be much longer than the time needed to just write it in the library.json thouugh I think. (libraries can also have a extra_script directive)
I think you misunderstood my statement about the ArduinoFake library (or I misunderstand you?).
What I meant here, it did NOT also work for me. Particularly: I included the WString.h Arduino file in different header files in my code:
#include <WString.h>
and of course this works normally when I compile for my ESP board, but for my unit tests (in Native env), I tried using the ArduinoFake library, which does not work for my case, probably -if I understand correctly- because the WString.h is not in the standard src folder, therefore I always get the error that the WString.h header file cannot be found.
The Arduino-Fake library auto-includes WString.h through the Arduino.h → ArduinoFake.h → arduino/Arduino.h path.
If you need to reference those files directly then either access them via arduino/WString.h or just #include <Arduino.h>, in the case of the Arduino-Fake library. You might also choose to add the folder where WString.h is directly to the include path.
That is exactly the problem, I do not want to change the whole includes to use arduino/WString.h, and I do not want to expose the whole Arduino.h in my files. Therefore I went with the last solution (to add the folder of WString.h to my build_flags).
The only problem I have with the following is that I was not able to pass a relative path to the compiler. For example:
build_flags =
-Ilib/custom_arduino_fakes/
When checking the verbose output of the compilation, I see that it is always translated into the following: