The Arduino CLI handles that auto-magically (if you want) by leveraging clang and other tools. Also it's a single binary and doesn't require you to deal with python and other stuff. This was a pain point we got as feedback from a number of users. (Disclaimer: I'm the con-founder of Arduino)
In contrast to Arduino, I've found it does a great job of handling your dependencies.
https://platformio.org/