--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/cmake/FindVersion.cmake Thu Jan 15 21:33:54 2009 +0200
@@ -0,0 +1,48 @@
+#
+# CMake build script to determine project version number.
+#
+# this will set PROJECT_VERSION to a string
+#
+FUNCTION (FindProjectVersion project_path)
+ # XXX: only support mercurial for now
+
+ MESSAGE (STATUS "project_path=${project_path}")
+
+ # first, determine tag
+ EXECUTE_PROCESS (
+ COMMAND hg identify --tag
+ WORKING_DIRECTORY "${project_path}"
+ RESULT_VARIABLE hg_error_code
+ OUTPUT_VARIABLE hg_tag
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+
+ if (hg_error_code)
+ MESSAGE (FATAL_ERROR "`hg identify --tag` failed")
+ endif (hg_error_code)
+
+ # if tag is other than tip, use that
+ if ("${hg_tag}" STREQUAL "tip")
+ # use the revision hash
+ EXECUTE_PROCESS (
+ COMMAND hg identify --id
+ WORKING_DIRECTORY "${project_path}"
+ RESULT_VARIABLE hg_error_code
+ OUTPUT_VARIABLE hg_id
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+
+ if (hg_error_code)
+ MESSAGE (FATAL_ERROR "`hg identify --id` failed")
+ endif (hg_error_code)
+
+ SET (PROJECT_VERSION "${hg_id}" PARENT_SCOPE)
+ MESSAGE (STATUS "Version: mercurial tip id: ${hg_id}")
+
+ else ("${hg_tag}" STREQUAL "tip")
+ SET (PROJECT_VERSION "${hg_tag}" PARENT_SCOPE)
+ MESSAGE (STATUS "Version: mercurial tag: ${hg_tag}")
+
+ endif ("${hg_tag}" STREQUAL "tip")
+
+ENDFUNCTION (FindProjectVersion)