How to structure code when supporting multiple platforms?

Ive got some code which targets different platforms, with platform specific .cpp files for each.
Currently PIO tries to compile all the .cpp files under /src for both platforms and therefore I get build errors for the code for the “other” platform.

Where am I supposed to put the platform specific cpp code? Is there some built-in mechanism for searching for a src folder named by the platform?

Thanks

One example is how simpleFOC does it.

Thanks for taking the time to respond

Putting giant #if blocks around code surely can’t be the best solution for a tool who’s top feature is cross platform development…

I’ve found build_src_filter which solves my problem, but its clunky and manual. It would be nice if there was a built in mechanism for this

Thanks