improved cmake configuration not to compile source code twice