From c1b832c03a7d1045a1ad34457024a8590ef3e165 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Sun, 21 Aug 2022 06:57:26 +0200 Subject: [PATCH] cmake: Fix bad version strings PROJECT_VERSION is defined by CMake, and can't be relied on. --- CMakeLists.txt | 122 ++++++++++++++++-------------- cmake/version | 2 +- templates/installer-signed.iss.in | 4 +- templates/installer.iss.in | 4 +- templates/installer.pkgproj.in | 2 +- templates/version.hpp.in | 6 +- templates/version.rc.in | 8 +- 7 files changed, 78 insertions(+), 70 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 31172958..8b63802e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,11 +69,11 @@ endif() ################################################################################ # For automatic versioning, which version is the "root" of the current changes? -set(PROJECT_VERSION_GIT_BASE "0.11.0") +set(_VERSION_GIT_BASE "0.11.0") # What is our version goal? -set(PROJECT_VERSION "0.12.0") -version(PARSE PROJECT_VERSION "${PROJECT_VERSION}") +set(_VERSION "0.12.0") +version(PARSE _VERSION "${_VERSION}") # If possible, automatically generate versions from git. if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/.git") @@ -86,10 +86,10 @@ if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/.git") if(EXISTS "${GIT}") # Calculate the Tweak version component from the given base version. execute_process( - COMMAND "${GIT}" describe --tags --long --match "${PROJECT_VERSION_GIT_BASE}" --abbrev=8 HEAD + COMMAND "${GIT}" describe --tags --long --match "${_VERSION_GIT_BASE}" --abbrev=8 HEAD WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} RESULT_VARIABLE GIT_RESULT - OUTPUT_VARIABLE PROJECT_VERSION_GIT + OUTPUT_VARIABLE _VERSION_GIT ERROR_VARIABLE GIT_ERROR OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE @@ -97,20 +97,20 @@ if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/.git") ) if(GIT_RESULT EQUAL 0) # Some minor string editing so the output conforms to SemVer 2.0.0. - string(REPLACE "-" ";" PROJECT_VERSION_GIT "${PROJECT_VERSION_GIT}") + string(REPLACE "-" ";" _VERSION_GIT "${_VERSION_GIT}") # Parse as SemVer 2.0.0 - list(GET PROJECT_VERSION_GIT 1 PROJECT_VERSION_GIT_TWEAK) - list(GET PROJECT_VERSION_GIT 2 PROJECT_VERSION_GIT_BUILD) + list(GET _VERSION_GIT 1 _VERSION_GIT_TWEAK) + list(GET _VERSION_GIT 2 _VERSION_GIT_BUILD) # Update our global version. - version(MODIFY PROJECT_VERSION "${PROJECT_VERSION}" COMPRESS - TWEAK "${PROJECT_VERSION_GIT_TWEAK}" - BUILD "${PROJECT_VERSION_GIT_BUILD}" + version(MODIFY _VERSION "${_VERSION}" COMPRESS + TWEAK "${_VERSION_GIT_TWEAK}" + BUILD "${_VERSION_GIT_BUILD}" PRERELEASE "a" - REQUIRE "PATCH;TWEAK" + REQUIRE PATCH TWEAK ) - version(PARSE PROJECT_VERSION "${PROJECT_VERSION}" REQUIRE "PATCH;TWEAK") + version(PARSE _VERSION "${_VERSION}" REQUIRE PATCH TWEAK) else() message(WARNING "${LOGPREFIX}Unable to detect Tweak and Build component with 'git'.") endif() @@ -120,37 +120,38 @@ if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/.git") COMMAND "${GIT}" tag "--sort=-v:refname" "--points-at" HEAD WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} RESULT_VARIABLE GIT_RESULT - OUTPUT_VARIABLE PROJECT_VERSION_TAG + OUTPUT_VARIABLE _VERSION_TAG ERROR_VARIABLE GIT_ERROR OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE ERROR_QUIET ) - if((GIT_RESULT EQUAL 0) AND (NOT "${PROJECT_VERSION_TAG}" STREQUAL "")) + if((GIT_RESULT EQUAL 0) AND (NOT "${_VERSION_TAG}" STREQUAL "")) # Some minor string editing so the output conforms to SemVer 2.0.0. - string(REGEX REPLACE "[\r\n]+.*" "" PROJECT_VERSION_TAG "${PROJECT_VERSION_TAG}") + string(REGEX REPLACE "[\r\n]+.*" "" _VERSION_TAG "${_VERSION_TAG}") # Parse as SemVer 2.0.0 - version(PARSE PROJECT_VERSION_TAG "${PROJECT_VERSION_TAG}" REQUIRE "PATCH;TWEAK") - if(PROJECT_VERSION_TAG_PRERELEASE) - string(SUBSTRING "${PROJECT_VERSION_TAG_PRERELEASE}" 1 -1 PROJECT_VERSION_TAG_TWEAK) - string(SUBSTRING "${PROJECT_VERSION_TAG_PRERELEASE}" 0 1 PROJECT_VERSION_TAG_PRERELEASE) + version(PARSE _VERSION_TAG "${_VERSION_TAG}" REQUIRE PATCH TWEAK) + if(_VERSION_TAG_PRERELEASE) + string(SUBSTRING "${_VERSION_TAG_PRERELEASE}" 1 -1 _VERSION_TAG_TWEAK) + string(SUBSTRING "${_VERSION_TAG_PRERELEASE}" 0 1 _VERSION_TAG_PRERELEASE) - if(NOT PROJECT_VERSION_TAG_TWEAK STREQUAL PROJECT_VERSION_GIT_TWEAK) - message(WARNING "${LOGPREFIX}'git' tag mismatches detected version: '${PROJECT_VERSION_TAG_TWEAK}' != '${PROJECT_VERSION_GIT_TWEAK}'.") + if(NOT _VERSION_TAG_TWEAK STREQUAL _VERSION_GIT_TWEAK) + message(WARNING "${LOGPREFIX}'git' tag mismatches detected version: '${_VERSION_TAG_TWEAK}' != '${_VERSION_GIT_TWEAK}'.") endif() endif() # Update our global version. - version(GENERATE PROJECT_VERSION COMPRESS - MAJOR "${PROJECT_VERSION_TAG_MAJOR}" - MINOR "${PROJECT_VERSION_TAG_MINOR}" - PATCH "${PROJECT_VERSION_TAG_PATCH}" - TWEAK "${PROJECT_VERSION_TAG_TWEAK}" - PRERELEASE "${PROJECT_VERSION_TAG_PRERELEASE}" - BUILD "${PROJECT_VERSION_BUILD}" + version(GENERATE _VERSION COMPRESS + MAJOR "${_VERSION_TAG_MAJOR}" + MINOR "${_VERSION_TAG_MINOR}" + PATCH "${_VERSION_TAG_PATCH}" + TWEAK "${_VERSION_TAG_TWEAK}" + PRERELEASE "${_VERSION_TAG_PRERELEASE}" + BUILD "${_VERSION_BUILD}" + REQUIRE PATCH TWEAK ) - version(PARSE PROJECT_VERSION "${PROJECT_VERSION}" REQUIRE "PATCH;TWEAK") + version(PARSE _VERSION "${_VERSION}" REQUIRE PATCH TWEAK) endif() else() message(STATUS "${LOGPREFIX}'git' not found, automatic version detection disabled.") @@ -162,37 +163,46 @@ endif() # Allow manual overrides of the detected version. set(${PREFIX}VERSION "" CACHE STRING "Override detected or pre-configured version with this string. Accepts strings in CMake and SemVer 2.0.0 format.") if(NOT ("${${PREFIX}VERSION}" STREQUAL "")) - version(PARSE PROJECT_VERSION_CFG "${${PREFIX}VERSION}" REQUIRE "PATCH;TWEAK") - if("${PROJECT_VERSION_CFG_BUILD}" STREQUAL "") - set(PROJECT_VERSION_CFG_BUILD "${PROJECT_VERSION_BUILD}") + version(PARSE _VERSION_CFG "${${PREFIX}VERSION}" REQUIRE PATCH TWEAK) + if("${_VERSION_CFG_BUILD}" STREQUAL "") + set(_VERSION_CFG_BUILD "${_VERSION_BUILD}") endif() - version(GENERATE PROJECT_VERSION COMPRESS - MAJOR "${PROJECT_VERSION_CFG_MAJOR}" - MINOR "${PROJECT_VERSION_CFG_MINOR}" - PATCH "${PROJECT_VERSION_CFG_PATCH}" - TWEAK "${PROJECT_VERSION_CFG_TWEAK}" - PRERELEASE "${PROJECT_VERSION_CFG_PRERELEASE}" - BUILD "${PROJECT_VERSION_CFG_BUILD}" + version(GENERATE _VERSION COMPRESS + MAJOR "${_VERSION_CFG_MAJOR}" + MINOR "${_VERSION_CFG_MINOR}" + PATCH "${_VERSION_CFG_PATCH}" + TWEAK "${_VERSION_CFG_TWEAK}" + PRERELEASE "${_VERSION_CFG_PRERELEASE}" + BUILD "${_VERSION_CFG_BUILD}" ) endif() +set(_VERSION_THIN "${_VERSION_MAJOR}.${_VERSION_MINOR}.${_VERSION_PATCH}") +if(NOT (_VERSION_PRERELEASE STREQUAL "")) + set(_VERSION_THIN "${_VERSION_THIN}${_VERSION_PRERELEASE}${_VERSION_TWEAK}") +endif() +if(NOT (VERSION_COMMIT STREQUAL "")) + set(_VERSION_THIN "${_VERSION_THIN}-${_VERSION_BUILD}") +endif() + # Parse & Log the detected version. -message(STATUS "${LOGPREFIX}Version ${PROJECT_VERSION}") +message(STATUS "${LOGPREFIX}Version ${_VERSION}") ################################################################################ # Project ################################################################################ # Metadata -version(GENERATE PROJECT_VERSION_CMAKE - MAJOR "${PROJECT_VERSION_MAJOR}" - MINOR "${PROJECT_VERSION_MINOR}" - PATCH "${PROJECT_VERSION_PATCH}" - TWEAK "${PROJECT_VERSION_TWEAK}" +version(GENERATE PROJECT_VERSION + MAJOR "${_VERSION_MAJOR}" + MINOR "${_VERSION_MINOR}" + PATCH "${_VERSION_PATCH}" + TWEAK "${_VERSION_TWEAK}" + REQUIRE PATCH TWEAK ) project( StreamFX - VERSION ${PROJECT_VERSION_CMAKE} + VERSION ${PROJECT_VERSION} DESCRIPTION "Additional sources, filters, transitions and encoders for OBS Studio." HOMEPAGE_URL "https://streamfx.xaymar.com/" ) @@ -1887,15 +1897,13 @@ set_target_properties(${PROJECT_NAME} PROPERTIES IMPORT_PREFIX "" ) -# Set file version (on anything but MacOS) -if(NOT D_PLATFORM_MAC) - set_target_properties(${PROJECT_NAME} PROPERTIES - MACHO_COMPATIBILITY_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} - MACHO_CURRENT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH} - VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.${PROJECT_VERSION_TWEAK} - SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.${PROJECT_VERSION_TWEAK} - ) -endif() +# Set file version +set_target_properties(${PROJECT_NAME} PROPERTIES + MACHO_COMPATIBILITY_VERSION ${_VERSION_MAJOR}.${_VERSION_MINOR} + MACHO_CURRENT_VERSION ${PROJECT_VERSION} + SOVERSION ${_VERSION_MAJOR}.${_VERSION_MINOR} + VERSION ${PROJECT_VERSION} +) # Delay-Loading on Microsoft Visual C++ if(D_PLATFORM_WINDOWS) @@ -2194,7 +2202,7 @@ endif() if(STANDALONE) # Packaging if(NOT PACKAGE_SUFFIX) - set(_PACKAGE_SUFFIX_OVERRIDE "${PROJECT_VERSION}") + set(_PACKAGE_SUFFIX_OVERRIDE "${_VERSION_THIN}") else() set(_PACKAGE_SUFFIX_OVERRIDE "${PACKAGE_SUFFIX}") endif() diff --git a/cmake/version b/cmake/version index 2494a2b6..16bfa956 160000 --- a/cmake/version +++ b/cmake/version @@ -1 +1 @@ -Subproject commit 2494a2b6c894380ced96307ae833afc0be37a143 +Subproject commit 16bfa9568c3d72e07d94c214a0da53956c7a33eb diff --git a/templates/installer-signed.iss.in b/templates/installer-signed.iss.in index 467bbd80..a80214b8 100644 --- a/templates/installer-signed.iss.in +++ b/templates/installer-signed.iss.in @@ -2,8 +2,8 @@ ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! #define MyAppName "@PROJECT_TITLE@" -#define MyAppVersion "@PROJECT_VERSION_CMAKE@" -#define MyAppVersionText "@PROJECT_VERSION@" +#define MyAppVersion "@PROJECT_VERSION@" +#define MyAppVersionText "@_VERSION@" #define MyAppPublisher "Xaymars Technology Workshop" #define MyAppURL "https://xaymar.com/" #define MyAppCopyright "@PROJECT_COPYRIGHT@" diff --git a/templates/installer.iss.in b/templates/installer.iss.in index 506877bf..9b2cc81f 100644 --- a/templates/installer.iss.in +++ b/templates/installer.iss.in @@ -2,8 +2,8 @@ ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! #define MyAppName "@PROJECT_TITLE@" -#define MyAppVersion "@PROJECT_VERSION_CMAKE@" -#define MyAppVersionText "@PROJECT_VERSION@" +#define MyAppVersion "@PROJECT_VERSION@" +#define MyAppVersionText "@_VERSION@" #define MyAppPublisher "Xaymars Technology Workshop" #define MyAppURL "https://xaymar.com/" #define MyAppCopyright "@PROJECT_COPYRIGHT@" diff --git a/templates/installer.pkgproj.in b/templates/installer.pkgproj.in index d9cc7924..2c33be46 100644 --- a/templates/installer.pkgproj.in +++ b/templates/installer.pkgproj.in @@ -528,7 +528,7 @@ USE_HFS+_COMPRESSION VERSION - @PROJECT_VERSION_CMAKE@ + @PROJECT_VERSION@ TYPE 0 diff --git a/templates/version.hpp.in b/templates/version.hpp.in index 02eab085..baf8a53e 100644 --- a/templates/version.hpp.in +++ b/templates/version.hpp.in @@ -34,9 +34,9 @@ #define STREAMFX_VERSION_MINOR @PROJECT_VERSION_MINOR@u #define STREAMFX_VERSION_PATCH @PROJECT_VERSION_PATCH@u #define STREAMFX_VERSION_TWEAK @PROJECT_VERSION_TWEAK@u -#define STREAMFX_VERSION_PRERELEASE "@PROJECT_VERSION_PRERELEASE@" -#define STREAMFX_VERSION_BUILD "@PROJECT_VERSION_BUILD@" +#define STREAMFX_VERSION_PRERELEASE "@_VERSION_PRERELEASE@" +#define STREAMFX_VERSION_BUILD "@_VERSION_BUILD@" #define STREAMFX_VERSION \ STREAMFX_MAKE_VERSION(STREAMFX_VERSION_MAJOR, STREAMFX_VERSION_MINOR, STREAMFX_VERSION_PATCH, \ STREAMFX_VERSION_TWEAK) -#define STREAMFX_VERSION_STRING "@PROJECT_VERSION@" +#define STREAMFX_VERSION_STRING "@_VERSION_THIN@" diff --git a/templates/version.rc.in b/templates/version.rc.in index f4c61a59..6d9cceaa 100644 --- a/templates/version.rc.in +++ b/templates/version.rc.in @@ -10,8 +10,8 @@ #endif VS_VERSION_INFO VERSIONINFO -FILEVERSION @PROJECT_VERSION_CMAKE@ -PRODUCTVERSION @PROJECT_VERSION_CMAKE@ +FILEVERSION @PROJECT_VERSION@ +PRODUCTVERSION @PROJECT_VERSION@ FILEFLAGSMASK VS_FFI_FILEFLAGSMASK FILEFLAGS (VER_DEBUG) FILEOS VOS__WINDOWS32 @@ -29,8 +29,8 @@ BEGIN VALUE "CompanyName", "@PROJECT_AUTHORS@\0" VALUE "LegalCopyright", "@PROJECT_COPYRIGHT@\0" VALUE "LegalTrademarks", "@PROJECT_TRADEMARKS@\0" - VALUE "FileVersion", "@VERSION_STRING@\0" - VALUE "ProductVersion", "@VERSION_STRING@\0" + VALUE "FileVersion", "@_VERSION@\0" + VALUE "ProductVersion", "@_VERSION@\0" END END