Filter out certain cpp files from library

How can I filter out source files of a library?

[env]
test_framework = unity
lib_deps =                                            ; external library dependencies
    etlcpp/Embedded Template Library@^20.39.4         ; ETL
    crepe=private_git_url/crepe.git#v1.0.0

; lib_src_filter =
build_src_filter =
    +<**/*.cpp>
    -<**/pybind_*.cpp>
    -<**/example_*.cpp>
    -<**/gtest_*.cpp>

This doesn’t work at all. Filtered out sources are still attempted to be built. What am I doing wrong? Thanks.

The build_src_filter applies just to the src folder of your project.

What problem are you trying to solve or what do you want to achieve and why?

1 Like

Library I’m trying to use has python bindings, examples and google tests (all .cpp files). I certainly don’t need them on Teensy. I’m trying to filter them out as you can see in the example. They are not located inside project’s src directory but inside library’s src directory. What’s the right way of doing this?

See Best Practices — PlatformIO latest documentation

#2: “Tests should not depend on the main application source code”

Also note
" Linking the main application source code from src_dir with a test suite code will lead to multiple compilation errors. Hence, the Shared Code is disabled by default."

That means you should write independent test code without testing the libraries. So your test code should not depend on external libraries. If there are dependencies you should write a mockup.

Can you carefully re-read my question and answer? I’m trying to exclude tests, examples and python bindings of a library from my build.

Is this your full platformio.ini ? I only see a generic “env” but no specific sections. I think that’s the error.

Your platformio.ini should more look like this:

[env]
test_framework = googletest

[env:native]
platform = native

[env:esp32dev]
platform = espressif32
framework = arduino
test_framework = googletest

*Of course with the right settings for a Teensy

See GoogleTest — PlatformIO latest documentation