build: get verson from git

This commit is contained in:
sithlord48 2024-10-13 22:00:12 -04:00 committed by Chris Rizzitello
parent e4b348c183
commit 5cff026d7e
6 changed files with 74 additions and 104 deletions

View file

@ -21,15 +21,64 @@
# > See https://reproducible-builds.org/specs/source-date-epoch/ for details. # > See https://reproducible-builds.org/specs/source-date-epoch/ for details.
cmake_minimum_required(VERSION 3.8) cmake_minimum_required(VERSION 3.8)
project(deskflow C CXX) # Fallback for when git can not be found
set(DESKFLOW_VERSION_MAJOR 1)
set(DESKFLOW_VERSION_MINOR 17)
set(DESKFLOW_VERSION_PATCH 0)
set(DESKFLOW_VERSION_TWEAK 0)
# Get the version from git if it's a git repository
# cmake-format: off
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
find_package(Git)
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --long --match v* --always
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE GITREV
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
string(FIND ${GITREV} "v" isRev)
if(NOT ifRev EQUAL -1)
string(REGEX MATCH [0-9]+ MAJOR ${GITREV})
string(REGEX MATCH \\.[0-9]+ MINOR ${GITREV})
string(REPLACE "." "" MINOR "${MINOR}")
string(REGEX MATCH [0-9]+\- PATCH ${GITREV})
string(REPLACE "-" "" PATCH "${PATCH}")
string(REGEX MATCH \-[0-9]+\- TWEAK ${GITREV})
string(REPLACE "-" "" TWEAK "${TWEAK}")
set(DESKFLOW_VERSION_MAJOR ${MAJOR})
set(DESKFLOW_VERSION_MINOR ${MINOR})
set(DESKFLOW_VERSION_PATCH ${PATCH})
set(DESKFLOW_VERSION_TWEAK ${TWEAK})
elseif(NOT ${GITREV} STREQUAL "")
set(DESKFLOW_VERSION_TWEAK ${GITREV})
endif()
endif()
endif()
# cmake-format: on
set(DESKFLOW_VERSION
"${DESKFLOW_VERSION_MAJOR}.${DESKFLOW_VERSION_MINOR}.${DESKFLOW_VERSION_PATCH}.${DESKFLOW_VERSION_TWEAK}"
)
set(DESKFLOW_VERSION_MS_CSV
"${DESKFLOW_VERSION_MAJOR},${DESKFLOW_VERSION_MINOR},${DESKFLOW_VERSION_PATCH},${DESKFLOW_VERSION_TWEAK}"
)
add_definitions(-DDESKFLOW_VERSION="${DESKFLOW_VERSION}")
#Define our project
project(
deskflow
VERSION ${DESKFLOW_VERSION}
LANGUAGES C CXX)
message(STATUS "Building ${CMAKE_PROJECT_NAME}-${CMAKE_PROJECT_VERSION}")
include(cmake/Version.cmake)
include(cmake/Definitions.cmake) include(cmake/Definitions.cmake)
include(cmake/Build.cmake) include(cmake/Build.cmake)
include(cmake/Libraries.cmake) include(cmake/Libraries.cmake)
include(cmake/Packaging.cmake) include(cmake/Packaging.cmake)
set_version()
configure_definitions() configure_definitions()
configure_build() configure_build()
configure_libs() configure_libs()

View file

@ -0,0 +1,13 @@
# SPDX-FileCopyrightText: 2022 - 2023 Chris Rizzitello <sithlord48@gmail.com>
# SPDX-License-Identifier: MIT
#This File is generated at CONFIGURE time
#This file is run at CPACK Time
#Do not set CPACK used CMAKE_* Vars here
# some Generators will fail if you do
#These installs must not use "continuous"
if(CPACK_GENERATOR MATCHES DEB|WIX|RPM)
set(CPACK_PACKAGE_VERSION @CMAKE_PROJECT_VERSION@)
endif()

View file

@ -20,6 +20,9 @@
macro(configure_packaging) macro(configure_packaging)
set(DESKFLOW_PROJECT_RES_DIR ${PROJECT_SOURCE_DIR}/res) set(DESKFLOW_PROJECT_RES_DIR ${PROJECT_SOURCE_DIR}/res)
configure_file(${CMAKE_SOURCE_DIR}/cmake/CPackOptions.cmake.in
${CMAKE_BINARY_DIR}/cmake/CPackOptions.cmake @ONLY)
set(CPACK_PROJECT_CONFIG_FILE ${CMAKE_CURRENT_BINARY_DIR}/CPackOptions.cmake)
if(${BUILD_INSTALLER}) if(${BUILD_INSTALLER})
set(CPACK_PACKAGE_NAME ${DESKFLOW_APP_ID}) set(CPACK_PACKAGE_NAME ${DESKFLOW_APP_ID})
@ -28,6 +31,9 @@ macro(configure_packaging)
set(CPACK_PACKAGE_VENDOR ${DESKFLOW_AUTHOR_NAME}) set(CPACK_PACKAGE_VENDOR ${DESKFLOW_AUTHOR_NAME})
set(CPACK_RESOURCE_FILE_LICENSE ${PROJECT_SOURCE_DIR}/LICENSE) set(CPACK_RESOURCE_FILE_LICENSE ${PROJECT_SOURCE_DIR}/LICENSE)
if(NOT CPACK_PACKAGE_VERSION)
set(CPACK_PACKAGE_VERSION ${DESKFLOW_VERSION})
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
configure_windows_packaging() configure_windows_packaging()
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
@ -52,7 +58,6 @@ macro(configure_windows_packaging)
message(VERBOSE "Configuring Windows installer") message(VERBOSE "Configuring Windows installer")
set(CPACK_PACKAGE_VERSION ${DESKFLOW_VERSION_MS})
set(QT_PATH $ENV{CMAKE_PREFIX_PATH}) set(QT_PATH $ENV{CMAKE_PREFIX_PATH})
set(DESKFLOW_MSI_64_GUID set(DESKFLOW_MSI_64_GUID
@ -75,8 +80,6 @@ macro(configure_mac_packaging)
message(VERBOSE "Configuring macOS app bundle") message(VERBOSE "Configuring macOS app bundle")
set(CPACK_PACKAGE_VERSION ${DESKFLOW_VERSION})
set(CMAKE_INSTALL_RPATH set(CMAKE_INSTALL_RPATH
"@loader_path/../Libraries;@loader_path/../Frameworks") "@loader_path/../Libraries;@loader_path/../Frameworks")
set(DESKFLOW_BUNDLE_SOURCE_DIR set(DESKFLOW_BUNDLE_SOURCE_DIR
@ -99,7 +102,6 @@ macro(configure_linux_packaging)
message(VERBOSE "Configuring Linux packaging") message(VERBOSE "Configuring Linux packaging")
set(CPACK_PACKAGE_VERSION ${DESKFLOW_VERSION_LINUX})
set(CPACK_GENERATOR "DEB;RPM") set(CPACK_GENERATOR "DEB;RPM")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${DESKFLOW_MAINTAINER}) set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${DESKFLOW_MAINTAINER})

View file

@ -1,94 +0,0 @@
# Deskflow -- mouse and keyboard sharing utility
# Copyright (C) 2012-2024 Symless Ltd.
# Copyright (C) 2009-2012 Nick Bolton
#
# This package is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# found in the file LICENSE that should have accompanied this file.
#
# This package is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Either get the version number from the environment or from the VERSION file.
# On Windows, we also set a special 4-digit MSI version number.
macro(set_version)
set(DESKFLOW_VERSION $ENV{DESKFLOW_VERSION})
string(STRIP "${DESKFLOW_VERSION}" DESKFLOW_VERSION)
if(NOT DESKFLOW_VERSION)
file(READ "${PROJECT_SOURCE_DIR}/VERSION" DESKFLOW_VERSION)
string(STRIP "${DESKFLOW_VERSION}" DESKFLOW_VERSION)
endif()
message(STATUS "Version number (semver): " ${DESKFLOW_VERSION})
add_definitions(-DDESKFLOW_VERSION="${DESKFLOW_VERSION}")
# Useful for copyright (e.g. in macOS bundle .plist.in and Windows version .rc
# file)
string(TIMESTAMP DESKFLOW_BUILD_YEAR "%Y")
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set_windows_version()
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set_linux_version()
endif()
endmacro()
macro(set_four_part_version)
string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)" _ "${DESKFLOW_VERSION}")
set(VERSION_MAJOR "${CMAKE_MATCH_1}")
set(VERSION_MINOR "${CMAKE_MATCH_2}")
set(VERSION_PATCH "${CMAKE_MATCH_3}")
# Find the revision number, which is the number after the 'r'.
string(REGEX MATCH "r([0-9]+)$" _ "${DESKFLOW_VERSION}")
set(VERSION_REVISION "${CMAKE_MATCH_1}")
if(NOT VERSION_REVISION)
set(VERSION_REVISION "0")
endif()
set(DESKFLOW_VERSION_FOUR_PART
"${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_REVISION}")
endmacro()
# MSI requires a 4-digit number and doesn't accept semver.
macro(set_windows_version)
set_four_part_version()
# Dot-separated version number for MSI and Windows version .rc file.
set(DESKFLOW_VERSION_MS ${DESKFLOW_VERSION_FOUR_PART})
message(VERBOSE "Version number for (Microsoft 4-part): "
${DESKFLOW_VERSION_MS})
# CSV version number for Windows version .rc file.
set(DESKFLOW_VERSION_MS_CSV
"${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_REVISION}")
message(VERBOSE "Version number for (Microsoft CSV): "
${DESKFLOW_VERSION_MS_CSV})
endmacro()
macro(set_linux_version)
# Replace the first occurrence of '-' with '~' for Linux versioning; the '-'
# char is reserved for use at at the end of the version string to indicate a
# package revision. Debian has always used this convention, but support for
# this was also introduced in RPM 4.10.0.
string(REGEX REPLACE "-" "~" DESKFLOW_VERSION_LINUX "${DESKFLOW_VERSION}")
message(STATUS "Version number (DEB/RPM): ${DESKFLOW_VERSION_LINUX}")
# Arch does not support SemVer or DEB/RPM version format, so use the four-part
# version format which funnily enough is what Microsoft requires for MSI.
set_four_part_version()
message(STATUS "Version number (4-part): ${DESKFLOW_VERSION_FOUR_PART}")
endmacro()

View file

@ -1,7 +1,7 @@
# Maintainer: @DESKFLOW_MAINTAINER@ # Maintainer: @DESKFLOW_MAINTAINER@
pkgname=@DESKFLOW_APP_ID@ pkgname=@DESKFLOW_APP_ID@
pkgver=@DESKFLOW_VERSION_FOUR_PART@ pkgver=@DESKFLOW_VERSION@
pkgrel=1 pkgrel=1
pkgdesc="Mouse and keyboard sharing utility" pkgdesc="Mouse and keyboard sharing utility"
url='@DESKFLOW_WEBSITE_URL@' url='@DESKFLOW_WEBSITE_URL@'

View file

@ -2,7 +2,7 @@
<Include> <Include>
<?define AppId="@DESKFLOW_APP_ID@"?> <?define AppId="@DESKFLOW_APP_ID@"?>
<?define Name="@DESKFLOW_APP_NAME@"?> <?define Name="@DESKFLOW_APP_NAME@"?>
<?define Version="@DESKFLOW_VERSION_MS@"?> <?define Version="@DESKFLOW_VERSION@"?>
<?define Author="@DESKFLOW_AUTHOR_NAME@"?> <?define Author="@DESKFLOW_AUTHOR_NAME@"?>
<?define BinDir="@CMAKE_RUNTIME_OUTPUT_DIRECTORY@"?> <?define BinDir="@CMAKE_RUNTIME_OUTPUT_DIRECTORY@"?>
<?define ProjectResDir="@DESKFLOW_PROJECT_RES_DIR@"?> <?define ProjectResDir="@DESKFLOW_PROJECT_RES_DIR@"?>