From 272ec5a8ef8964460c65bf9b462bf3483036d473 Mon Sep 17 00:00:00 2001 From: Davide Beatrici Date: Fri, 19 Feb 2021 21:05:43 +0100 Subject: [PATCH] Add BUILD_NUMBER option to CMake and version.py script The BUILD_NUMBER option controls the last part of the version, allowing us to increase it for each build. This commit also adds version.py, which simply prints the version (e.g. "5.01") specified in CMakeLists.txt. The script will be used to determine the build number. --- CMakeLists.txt | 8 +++++++- version.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 version.py diff --git a/CMakeLists.txt b/CMakeLists.txt index a7aca94f..2b5656e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,13 @@ cmake_minimum_required(VERSION 3.7) +set(BUILD_NUMBER CACHE STRING "The number of the current build.") + +if ("${BUILD_NUMBER}" STREQUAL "") + set(BUILD_NUMBER "0") +endif() + project("SoftEther VPN" - VERSION 5.01.9674 + VERSION "5.01.${BUILD_NUMBER}" LANGUAGES C ) diff --git a/version.py b/version.py new file mode 100644 index 00000000..6ccacd27 --- /dev/null +++ b/version.py @@ -0,0 +1,28 @@ +import argparse + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('-n', '--newline', action = 'store_true', help = 'Break line after printing version') + args = parser.parse_args() + + end = None if args.newline else '' + + version = None + with open('CMakeLists.txt', 'r') as file: + for line in file: + if 'VERSION "' in line and '.${BUILD_NUMBER}"' in line: + line = line.replace('VERSION "', '') + line = line[0 : line.find('.${BUILD_NUMBER}"')].strip() + version = line + break + + if version is None: + raise Exception('Unable to read version from CMakeLists.txt') + + if len(version) == 0 or not '.' in version: + raise Exception('Bad version: "{0}"'.format(version)) + + print(version, end = end) + +if __name__ == '__main__': + main()