I’m using a header-only library that includes a src directory with benchmarks and tests. I want the build process to ignore everything in the library’s src directory.
I can add a library.json file to the root directory of the library wherein I specify a source filter. Works great, but of course it’s manual and would have to be done by any project developer, because I don’t want to fork the lib maintain my own repo just to add the file. (And the library author is unlikely to accept a PR with PlatformIO specific file.)
I tried specifying a source filter in platformio.ini like -<../.piolibdeps/library_name/src> (and variants with ...src/*.cpp, ...src/*/*.cpp, ...src/subdir/*.cpp), but that didn’t work.
EDIT 20181123: src_filter works perfectly for this purpose. My test was bad. Also, Ivan’s alternative below works, too.
Should I be able to exclude library source files with a src_filter?
Sorry to dig up this old thread, but my question seems to be closely related.
I got a project that primarily is meant to develop a library. The library code is under <project>/lib/<lib name>/src/... and is a local of a Github repository.
In <project>/src/..., the test sources using the library are found. platformio.ini has several additional [env] entries for different test source constellations.
Now in <project>/lib/<lib name>/src/Linux/... some additional files for the Linux environment are held, that shall not be compiled when building the test sources.
How can I achieve in PlatformIO to have these files excluded from building?
If the library has source files which are only supposed to be compiled under some platform or operating systems, the documentation has an example (“HAL based library”) with an extra_script that lets you use a src_filter expression to exclude certain files from the build, if you detect in Python code that they must not be included. That is the only way I know of that handles this in the library, and not via src_filter or extra scripts in the project.