| 1 |
# === This file is part of Calamares - <https://calamares.io> === |
| 2 |
# |
| 3 |
# SPDX-FileCopyrightText: 2014 Teo Mrnjavac <[email protected]> |
| 4 |
# SPDX-FileCopyrightText: 2021 Adriaan de Groot <[email protected]> |
| 5 |
# SPDX-License-Identifier: BSD-2-Clause |
| 6 |
# |
| 7 |
### |
| 8 |
# |
| 9 |
# This file defines one function for extending a VERSION-like value |
| 10 |
# with date and git information (if desired). |
| 11 |
# |
| 12 |
# - extend_version( version-string short_only short_var long_var ) |
| 13 |
# Calling this function will copy *version-string* (which would typically |
| 14 |
# be a semver-style string, like "3.2.40") into the variable *short_var*. |
| 15 |
# If *short_only* is true, then: |
| 16 |
# - the short version is also copied into the variable *long_var*, |
| 17 |
# If *short_only* is false, then: |
| 18 |
# - the *version-string* plus date and git information, is copied |
| 19 |
# into the varialbe *long_var*, in the format {version}-{date}-{hash} |
| 20 |
# |
| 21 |
# |
| 22 |
|
| 23 |
function( get_git_version_info out_var ) |
| 24 |
set(CMAKE_VERSION_SOURCE "") |
| 25 |
if(EXISTS ${CMAKE_SOURCE_DIR}/.git/HEAD) |
| 26 |
find_program(GIT_EXECUTABLE NAMES git git.cmd) |
| 27 |
mark_as_advanced(GIT_EXECUTABLE) |
| 28 |
if(GIT_EXECUTABLE) |
| 29 |
execute_process( |
| 30 |
COMMAND ${GIT_EXECUTABLE} rev-parse --verify -q --short=8 HEAD |
| 31 |
OUTPUT_VARIABLE head |
| 32 |
OUTPUT_STRIP_TRAILING_WHITESPACE |
| 33 |
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
| 34 |
) |
| 35 |
if(head) |
| 36 |
set(CMAKE_VERSION_SOURCE "${head}") |
| 37 |
execute_process( |
| 38 |
COMMAND ${GIT_EXECUTABLE} update-index -q --refresh |
| 39 |
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
| 40 |
) |
| 41 |
execute_process( |
| 42 |
COMMAND ${GIT_EXECUTABLE} diff-index --name-only HEAD -- |
| 43 |
OUTPUT_VARIABLE dirty |
| 44 |
OUTPUT_STRIP_TRAILING_WHITESPACE |
| 45 |
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
| 46 |
) |
| 47 |
if(dirty) |
| 48 |
set(CMAKE_VERSION_SOURCE "${CMAKE_VERSION_SOURCE}-dirty") |
| 49 |
endif() |
| 50 |
endif() |
| 51 |
endif() |
| 52 |
endif() |
| 53 |
set( ${out_var} "${CMAKE_VERSION_SOURCE}" PARENT_SCOPE ) |
| 54 |
endfunction() |
| 55 |
|
| 56 |
function( extend_version version short_only short_var long_var ) |
| 57 |
set( ${short_var} "${version}" PARENT_SCOPE ) |
| 58 |
set( _v "${version}" ) |
| 59 |
if ( NOT short_only ) |
| 60 |
string( TIMESTAMP CALAMARES_VERSION_DATE "%Y%m%d" ) |
| 61 |
if( CALAMARES_VERSION_DATE GREATER 0 ) |
| 62 |
set( _v ${_v}.${CALAMARES_VERSION_DATE} ) |
| 63 |
endif() |
| 64 |
get_git_version_info( _gitv ) |
| 65 |
if( _gitv ) |
| 66 |
set( _v "${_v}-${_gitv}" ) |
| 67 |
endif() |
| 68 |
endif() |
| 69 |
set( ${long_var} "${_v}" PARENT_SCOPE ) |
| 70 |
endfunction() |