Skip to content

Instantly share code, notes, and snippets.

@candycode
Created December 6, 2012 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save candycode/4223738 to your computer and use it in GitHub Desktop.
Save candycode/4223738 to your computer and use it in GitHub Desktop.
Add git repo version info as #define with CMake
#look for a tag...
exec_program(
"git"
${CMAKE_CURRENT_SOURCE_DIR}
ARGS "describe"
OUTPUT_VARIABLE GIT_TAG )
#...if not found get the SHA1 hash instead
if( ${GIT_TAG} MATCHES "fatal:.*" )
exec_program(
"git"
${CMAKE_CURRENT_SOURCE_DIR}
ARGS "rev-parse HEAD"
OUTPUT_VARIABLE GIT_VERSION )
else()
set( GIT_VERSION ${GIT_TAG} )
endif()
add_definitions( -DAPP_GIT_VERSION="${GIT_VERSION}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment