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?
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.