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