1 find_program(GIT git) 2 execute_process( 3 COMMAND ${GIT} describe 4 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 5 OUTPUT_VARIABLE GIT_DESCRIBE_DIRTY 6 OUTPUT_STRIP_TRAILING_WHITESPACE 7 ) 8 string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${GIT_DESCRIBE_DIRTY}") 9 string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${GIT_DESCRIBE_DIRTY}") 10 string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${GIT_DESCRIBE_DIRTY}") 11 string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+\\-([0-9]+).*" "\\1" VERSION_COMMIT "${GIT_DESCRIBE_DIRTY}") 12