|
| 1 | +# Compute ITK_VERSION_TWEAK: commits since the closest v* tag, at configure |
| 2 | +# time. The tweak must never reach itkConfigure.h, so a per-commit change of |
| 3 | +# this count cannot invalidate ccache. |
| 4 | +function(_itk_compute_version_tweak outvar) |
| 5 | + set(tweak "") |
| 6 | + set(script "${ITK_SOURCE_DIR}/Utilities/Maintenance/ComputeVersionTweak.py") |
| 7 | + |
| 8 | + set(python "${Python3_EXECUTABLE}") |
| 9 | + if(NOT python) |
| 10 | + find_program( |
| 11 | + ITK_TWEAK_Python3_EXECUTABLE |
| 12 | + NAMES |
| 13 | + python3 |
| 14 | + python |
| 15 | + ) |
| 16 | + mark_as_advanced(ITK_TWEAK_Python3_EXECUTABLE) |
| 17 | + set(python "${ITK_TWEAK_Python3_EXECUTABLE}") |
| 18 | + endif() |
| 19 | + if(python AND EXISTS "${script}") |
| 20 | + execute_process( |
| 21 | + COMMAND |
| 22 | + "${python}" "${script}" "${ITK_SOURCE_DIR}" |
| 23 | + OUTPUT_VARIABLE tweak |
| 24 | + OUTPUT_STRIP_TRAILING_WHITESPACE |
| 25 | + ERROR_QUIET |
| 26 | + ) |
| 27 | + endif() |
| 28 | + |
| 29 | + if(NOT tweak MATCHES "^[0-9]+$") |
| 30 | + find_package(Git QUIET) |
| 31 | + if(Git_FOUND) |
| 32 | + execute_process( |
| 33 | + COMMAND |
| 34 | + "${GIT_EXECUTABLE}" -C "${ITK_SOURCE_DIR}" describe --tags --long |
| 35 | + --match "v[0-9]*" |
| 36 | + OUTPUT_VARIABLE describe |
| 37 | + OUTPUT_STRIP_TRAILING_WHITESPACE |
| 38 | + ERROR_QUIET |
| 39 | + ) |
| 40 | + if(describe MATCHES "-([0-9]+)-g[0-9a-f]+$") |
| 41 | + set(tweak "${CMAKE_MATCH_1}") |
| 42 | + endif() |
| 43 | + endif() |
| 44 | + endif() |
| 45 | + |
| 46 | + # Exported tarball with no git and no usable interpreter: parse the |
| 47 | + # git-archive-substituted describe string so the count survives without Python. |
| 48 | + if( |
| 49 | + NOT |
| 50 | + tweak |
| 51 | + MATCHES |
| 52 | + "^[0-9]+$" |
| 53 | + AND |
| 54 | + EXISTS |
| 55 | + "${ITK_SOURCE_DIR}/.git_archival.txt" |
| 56 | + ) |
| 57 | + file( |
| 58 | + STRINGS |
| 59 | + "${ITK_SOURCE_DIR}/.git_archival.txt" |
| 60 | + archival |
| 61 | + REGEX "^describe-name:" |
| 62 | + ) |
| 63 | + if(archival) |
| 64 | + list(GET archival 0 describe) |
| 65 | + if(describe MATCHES "-([0-9]+)-g[0-9a-f]+$") |
| 66 | + set(tweak "${CMAKE_MATCH_1}") |
| 67 | + elseif(describe MATCHES "describe-name:[ \t]*v[0-9][^ \t]*$") |
| 68 | + set(tweak "0") |
| 69 | + endif() |
| 70 | + endif() |
| 71 | + endif() |
| 72 | + |
| 73 | + if(NOT tweak MATCHES "^[0-9]+$") |
| 74 | + set(tweak "0") |
| 75 | + endif() |
| 76 | + set(${outvar} "${tweak}" PARENT_SCOPE) |
| 77 | +endfunction() |
| 78 | + |
| 79 | +_itk_compute_version_tweak(ITK_VERSION_TWEAK) |
| 80 | +set(ITK_VERSION_FULL "${ITK_VERSION}.${ITK_VERSION_TWEAK}") |
0 commit comments