blob: 5dce58395343741d51527ba907165ee4a7eae287 (
plain)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
From 46486381f0c18110002ec62108969be957b419be Mon Sep 17 00:00:00 2001
From: Rafael Kitover <rkitover@gmail.com>
Date: Wed, 11 Oct 2017 19:17:25 -0700
Subject: [PATCH] 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]`.
---
CMakeLists.txt | 9 +++------
cmake/ChangeLogVersion.cmake | 25 +++++++++++++++++++++++++
2 files changed, 28 insertions(+), 6 deletions(-)
create mode 100644 cmake/ChangeLogVersion.cmake
diff --git a/CMakeLists.txt b/CMakeLists.txt
index bd09527d..4ad859b2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -112,15 +112,12 @@ if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
# of files that depend on version.h
include(GetGitRevisionDescription)
get_git_head_revision(REFSPEC COMMITHASH)
-else()
- message(WARNING "Git not found, cannot set version info")
endif()
-# no git or no tags
+# no git or no tags, use ChangeLog
if(NOT VERSION)
- set(VERSION 2.0.0)
- set(REVISION "unknown")
- set(VERSION_RELEASE 0)
+ include(ChangeLogVersion)
+ changelog_version(VERSION REVISION VERSION_RELEASE)
endif()
# generate version.h
diff --git a/cmake/ChangeLogVersion.cmake b/cmake/ChangeLogVersion.cmake
new file mode 100644
index 00000000..101d23bd
--- /dev/null
+++ b/cmake/ChangeLogVersion.cmake
@@ -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()
|