Cmake improvement

Fix #323

Thanks @elfring for the advice!