blob: e6f4b4c8fc3c04ce3f2581b3a2cc492ecb5223b6 [file] [log] [blame]
James Kuszmaul8e62b022022-03-22 09:33:25 -07001set(VERSION_MAJOR 2)
2set(VERSION_MINOR 0)
Austin Schuh2dd86a92022-09-14 21:19:23 -07003set(VERSION_PATCH 8)
Austin Schuh272c6132020-11-14 16:37:52 -08004set(VERSION_COMMIT 0)
5
Austin Schuhe89fa2d2019-08-14 20:24:23 -07006find_program(GIT git)
James Kuszmaul8e62b022022-03-22 09:33:25 -07007if(GIT AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
Austin Schuh272c6132020-11-14 16:37:52 -08008 execute_process(
James Kuszmaul8e62b022022-03-22 09:33:25 -07009 COMMAND ${GIT} describe --tags
Austin Schuh272c6132020-11-14 16:37:52 -080010 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
11 OUTPUT_VARIABLE GIT_DESCRIBE_DIRTY
12 OUTPUT_STRIP_TRAILING_WHITESPACE
13 RESULT_VARIABLE GIT_DESCRIBE_RESULT
14 )
15
16 if(GIT_DESCRIBE_RESULT EQUAL 0)
Austin Schuh2dd86a92022-09-14 21:19:23 -070017 # Test if the most recent Git tag matches the pattern "v<major>.<minor>.<patch>*"
18 if(GIT_DESCRIBE_DIRTY MATCHES "^v[0-9]+\\.[0-9]+\\.[0-9]+.*")
19 string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${GIT_DESCRIBE_DIRTY}")
20 string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${GIT_DESCRIBE_DIRTY}")
21 string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${GIT_DESCRIBE_DIRTY}")
22 string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+\\-([0-9]+).*" "\\1" VERSION_COMMIT "${GIT_DESCRIBE_DIRTY}")
23 # If the tag points to the commit, then only the tag is shown in "git describe"
24 if(VERSION_COMMIT STREQUAL GIT_DESCRIBE_DIRTY)
25 set(VERSION_COMMIT 0)
26 endif()
27 else()
28 message(WARNING "\"${GIT_DESCRIBE_DIRTY}\" does not match pattern v<major>.<minor>.<patch>-<commit>")
29 endif()
Austin Schuh272c6132020-11-14 16:37:52 -080030 else()
31 message(WARNING "git describe failed with exit code: ${GIT_DESCRIBE_RESULT}")
32 endif()
33else()
34 message(WARNING "git is not found")
35endif()
36
James Kuszmaul8e62b022022-03-22 09:33:25 -070037message(STATUS "Proceeding with version: ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_COMMIT}")