Refactor cmake

These commits make the cmake a bit more idiomatic and cleaner.