Avoid complete rebuild on cmake run with git info change
Before these changes, the following will trigger a complete rebuild:
- create another git name (git checkout -b test)
- run cmake again manually (cmake ..)
- run ninja again
This is fixed in this commit; switching branches and re-compiling should take less time. For explanations, check the commit message.
Later work will reuse this in the CI to speed up builds.