| 1 |
# Minimum required version is 3.12.0 for the list(TRANSFORM), and 3.6.0 for list(FILTER) |
| 2 |
cmake_minimum_required(VERSION 3.12.0) |
| 3 |
|
| 4 |
# This file is processed by git archive and the template is filled in. It is |
| 5 |
# always safe to include. The variable VCS_SNAPSHOT is set to 1 when the |
| 6 |
# template was filled in, to 0 otherwise. |
| 7 |
|
| 8 |
# If this file is exported with git, we set the snapshot to 1 and define some values to the variables. |
| 9 |
if ("YES" STREQUAL "YES") |
| 10 |
set(VCS_SNAPSHOT 1) |
| 11 |
set(VCS_BRANCH "SNAPSHOT") |
| 12 |
set(VCS_DIRTY 0) |
| 13 |
string(SUBSTRING "f55c5669b96bc5fa7ee309f3bd9145fb3c70d521" 0 12 VCS_COMMIT) |
| 14 |
if (DEFINED VCS_FALLBACK_VERSION) |
| 15 |
set(VCS_DESCRIBE "${VCS_FALLBACK_VERSION}-SNAPSHOT-99999-gf55c5669b") |
| 16 |
else() |
| 17 |
message(FATAL_ERROR "Snapshot VCS information in use, but VCS_FALLBACK_VERSION not defined by root CMakeLists.txt.") |
| 18 |
endif() |
| 19 |
|
| 20 |
# Here, we do some magic to extract tags on this commit. The %D will result in a string in form: |
| 21 |
# HEAD -> master, tag: mytag1, mytag2 |
| 22 |
# To process it, we split it by ", ", filter only elements starting with "tag:" and replace the "tag: " out. |
| 23 |
# The remaining variable VCS_TAGS is a CMAKE list of exactly the tags, and can be conveniently test if some tags are found on the current commit. |
| 24 |
# Note: this does not help us in generating something like git describe --tags, as I see no way of extracting the last ancestor tag. |
| 25 |
set(VCS_REFS "HEAD -> master, tag: 0.20.0") |
| 26 |
string(REPLACE ", " ";" VCS_TAGS ${VCS_REFS}) |
| 27 |
list(FILTER VCS_TAGS INCLUDE REGEX "^tag: ") |
| 28 |
list(TRANSFORM VCS_TAGS REPLACE "^tag: " "") |
| 29 |
if (VCS_TAGS) |
| 30 |
# Pop first tag into VCS_DESCRIBE if any tags are present. |
| 31 |
list(POP_FRONT VCS_TAGS VCS_DESCRIBE) |
| 32 |
endif() |
| 33 |
else() |
| 34 |
set(VCS_SNAPSHOT 0) |
| 35 |
endif() |