From e96e14ca76544402d8e003a2a595aa2f156b73d3 Mon Sep 17 00:00:00 2001 From: Eugene Shalygin Date: Mon, 6 Feb 2017 18:05:35 +0100 Subject: [PATCH] cmake: read version numbers from the version.pri file. Closes #6350. --- CMakeLists.txt | 14 ++++++------- cmake/Modules/FunctionReadVersion.cmake | 28 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 cmake/Modules/FunctionReadVersion.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index a049e0677..2501e4f07 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,14 @@ cmake_minimum_required(VERSION 3.5) cmake_policy(VERSION 3.5) -project(qBittorrent VERSION 3.4.0.0) +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules) +include(FunctionReadVersion) -set(VER_MAJOR ${qBittorrent_VERSION_MAJOR}) -set(VER_MINOR ${qBittorrent_VERSION_MINOR}) -set(VER_BUGFIX ${qBittorrent_VERSION_PATCH}) -set(VER_BUILD ${qBittorrent_VERSION_TWEAK}) -set(VER_STATUS "alpha") # Should be empty for stable releases! +read_version("${CMAKE_CURRENT_SOURCE_DIR}/version.pri" VER_MAJOR VER_MINOR VER_BUGFIX VER_BUILD VER_STATUS) +# message(STATUS "Project version is: ${VER_MAJOR}.${VER_MINOR}.${VER_BUGFIX}.${VER_BUILD} (${VER_STATUS})") + +project(qBittorrent VERSION ${VER_MAJOR}.${VER_MINOR}.${VER_BUGFIX}.${VER_BUILD}) -# Don't touch the rest part set(PROJECT_VERSION "${VER_MAJOR}.${VER_MINOR}.${VER_BUGFIX}") if (NOT VER_BUILD EQUAL 0) @@ -28,7 +27,6 @@ add_definitions(-DVERSION_BUILD=${VER_BUILD}) # } else { add_definitions(-DVERSION="v${PROJECT_VERSION}") # } -list(APPEND CMAKE_MODULE_PATH ${qBittorrent_SOURCE_DIR}/cmake/Modules) # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Og") if (UNIX AND NOT APPLE) diff --git a/cmake/Modules/FunctionReadVersion.cmake b/cmake/Modules/FunctionReadVersion.cmake new file mode 100644 index 000000000..2e51f7d02 --- /dev/null +++ b/cmake/Modules/FunctionReadVersion.cmake @@ -0,0 +1,28 @@ +# function for parsing version variables that are set in version.pri file +# the version identifiers there are defined as follows: +# VER_MAJOR = 3 +# VER_MINOR = 4 +# VER_BUGFIX = 0 +# VER_BUILD = 0 +# VER_STATUS = alpha + +function(read_version priFile outMajor outMinor outBugfix outBuild outStatus) + file(STRINGS ${priFile} _priFileContents REGEX "^VER_.+") + # message(STATUS "version.pri version contents: ${_priFileContents}") + # the _priFileContents variable contains something like the following: + # VER_MAJOR = 3;VER_MINOR = 4;VER_BUGFIX = 0;VER_BUILD = 0;VER_STATUS = alpha # Should be empty for stable releases! + set(_regex "VER_MAJOR += +([0-9]+);VER_MINOR += +([0-9]+);VER_BUGFIX += +([0-9]+);VER_BUILD += +([0-9]+);VER_STATUS += +([0-9A-Za-z]+)?") + # note quotes around _regex, they are needed because the variable contains semicolons + string(REGEX MATCH "${_regex}" _tmp "${_priFileContents}") + if (NOT _tmp) + message(FATAL_ERROR "Could not detect project version number from ${priFile}") + endif() + + # message(STATUS "Matched version string: ${_tmp}") + + set(${outMajor} ${CMAKE_MATCH_1} PARENT_SCOPE) + set(${outMinor} ${CMAKE_MATCH_2} PARENT_SCOPE) + set(${outBugfix} ${CMAKE_MATCH_3} PARENT_SCOPE) + set(${outBuild} ${CMAKE_MATCH_4} PARENT_SCOPE) + set(${outStatus} ${CMAKE_MATCH_5} PARENT_SCOPE) +endfunction()