James Kuszmaul | 3b15b0c | 2022-11-08 14:03:16 -0800 | [diff] [blame] | 1 | set(VERSION_MAJOR 22) |
| 2 | set(VERSION_MINOR 10) |
| 3 | set(VERSION_PATCH 26) |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 4 | set(VERSION_COMMIT 0) |
| 5 | |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 6 | find_program(GIT git) |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 7 | if(GIT AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 8 | execute_process( |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 9 | COMMAND ${GIT} describe --tags |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 10 | 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 Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 17 | # 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 Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 30 | else() |
| 31 | message(WARNING "git describe failed with exit code: ${GIT_DESCRIBE_RESULT}") |
| 32 | endif() |
| 33 | else() |
| 34 | message(WARNING "git is not found") |
| 35 | endif() |
| 36 | |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 37 | message(STATUS "Proceeding with version: ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_COMMIT}") |