read version info from CHANGELOG.md if no git

If git tags are not available, set the version and revision by finding
the first version tag in `CHANGELOG.md` of the form

```
```

Where N.N.N is the number version (number of components can vary) and
the revision (as speicified by -REV) is optional.

TODO: support named revision without a version number of the form
`[REV]`.
This commit is contained in:
Rafael Kitover 2017-10-11 19:17:25 -07:00
parent 30b6ecf1a5
commit 46486381f0
2 changed files with 28 additions and 6 deletions

View File

@ -112,15 +112,12 @@ if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
# of files that depend on version.h # of files that depend on version.h
include(GetGitRevisionDescription) include(GetGitRevisionDescription)
get_git_head_revision(REFSPEC COMMITHASH) get_git_head_revision(REFSPEC COMMITHASH)
else()
message(WARNING "Git not found, cannot set version info")
endif() endif()
# no git or no tags # no git or no tags, use ChangeLog
if(NOT VERSION) if(NOT VERSION)
set(VERSION 2.0.0) include(ChangeLogVersion)
set(REVISION "unknown") changelog_version(VERSION REVISION VERSION_RELEASE)
set(VERSION_RELEASE 0)
endif() endif()
# generate version.h # generate version.h

View File

@ -0,0 +1,25 @@
function(changelog_version version revision version_release)
set(${version} "" CACHE STRING "Latest ChangeLog Version" FORCE)
set(${revision} "" CACHE STRING "Latest ChangeLog Revision" FORCE)
set(${version_release} 0 CACHE STRING "Is this a versioned release without revision" FORCE)
file(READ CHANGELOG.md changelog_file)
if(NOT changelog_file)
return()
endif()
string(REGEX MATCH "\n## +\\[([0-9.]+)(-([^] ]+))?\\] +- +[0-9][0-9]?/" match_out "${changelog_file}")
set(changelog_version "${CMAKE_MATCH_1}")
set(is_version_release 0)
set(changelog_revision "${CMAKE_MATCH_3}")
if(NOT changelog_revision)
set(is_version_release 1)
endif()
set(${version} "${changelog_version}" CACHE STRING "Latest ChangeLog Version" FORCE)
set(${revision} "${changelog_revision}" CACHE STRING "Latest ChangeLog Revision" FORCE)
set(${version_release} "${is_version_release}" CACHE STRING "Is this a versioned release without revision" FORCE)
endfunction()