From 5cff026d7ecc68c53c4789577103eb9d04272e7b Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Sun, 13 Oct 2024 22:00:12 -0400 Subject: [PATCH] build: get verson from git --- CMakeLists.txt | 55 ++++++++++++++++++++-- cmake/CPackOptions.cmake.in | 13 +++++ cmake/Packaging.cmake | 10 ++-- cmake/Version.cmake | 94 ------------------------------------- res/dist/arch/PKGBUILD.in | 2 +- res/dist/wix/Include.wxi.in | 4 +- 6 files changed, 74 insertions(+), 104 deletions(-) create mode 100644 cmake/CPackOptions.cmake.in delete mode 100644 cmake/Version.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index b58b752d9..4b5e592e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,15 +21,64 @@ # > See https://reproducible-builds.org/specs/source-date-epoch/ for details. 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/Build.cmake) include(cmake/Libraries.cmake) include(cmake/Packaging.cmake) -set_version() configure_definitions() configure_build() configure_libs() diff --git a/cmake/CPackOptions.cmake.in b/cmake/CPackOptions.cmake.in new file mode 100644 index 000000000..db2dab4c7 --- /dev/null +++ b/cmake/CPackOptions.cmake.in @@ -0,0 +1,13 @@ +# SPDX-FileCopyrightText: 2022 - 2023 Chris Rizzitello +# 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() diff --git a/cmake/Packaging.cmake b/cmake/Packaging.cmake index 88a9551b5..8f7f2d8e9 100644 --- a/cmake/Packaging.cmake +++ b/cmake/Packaging.cmake @@ -20,6 +20,9 @@ macro(configure_packaging) 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}) set(CPACK_PACKAGE_NAME ${DESKFLOW_APP_ID}) @@ -28,6 +31,9 @@ macro(configure_packaging) set(CPACK_PACKAGE_VENDOR ${DESKFLOW_AUTHOR_NAME}) 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") configure_windows_packaging() elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") @@ -52,7 +58,6 @@ macro(configure_windows_packaging) message(VERBOSE "Configuring Windows installer") - set(CPACK_PACKAGE_VERSION ${DESKFLOW_VERSION_MS}) set(QT_PATH $ENV{CMAKE_PREFIX_PATH}) set(DESKFLOW_MSI_64_GUID @@ -75,8 +80,6 @@ macro(configure_mac_packaging) message(VERBOSE "Configuring macOS app bundle") - set(CPACK_PACKAGE_VERSION ${DESKFLOW_VERSION}) - set(CMAKE_INSTALL_RPATH "@loader_path/../Libraries;@loader_path/../Frameworks") set(DESKFLOW_BUNDLE_SOURCE_DIR @@ -99,7 +102,6 @@ macro(configure_linux_packaging) message(VERBOSE "Configuring Linux packaging") - set(CPACK_PACKAGE_VERSION ${DESKFLOW_VERSION_LINUX}) set(CPACK_GENERATOR "DEB;RPM") set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${DESKFLOW_MAINTAINER}) diff --git a/cmake/Version.cmake b/cmake/Version.cmake deleted file mode 100644 index 5d477d0c9..000000000 --- a/cmake/Version.cmake +++ /dev/null @@ -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 . - -# 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() diff --git a/res/dist/arch/PKGBUILD.in b/res/dist/arch/PKGBUILD.in index b3a413d3d..43441e4ed 100644 --- a/res/dist/arch/PKGBUILD.in +++ b/res/dist/arch/PKGBUILD.in @@ -1,7 +1,7 @@ # Maintainer: @DESKFLOW_MAINTAINER@ pkgname=@DESKFLOW_APP_ID@ -pkgver=@DESKFLOW_VERSION_FOUR_PART@ +pkgver=@DESKFLOW_VERSION@ pkgrel=1 pkgdesc="Mouse and keyboard sharing utility" url='@DESKFLOW_WEBSITE_URL@' diff --git a/res/dist/wix/Include.wxi.in b/res/dist/wix/Include.wxi.in index 9c6c39630..2c33c80d5 100644 --- a/res/dist/wix/Include.wxi.in +++ b/res/dist/wix/Include.wxi.in @@ -2,7 +2,7 @@ - + @@ -27,4 +27,4 @@ - \ No newline at end of file +