Various CMake-related bug fixes and enhancements