various cmake fixes for OS X

this needs to be tested on other platforms to see if it breaks something, plus I'm not a cmake expert, so maybe I did something wrong here