cmake/FindVersion.cmake
changeset 397 13fa0546ef87
parent 396 e1a24791d192
child 398 306825786fba
--- a/cmake/FindVersion.cmake	Thu Jan 15 21:33:54 2009 +0200
+++ b/cmake/FindVersion.cmake	Fri Jan 16 00:42:02 2009 +0200
@@ -4,45 +4,48 @@
 # 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
+    # Mercurial
+    if (EXISTS ${project_path}/.hg)
+        # first, determine tag
         EXECUTE_PROCESS (
-            COMMAND hg identify --id
+            COMMAND hg identify --tag
             WORKING_DIRECTORY "${project_path}"
             RESULT_VARIABLE hg_error_code 
-            OUTPUT_VARIABLE hg_id
+            OUTPUT_VARIABLE hg_tag
             OUTPUT_STRIP_TRAILING_WHITESPACE
         )
-
+        
         if (hg_error_code)
-            MESSAGE (FATAL_ERROR "`hg identify --id` failed")
+            MESSAGE (FATAL_ERROR "`hg identify --tag` failed")
         endif (hg_error_code)
 
-        SET (PROJECT_VERSION "${hg_id}" PARENT_SCOPE)
-        MESSAGE (STATUS "Version: mercurial tip id: ${hg_id}")
+        # 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
+            )
 
-    else ("${hg_tag}" STREQUAL "tip")
-        SET (PROJECT_VERSION "${hg_tag}" PARENT_SCOPE)
-        MESSAGE (STATUS "Version: mercurial tag: ${hg_tag}")
+            if (hg_error_code)
+                MESSAGE (FATAL_ERROR "`hg identify --id` failed")
+            endif (hg_error_code)
 
-    endif ("${hg_tag}" STREQUAL "tip")
+            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")
+
+    else (EXISTS ${project_path}/.hg)
+        SET (PROJECT_VERSION "0.0" PARENT_SCOPE)
+        MESSAGE (STATUS "No version information available, assuming version ${PROJECT_VERSION}")
+
+    endif (EXISTS ${project_path}/.hg)
 ENDFUNCTION (FindProjectVersion)