cmake improvements

Don't merge until Travis approves.

Cleaned repeated logic, added a few options.