summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--src/.gitattributes1
-rw-r--r--src/Version.cmake48
3 files changed, 51 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 408698a..5e4224a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -16,6 +16,8 @@
cmake_minimum_required(VERSION 2.8.5)
project(CastXML)
+include(src/Version.cmake)
+
include(CTest)
# Build tree locations.
diff --git a/src/.gitattributes b/src/.gitattributes
new file mode 100644
index 0000000..e8bb4f2
--- /dev/null
+++ b/src/.gitattributes
@@ -0,0 +1 @@
+Version.cmake export-subst
diff --git a/src/Version.cmake b/src/Version.cmake
new file mode 100644
index 0000000..02cc9da
--- /dev/null
+++ b/src/Version.cmake
@@ -0,0 +1,48 @@
+set(CastXML_VERSION "0.1")
+
+if(EXISTS ${CastXML_SOURCE_DIR}/.git)
+ find_package(Git)
+ if(GIT_FOUND)
+ macro(_git)
+ execute_process(
+ COMMAND ${GIT_EXECUTABLE} ${ARGN}
+ WORKING_DIRECTORY ${CastXML_SOURCE_DIR}
+ RESULT_VARIABLE _git_res
+ OUTPUT_VARIABLE _git_out OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_VARIABLE _git_err ERROR_STRIP_TRAILING_WHITESPACE
+ )
+ endmacro()
+ endif()
+endif()
+
+if(EXISTS ${CastXML_SOURCE_DIR}/VERSION)
+ # Read version provided in file with source tarball.
+ file(STRINGS ${CastXML_SOURCE_DIR}/VERSION CastXML_VERSION
+ LIMIT_COUNT 1 LIMIT_INPUT 1024)
+elseif(COMMAND _git)
+ # Compute version relative to annotated version tags, if any.
+ _git(describe --match "v[0-9]*" --dirty)
+ if(_git_out MATCHES "^v([0-9].*)$")
+ # Use version computed by 'git describe'.
+ set(CastXML_VERSION "${CMAKE_MATCH_1}")
+ else()
+ # Compute version currently checked out, possibly dirty.
+ _git(rev-parse --verify -q --short=7 HEAD)
+ if(_git_out MATCHES "^([0-9a-f]+)$")
+ set(CastXML_VERSION "${CastXML_VERSION}-g${CMAKE_MATCH_1}")
+ _git(update-index -q --refresh)
+ _git(diff-index --name-only HEAD --)
+ if(_git_out)
+ set(CastXML_VERSION "${CastXML_VERSION}-dirty")
+ endif()
+ else()
+ set(CastXML_VERSION "${CastXML_VERSION}-git")
+ endif()
+ endif()
+elseif("$Format:%h$" MATCHES "^([0-9a-f]+)$")
+ # Use version exported by 'git archive'.
+ set(CastXML_VERSION "${CastXML_VERSION}-g${CMAKE_MATCH_1}")
+else()
+ # Generic development version.
+ set(CastXML_VERSION "${CastXML_VERSION}-git")
+endif()