Improved cmake script (only tested on linux so far)