Created
December 6, 2012 11:07
-
-
Save candycode/4223738 to your computer and use it in GitHub Desktop.
Add git repo version info as #define with CMake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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