How it works
We use find_package(Git QUIET) to detect whether Git is available on the system. If it is (if GIT_FOUND is true), we run a Git command: ${GIT_EXECUTABLE} log -1 --pretty=format:%h. This command gives us the short version of the current commit hash. Of course, we have full flexibility to run another Git command, instead. We ask the execute_process command to place the result of the command into a variable called GIT_HASH, which we subsequently strip of any trailing whitespace. With ERROR_QUIET, we ask the command to not stop the configuration if the Git command fails for some reason.
Since the Git command might fail (the source code might have been distributed outside of the Git repository) or Git might not even be available on ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access