|
| 1 | +# Compute ITK_VERSION_TWEAK: the YYYYMMDD date of the most recent commit, at |
| 2 | +# configure time. The tweak must never reach itkConfigure.h, so a per-commit |
| 3 | +# change of this value cannot invalidate ccache. |
| 4 | +# |
| 5 | +# .git_archival.txt is consulted before git so that an archive, or a fork that |
| 6 | +# commits a substituted file, pins the date it declares. In this repository the |
| 7 | +# file holds unexpanded $Format:$ placeholders, so a working tree falls through |
| 8 | +# to `git log`, which succeeds even in a shallow or tagless clone. |
| 9 | +function(_itk_version_tweak_from_date date outvar) |
| 10 | + if(date MATCHES "([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])") |
| 11 | + set( |
| 12 | + ${outvar} |
| 13 | + "${CMAKE_MATCH_1}${CMAKE_MATCH_2}${CMAKE_MATCH_3}" |
| 14 | + PARENT_SCOPE |
| 15 | + ) |
| 16 | + else() |
| 17 | + set(${outvar} "" PARENT_SCOPE) |
| 18 | + endif() |
| 19 | +endfunction() |
| 20 | + |
| 21 | +function(_itk_compute_version_tweak outvar) |
| 22 | + set(tweak "") |
| 23 | + |
| 24 | + if(EXISTS "${ITK_SOURCE_DIR}/.git_archival.txt") |
| 25 | + file( |
| 26 | + STRINGS |
| 27 | + "${ITK_SOURCE_DIR}/.git_archival.txt" |
| 28 | + archival |
| 29 | + REGEX "^node-date:" |
| 30 | + ) |
| 31 | + if(archival) |
| 32 | + list(GET archival 0 node_date) |
| 33 | + # Unexpanded placeholders mean this is a checkout, not an archive. |
| 34 | + if(NOT node_date MATCHES "\\$Format:") |
| 35 | + _itk_version_tweak_from_date("${node_date}" tweak) |
| 36 | + endif() |
| 37 | + endif() |
| 38 | + endif() |
| 39 | + |
| 40 | + if(NOT tweak MATCHES "^[0-9]+$") |
| 41 | + find_package(Git QUIET) |
| 42 | + if(Git_FOUND) |
| 43 | + execute_process( |
| 44 | + COMMAND |
| 45 | + "${GIT_EXECUTABLE}" -C "${ITK_SOURCE_DIR}" log -1 --format=%cd |
| 46 | + --date=short |
| 47 | + OUTPUT_VARIABLE commit_date |
| 48 | + OUTPUT_STRIP_TRAILING_WHITESPACE |
| 49 | + ERROR_QUIET |
| 50 | + ) |
| 51 | + _itk_version_tweak_from_date("${commit_date}" tweak) |
| 52 | + endif() |
| 53 | + endif() |
| 54 | + |
| 55 | + # Neither archive metadata nor git history, e.g. an unpacked plain tarball. |
| 56 | + if(NOT tweak MATCHES "^[0-9]+$") |
| 57 | + set(tweak "0") |
| 58 | + endif() |
| 59 | + set(${outvar} "${tweak}" PARENT_SCOPE) |
| 60 | +endfunction() |
| 61 | + |
| 62 | +_itk_compute_version_tweak(ITK_VERSION_TWEAK) |
| 63 | +set(ITK_VERSION_FULL "${ITK_VERSION}.${ITK_VERSION_TWEAK}") |
0 commit comments