Several CMake fixes and enhancements

Lots of minor fixes, also moves OBS_VERSION into a config.h file and wrapps it so compilation works without one.