use some structured code to decide which backends to build (should have cherry picked from waves' code but ...)