Improve cmake code generation cmake function

Change-Id: Ie8d68fbe64d46de28d717aee18e91f7f8328c04f