Various build fixes; CMake config; Dead code removal

Here are my fixes for various build issues, compiler warnings, and QA notices I encountered while writing an ebuild for Gentoo. I also added a CMake config and removed a tiny bit of unneeded code.

Florian