cmake: work with CMake < 2.8.5
authorDylan Noblesmith <nobled@dreamwidth.org>
Mon, 12 Dec 2011 13:06:25 +0000 (13:06 +0000)
committerDylan Noblesmith <nobled@dreamwidth.org>
Mon, 12 Dec 2011 13:06:25 +0000 (13:06 +0000)
CMake versions 2.8.4 and earlier were giving this error since r146323:
"string end index: -1 is out of range 0 - 6"

Passing -1 as the length of the desired substring was a new feature
added in CMake 2.8.5:
http://www.cmake.org/Bug/view.php?id=10740

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146372 91177308-0d34-0410-b5e6-96231b3b80d8

cmake/modules/VersionFromVCS.cmake

index a55e9b837f3870e69a7773459797af0cc339fc32..d6a2ae5f45f5eea20b9ba1ea710213f5ea14219f 100644 (file)
@@ -30,7 +30,9 @@ function(add_version_info_from_vcs VERS)
                       OUTPUT_VARIABLE git_output)
       if( git_result EQUAL 0 )
         string(REGEX MATCH r[0-9]+ git_svn_rev ${git_output})
-        string(SUBSTRING "${git_svn_rev}" 1 -1 git_svn_rev_number)
+        string(LENGTH "${git_svn_rev}" rev_length)
+        math(EXPR rev_length "${rev_length}-1")
+        string(SUBSTRING "${git_svn_rev}" 1 ${rev_length} git_svn_rev_number)
         set(SVN_REVISION ${git_svn_rev_number} PARENT_SCOPE)
         set(git_svn_rev "-svn-${git_svn_rev}")