-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_version.cmake
More file actions
60 lines (58 loc) · 2.27 KB
/
parse_version.cmake
File metadata and controls
60 lines (58 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
################################################################################
# Copyright (c) 2018 David D. Marshall <ddmarsha@calpoly.edu>
#
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# See LICENSE.md file in the project root for full license information.
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# David D. Marshall - initial code and implementation
################################################################################
#
# - Parses a version string to get the major, minor, and patch numbers
#
# This function takes a version string and extracts the major, minor, patch,
# and tweak values. The input terms are:
# * package_name - The name of the package to prepend to variable names that
# will be used to store results in PARENT_SCOPE
# * version_in - the version string to be parsed
#
# These variables will be set in the parent scope:
# * <package_name>_MAJOR_VERSION - Store the major version
# * <package_name>_MINOR_VERSION - Store the minor version
# * <package_name>_PATCH_VERSION - Store the patch version
# * <package_name>_TWEAK_VERSION - Store the tweak version
#
################################################################################
function(PARSE_VERSION package_name_ version_in)
string(REPLACE "." ";" _version_list ${version_in})
list(LENGTH _version_list _version_list_length)
if (_version_list_length GREATER 0)
list(GET _version_list 0 _major_version)
else()
unset(_major_version)
endif()
if (_version_list_length GREATER 1)
list(GET _version_list 1 _minor_version)
else()
unset(_minor_version)
endif()
if (_version_list_length GREATER 2)
list(GET _version_list 2 _patch_version)
else()
unset(_patch_version)
endif()
if (_version_list_length GREATER 3)
list(GET _version_list 3 _tweak_version)
else()
unset(_teak_version)
endif()
set(${package_name_}_MAJOR_VERSION ${_major_version} PARENT_SCOPE)
set(${package_name_}_MINOR_VERSION ${_minor_version} PARENT_SCOPE)
set(${package_name_}_PATCH_VERSION ${_patch_version} PARENT_SCOPE)
set(${package_name_}_TWEAK_VERSION ${_tweak_version} PARENT_SCOPE)
endfunction()