Convert build system to use cmake and fix for Mac OS X build