I just learned how I can use
project(ProjectName VERSION 1.0)
and the configure_file to play with the version and embed it into the binary.
On project documentation I see it also accept a description string.
project(ProjectName VERSION 1.0 description_string)
So I want to use the commit id as the description string. I can read commit id from command line with git rev-parse HEAD
but how can I use that to set the description?
CodePudding user response:
You can use FindGit module to find a git executable and then run it with execute_process
to get the result, so something like this:
find_package(Git REQUIRED)
execute_process(COMMAND "${GIT_EXECUTABLE}" rev-parse HEAD OUTPUT_VARIABLE COMMIT_ID OUTPUT_STRIP_TRAILING_WHITESPACE)
project(ProjectName VERSION 1.0 DESCRIPTION "${COMMIT_ID}")