mirror of
https://github.com/zealdocs/zeal.git
synced 2026-08-29 08:34:50 +08:00
build(cmake): add versioning for unstable builds
New SemVer compatible scheme: Following a stable release the hard-coded version will be bumped to the next patch. Builds from untagged revisions will have "-dev" version suffix added. If Git metadata is present it will be added to the version string as well.
This commit is contained in:
+38
-3
@@ -1,11 +1,14 @@
|
|||||||
cmake_minimum_required(VERSION 3.5.1)
|
cmake_minimum_required(VERSION 3.10.2)
|
||||||
|
|
||||||
# CMake options.
|
# CMake options.
|
||||||
set(CMAKE_ERROR_DEPRECATED TRUE)
|
set(CMAKE_ERROR_DEPRECATED TRUE)
|
||||||
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
|
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
|
||||||
|
|
||||||
project(Zeal VERSION 0.6.1)
|
project(Zeal VERSION 0.6.2)
|
||||||
set(RELEASE_DATE 2018-09-28)
|
|
||||||
|
# Set to TRUE for a tagged release.
|
||||||
|
# NOTE: Don't forget to add a new release entry in the AppStream metadata!
|
||||||
|
set(RELEASE_VERSION FALSE)
|
||||||
|
|
||||||
# Project information.
|
# Project information.
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
@@ -21,5 +24,37 @@ set(PROJECT_URL "https://zealdocs.org")
|
|||||||
|
|
||||||
set(QT_MINIMUM_VERSION 5.9.5)
|
set(QT_MINIMUM_VERSION 5.9.5)
|
||||||
|
|
||||||
|
# Determine version for dev builds.
|
||||||
|
if(NOT RELEASE_VERSION)
|
||||||
|
message(STATUS "Building unreleased code. Proceed at your own risk!")
|
||||||
|
|
||||||
|
# TODO: Add support for metadata passed from env, e.g. aur, appimage, etc.
|
||||||
|
include(GetVersionFromGit)
|
||||||
|
if(Zeal_GIT_VERSION_SHA)
|
||||||
|
# Extra check in case we forgot to bump version in project() directive.
|
||||||
|
if(NOT PROJECT_VERSION_PATCH EQUAL Zeal_GIT_VERSION_PATCH_NEXT)
|
||||||
|
message(FATAL_ERROR "Incorrect patch version! Forgot to bump?")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(ZEAL_VERSION_SUFFIX "-dev.${Zeal_GIT_VERSION_AHEAD}+${Zeal_GIT_VERSION_SHA}")
|
||||||
|
else()
|
||||||
|
set(ZEAL_VERSION_SUFFIX "-dev")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(ZEAL_VERSION_FULL "${Zeal_VERSION}${ZEAL_VERSION_SUFFIX}")
|
||||||
|
|
||||||
|
# For development builds insert an extra release in the AppStream metadata.
|
||||||
|
if(NOT RELEASE_VERSION)
|
||||||
|
string(TIMESTAMP ZEAL_APPSTREAM_DEV_RELEASE "\n <release date=\"%Y-%m-%d\" version=\"${ZEAL_VERSION_FULL}\" type=\"development\" />")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# A custom target to print the full version.
|
||||||
|
# Usage: cmake --build build --target zeal_version
|
||||||
|
add_custom_target(zeal_version
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E echo "Zeal version: ${ZEAL_VERSION_FULL}"
|
||||||
|
VERBATIM
|
||||||
|
)
|
||||||
|
|
||||||
add_subdirectory(assets)
|
add_subdirectory(assets)
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
|
|||||||
@@ -26,8 +26,8 @@
|
|||||||
<provides>
|
<provides>
|
||||||
<id>zeal.desktop</id>
|
<id>zeal.desktop</id>
|
||||||
</provides>
|
</provides>
|
||||||
<releases>
|
<releases>@ZEAL_APPSTREAM_DEV_RELEASE@
|
||||||
<release date="${RELEASE_DATE}" version="${Zeal_VERSION}" />
|
<release date="2018-09-28" version="0.6.1" type="stable" />
|
||||||
</releases>
|
</releases>
|
||||||
<update_contact>zeal@zealdocs.org</update_contact>
|
<update_contact>zeal@zealdocs.org</update_contact>
|
||||||
<content_rating type="oars-1.1">
|
<content_rating type="oars-1.1">
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
# Based on https://github.com/fakenmc/cmake-git-semver by Nuno Fachada.
|
||||||
|
# This module is public domain, use it as it fits you best.
|
||||||
|
#
|
||||||
|
# This cmake module sets the project version and partial version
|
||||||
|
# variables by analysing the git tag and commit history. It expects git
|
||||||
|
# tags defined with semantic versioning 2.0.0 (http://semver.org/).
|
||||||
|
#
|
||||||
|
# The module expects the PROJECT_NAME variable to be set, and recognizes
|
||||||
|
# the GIT_FOUND, GIT_EXECUTABLE and VERSION_UPDATE_FROM_GIT variables.
|
||||||
|
# If Git is found and VERSION_UPDATE_FROM_GIT is set to boolean TRUE,
|
||||||
|
# the project version will be updated using information fetched from the
|
||||||
|
# most recent git tag and commit. Otherwise, the module will try to read
|
||||||
|
# a VERSION file containing the full and partial versions. The module
|
||||||
|
# will update this file each time the project version is updated.
|
||||||
|
#
|
||||||
|
# Once done, this module will define the following variables:
|
||||||
|
#
|
||||||
|
# ${PROJECT_NAME}_GIT_VERSION_STRING - Version string without metadata
|
||||||
|
# such as "v2.0.0" or "v1.2.41-beta.1". This should correspond to the
|
||||||
|
# most recent git tag.
|
||||||
|
# ${PROJECT_NAME}_GIT_VERSION_STRING_FULL - Version string with metadata
|
||||||
|
# such as "v2.0.0+3.a23fbc" or "v1.3.1-alpha.2+4.9c4fd1"
|
||||||
|
# ${PROJECT_NAME}_GIT_VERSION_MAJOR - Major version integer (e.g. 2 in v2.3.1-RC.2+21.ef12c8)
|
||||||
|
# ${PROJECT_NAME}_GIT_VERSION_MINOR - Minor version integer (e.g. 3 in v2.3.1-RC.2+21.ef12c8)
|
||||||
|
# ${PROJECT_NAME}_GIT_VERSION_PATCH - Patch version integer (e.g. 1 in v2.3.1-RC.2+21.ef12c8)
|
||||||
|
# ${PROJECT_NAME}_GIT_VERSION_TWEAK - Tweak version string (e.g. "RC.2" in v2.3.1-RC.2+21.ef12c8)
|
||||||
|
# ${PROJECT_NAME}_GIT_VERSION_AHEAD - How many commits ahead of last tag (e.g. 21 in v2.3.1-RC.2+21.ef12c8)
|
||||||
|
# ${PROJECT_NAME}_GIT_VERSION_SHA - The git sha1 of the most recent commit (e.g. the "ef12c8" in v2.3.1-RC.2+21.ef12c8)
|
||||||
|
# Only if VERSION_UPDATE_FROM_GIT is TRUE:
|
||||||
|
# ${PROJECT_NAME}_VERSION - Same as ${PROJECT_NAME}_GIT_VERSION_STRING,
|
||||||
|
# without the preceding 'v', e.g. "2.0.0" or "1.2.41-beta.1"
|
||||||
|
|
||||||
|
# Check if git is found...
|
||||||
|
find_package(Git)
|
||||||
|
if(NOT GIT_FOUND)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Get last tag from git
|
||||||
|
execute_process(COMMAND ${GIT_EXECUTABLE} describe --abbrev=0 --tags
|
||||||
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||||
|
OUTPUT_VARIABLE ${PROJECT_NAME}_GIT_VERSION_STRING
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
|
||||||
|
# How many commits since the last tag
|
||||||
|
execute_process(COMMAND ${GIT_EXECUTABLE} rev-list master ${${PROJECT_NAME}_GIT_VERSION_STRING}^..HEAD --count
|
||||||
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||||
|
OUTPUT_VARIABLE ${PROJECT_NAME}_GIT_VERSION_AHEAD
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
|
||||||
|
# Get current commit SHA from git
|
||||||
|
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
|
||||||
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||||
|
OUTPUT_VARIABLE ${PROJECT_NAME}_GIT_VERSION_SHA
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
|
||||||
|
# Get partial versions into a list
|
||||||
|
string(REGEX MATCHALL "-.*$|[0-9]+" ${PROJECT_NAME}_PARTIAL_VERSION_LIST
|
||||||
|
${${PROJECT_NAME}_GIT_VERSION_STRING})
|
||||||
|
|
||||||
|
# Set the version numbers
|
||||||
|
list(GET ${PROJECT_NAME}_PARTIAL_VERSION_LIST
|
||||||
|
0 ${PROJECT_NAME}_GIT_VERSION_MAJOR)
|
||||||
|
list(GET ${PROJECT_NAME}_PARTIAL_VERSION_LIST
|
||||||
|
1 ${PROJECT_NAME}_GIT_VERSION_MINOR)
|
||||||
|
list(GET ${PROJECT_NAME}_PARTIAL_VERSION_LIST
|
||||||
|
2 ${PROJECT_NAME}_GIT_VERSION_PATCH)
|
||||||
|
|
||||||
|
# Calculate next patch version.
|
||||||
|
math(EXPR ${PROJECT_NAME}_GIT_VERSION_PATCH_NEXT ${${PROJECT_NAME}_GIT_VERSION_PATCH}+1)
|
||||||
|
|
||||||
|
# The tweak part is optional, so check if the list contains it
|
||||||
|
list(LENGTH ${PROJECT_NAME}_PARTIAL_VERSION_LIST
|
||||||
|
${PROJECT_NAME}_PARTIAL_VERSION_LIST_LEN)
|
||||||
|
if (${PROJECT_NAME}_PARTIAL_VERSION_LIST_LEN GREATER 3)
|
||||||
|
list(GET ${PROJECT_NAME}_PARTIAL_VERSION_LIST 3 ${PROJECT_NAME}_GIT_VERSION_TWEAK)
|
||||||
|
string(SUBSTRING ${${PROJECT_NAME}_GIT_VERSION_TWEAK} 1 -1 ${PROJECT_NAME}_GIT_VERSION_TWEAK)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Unset the list
|
||||||
|
unset(${PROJECT_NAME}_PARTIAL_VERSION_LIST)
|
||||||
|
|
||||||
|
# Set full project version string
|
||||||
|
set(${PROJECT_NAME}_GIT_VERSION_STRING_FULL
|
||||||
|
${${PROJECT_NAME}_GIT_VERSION_STRING}+${${PROJECT_NAME}_GIT_VERSION_AHEAD}.${${PROJECT_NAME}_GIT_VERSION_SHA})
|
||||||
|
|
||||||
|
if(VERSION_UPDATE_FROM_GIT)
|
||||||
|
# Set project version (without the preceding 'v')
|
||||||
|
set(${PROJECT_NAME}_VERSION ${${PROJECT_NAME}_GIT_VERSION_MAJOR}.${${PROJECT_NAME}_GIT_VERSION_MINOR}.${${PROJECT_NAME}_GIT_VERSION_PATCH})
|
||||||
|
if (${PROJECT_NAME}_GIT_VERSION_TWEAK)
|
||||||
|
set(${PROJECT_NAME}_VERSION ${${PROJECT_NAME}_VERSION}-${${PROJECT_NAME}_GIT_VERSION_TWEAK})
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
+2
-2
@@ -10,8 +10,8 @@ if(ZEAL_PORTABLE_BUILD)
|
|||||||
add_definitions(-DPORTABLE_BUILD)
|
add_definitions(-DPORTABLE_BUILD)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
## Macro
|
## Macros.
|
||||||
add_definitions(-DZEAL_VERSION="${Zeal_VERSION}")
|
add_definitions(-DZEAL_VERSION="${ZEAL_VERSION_FULL}")
|
||||||
|
|
||||||
# QString options
|
# QString options
|
||||||
add_definitions(-DQT_USE_QSTRINGBUILDER)
|
add_definitions(-DQT_USE_QSTRINGBUILDER)
|
||||||
|
|||||||
Reference in New Issue
Block a user