cmake: coalesce EXPAND macros into 3 common macros, and switch to using ...

...those; simplifies code and makes maintenance easier. This is just code shuffling, creating common macros and using them. I didn't rebase to the current master since this change can be merged without doing so.