CMake: simplify development-version string

- merge the (not-installed) date-stamp and git-version
  files into ExtendedVersion, turn things into functions
- drop support for CVS (wut?)
- don't mention the branch, in git-versioning, because the
  hash is enough to find whatever
- don't need external program to find date, use `string(TIMESTAMP...)`
main
Adriaan de Groot 4 years ago
parent 2be9aece3f
commit 38ec357bd5

@ -44,6 +44,14 @@ cmake_minimum_required( VERSION 3.3 FATAL_ERROR )
set( CALAMARES_VERSION 3.2.40 )
set( CALAMARES_RELEASE_MODE OFF )
if ( CMAKE_SCRIPT_MODE_FILE )
include( ${CMAKE_CURRENT_LIST_DIR}/CMakeModules/ExtendedVersion.cmake )
set( CMAKE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR} )
extend_version( ${CALAMARES_VERSION} OFF _vshort _vlong )
message( "${_vlong}" )
return()
endif()
project( CALAMARES
VERSION ${CALAMARES_VERSION}
LANGUAGES C CXX
@ -182,6 +190,7 @@ include( FeatureSummary )
# Calamares Modules
include( CMakeColors )
include( ExtendedVersion )
### C++ SETUP
#
@ -497,25 +506,7 @@ add_feature_info( ExampleDistro ${mksquashfs_FOUND} "Create example-distro targe
### CALAMARES PROPER
#
#
set( CALAMARES_VERSION_SHORT "${CALAMARES_VERSION}" )
# Additional info for non-release builds. The "extended" version information
# with date and git information (commit, dirty status) is used only
# by CalamaresVersionX.h, which is included by consumers that need a full
# version number with all that information; normal consumers can include
# CalamaresVersion.h with more stable numbers.
if( NOT CALAMARES_RELEASE_MODE AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git/" )
include( CMakeDateStamp )
set( CALAMARES_VERSION_DATE "${CMAKE_DATESTAMP_YEAR}${CMAKE_DATESTAMP_MONTH}${CMAKE_DATESTAMP_DAY}" )
if( CALAMARES_VERSION_DATE GREATER 0 )
set( CALAMARES_VERSION ${CALAMARES_VERSION}.${CALAMARES_VERSION_DATE} )
endif()
include( CMakeVersionSource )
if( CMAKE_VERSION_SOURCE )
set( CALAMARES_VERSION ${CALAMARES_VERSION}-${CMAKE_VERSION_SOURCE} )
endif()
endif()
extend_version( "${CALAMARES_VERSION}" ${CALAMARES_RELEASE_MODE} CALAMARES_VERSION_SHORT CALAMARES_VERSION )
# Special target for displaying the version. In RC (might-be-release)
# builds, use the short version (3.x.y), otherwise show the long version.

@ -1,31 +0,0 @@
# === This file is part of Calamares - <https://calamares.io> ===
#
# SPDX-FileCopyrightText: 2014 Teo Mrnjavac <teo@kde.org>
# SPDX-License-Identifier: BSD-2-Clause
#
###
#
# Find today's date, for versioning purposes.
find_program(DATE_EXECUTABLE NAMES date)
mark_as_advanced(DATE_EXECUTABLE)
if(DATE_EXECUTABLE)
execute_process(
COMMAND ${DATE_EXECUTABLE} +%Y
OUTPUT_VARIABLE CMAKE_DATESTAMP_YEAR
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
execute_process(
COMMAND ${DATE_EXECUTABLE} +%m
OUTPUT_VARIABLE CMAKE_DATESTAMP_MONTH
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
execute_process(
COMMAND ${DATE_EXECUTABLE} +%d
OUTPUT_VARIABLE CMAKE_DATESTAMP_DAY
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endif()

@ -1,52 +0,0 @@
# === This file is part of Calamares - <https://calamares.io> ===
#
# SPDX-FileCopyrightText: 2014 Teo Mrnjavac <teo@kde.org>
# SPDX-License-Identifier: BSD-2-Clause
#
###
#
# Try to identify the current development source version.
set(CMAKE_VERSION_SOURCE "")
if(EXISTS ${CMAKE_SOURCE_DIR}/.git/HEAD)
find_program(GIT_EXECUTABLE NAMES git git.cmd)
mark_as_advanced(GIT_EXECUTABLE)
if(GIT_EXECUTABLE)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --verify -q --short=7 HEAD
OUTPUT_VARIABLE head
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
if(head)
set(branch "")
execute_process(
COMMAND ${GIT_EXECUTABLE} name-rev HEAD
OUTPUT_VARIABLE branch
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
string(REGEX REPLACE "HEAD " "" branch "${branch}")
set(CMAKE_VERSION_SOURCE "git-${branch}-${head}")
execute_process(
COMMAND ${GIT_EXECUTABLE} update-index -q --refresh
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
execute_process(
COMMAND ${GIT_EXECUTABLE} diff-index --name-only HEAD --
OUTPUT_VARIABLE dirty
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
if(dirty)
set(CMAKE_VERSION_SOURCE "${CMAKE_VERSION_SOURCE}-dirty")
endif()
endif()
endif()
elseif(EXISTS ${CMAKE_SOURCE_DIR}/CVS/Repository)
file(READ ${CMAKE_SOURCE_DIR}/CVS/Repository repo)
set(branch "")
if("${repo}" MATCHES "\\.git/")
string(REGEX REPLACE ".*\\.git/([^\r\n]*).*" "-\\1" branch "${repo}")
endif()
set(CMAKE_VERSION_SOURCE "cvs${branch}")
endif()

@ -0,0 +1,75 @@
# === This file is part of Calamares - <https://calamares.io> ===
#
# SPDX-FileCopyrightText: 2014 Teo Mrnjavac <teo@kde.org>
# SPDX-FileCopyrightText: 2021 Adriaan de Groot <groot@kde.org>
# SPDX-License-Identifier: BSD-2-Clause
#
###
#
# This file defines one function for extending a VERSION-like value
# with date and git information (if desired).
#
# - extend_version( version-string short_only short_var long_var )
# Calling this function will copy *version-string* (which would typically
# be a semver-style string, like "3.2.40") into the variable *short_var*.
# If *short_only* is true, then:
# - the short version is also copied into the variable *long_var*,
# If *short_only* is false, then:
# - the *version-string* plus date and git information, is copied
# into the varialbe *long_var*, in the format {version}-{date}-{hash}
#
#
function( get_git_version_info out_var )
set(CMAKE_VERSION_SOURCE "")
if(EXISTS ${CMAKE_SOURCE_DIR}/.git/HEAD)
find_program(GIT_EXECUTABLE NAMES git git.cmd)
mark_as_advanced(GIT_EXECUTABLE)
if(GIT_EXECUTABLE)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --verify -q --short=8 HEAD
OUTPUT_VARIABLE head
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
if(head)
set(CMAKE_VERSION_SOURCE "${head}")
execute_process(
COMMAND ${GIT_EXECUTABLE} update-index -q --refresh
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
execute_process(
COMMAND ${GIT_EXECUTABLE} diff-index --name-only HEAD --
OUTPUT_VARIABLE dirty
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
if(dirty)
set(CMAKE_VERSION_SOURCE "${CMAKE_VERSION_SOURCE}-dirty")
endif()
endif()
endif()
endif()
set( ${out_var} "${CMAKE_VERSION_SOURCE}" PARENT_SCOPE )
endfunction()
function( extend_version version short_only short_var long_var )
set( ${short_var} "${version}" PARENT_SCOPE )
set( _v "${version}" )
if ( NOT short_only )
# Additional info for non-release builds which want "long" version info
# with date and git information (commit, dirty status). That is used only
# by CalamaresVersionX.h, which is included by consumers that need a full
# version number with all that information; normal consumers can include
# CalamaresVersion.h with more stable numbers.
string( TIMESTAMP CALAMARES_VERSION_DATE "%Y%m%d" )
if( CALAMARES_VERSION_DATE GREATER 0 )
set( _v ${_v}.${CALAMARES_VERSION_DATE} )
endif()
get_git_version_info( _gitv )
if( _gitv )
set( _v "${_v}-${_gitv}" )
endif()
endif()
set( ${long_var} "${_v}" PARENT_SCOPE )
endfunction()
Loading…
Cancel
Save