How to prevent PIO from indexing .cpp files in the specified folder (e. g. how to exclude a folder from indexing)?

I have a problem using my own small C++ support library - mostly a set of header-only stuff - in PIO. I connected it as a submodule to my project’s repo, so it’s just a folder (not lib_deps). Still, PIO insists on indexing it, finds some .cpp files for unit testing, and then compilation fails. These files should never be picked up. In fact, I don’t want PIO to even look at any files other than the explicitly included headers (some other headers use C++20 features, sadly not available for ESP32).

How can I tell PIO to NOT index a specified folder?

For some reason, it’s always easier to find an answer yourself after you’ve asked on the forum. I’m still working out the exact configuration for my case, but this reply seems to be solving my problem:

Although it’s not ideal that the library.json file must reside in the target library itself. I’d rather not pollute repositories that shouldn’t need to know anything about PIO or Arduino. Or maybe it’s a 3rd-party library that you can clone but can’t add files to.

There should be a way to this from platformio.ini. Let the specific project decide how and what it wants to include and compile, and what to ignore.