Find Version Tag
The git_find_version_tag()
function allows you to find the nearest version tag that matches a version-pattern
(local repository). Behind the scene, git-describe is invoked.
Table of Contents
Example
include("rsp/git")
git_find_version_tag(
OUTPUT version
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
message("${version}") # 1.15.2
Match Pattern
By default, the following glob-pattern is used for matching a version tag:
*[0-9].*[0-9].*[0-9]*
To customize the pattern, specify the MATCH_PATTERN
parameter.
git_find_version_tag(
OUTPUT pre_release
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
MATCH_PATTERN "*[0-9].*[0-9].*[0-9]-*"
)
message("${pre_release}") # 1.0.0-alpha.2
Default Version
If unable to find a version tag, "0.0.0"
is returned
(See also Exit on Failure).
You can change this by setting the DEFAULT
parameter, in situations when no version tag can be found.
git_find_version_tag(
OUTPUT version
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEFAULT "0.1.0"
)
message("${version}") # 0.1.0
Exit on Failure
A fatal error will be raised, if the EXIT_ON_FAILURE
option is set, and no version tag can be found.
When doing so, the default version parameter will be ignored.
git_find_version_tag(
OUTPUT version
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEFAULT "0.1.0"
EXIT_ON_FAILURE
) # Fatal Error: No version tag found ...