Fixed various build issues with CMake