blob: 46af8dac2063ee76fb4bd6ed58f519fe1277d9a4 (
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
|
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()
|