How to ignore some source files from a library when building

I’d like to use this library in an stm32 project. Adding it to platformio.ini file worked to acquire it, but when building I get some errors.

Compiling .pio/build/genericSTM32F103RC/libea6/Trinamic-library/tmc2209hal.o
.pio/libdeps/genericSTM32F103RC/Trinamic-library/tmc2130hal.c:42:10: fatal error: grbl/hal.h: No such file or directory
 #include "grbl/hal.h"
          ^~~~~~~~~~~~
compilation terminated.

The error is correct because I’m not using grbl (the dependency should be missing). However, I don’t need the object that is built. At this point I don’t even include any tmc headers in my project.

Is there a way to only build the headers that are included in my project source files before building lib files?

platformio.ini

[env:genericSTM32F103RC]
platform = ststm32
board = genericSTM32F103RC
framework = stm32cube
debug_tool = stlink
upload_protocol = stlink
monitor_speed = 115200
board_build.stm32cube.custom_config_header = yes
build_flags=
    -mthumb #-mfpu=fpv4-sp-d16 -mfloat-abi=softfp
lib_extra_dirs =
    USB_DEVICE
    lib
    ; Middlewares
lib_deps =
    https://github.com/terjeio/Trinamic-library

[platformio]
src_dir = Core/Src
include_dir = Core/Inc

Do you mean Build Middlewares — PlatformIO latest documentation ?

Some extra scripting could do the trick but I think that is overkill. The build task is automatically building things I’m not including.

I can fork it and add my own pio manifests, I guess.

Wanted to add that I also run into this somewhat frequently. Ideally, PlatformIO would build libraries lazily, only building files which are included elsewhere, if possible.

i’m encountering this kind of issue as well.
Within my library I want to have unit tests as well but obviously those should not be built when including the library.

I’m referencing the lib using the lib_deps: symlink: method and I’m assuming this just performs a search for all the c/cpp and compiles them.
It would be nice if the library could also have a platformio file which was used to define which files were belonging to the library.