[Cmake-commits] CMake branch, next, updated. v2.8.7-2921-g3646cdd

Rolf Eike Beer eike at sf-mail.de
Mon Feb 27 12:15:28 EST 2012


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, next has been updated
       via  3646cdd59d045557746ed7961a0be4ba4997b09a (commit)
       via  7d6db93de9ffc6e6092fa722aaf9c057dadcd634 (commit)
      from  91d99fed7beee4caa39e29b6f48905c2ddf069cd (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=3646cdd59d045557746ed7961a0be4ba4997b09a
commit 3646cdd59d045557746ed7961a0be4ba4997b09a
Merge: 91d99fe 7d6db93
Author:     Rolf Eike Beer <eike at sf-mail.de>
AuthorDate: Mon Feb 27 12:15:23 2012 -0500
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Mon Feb 27 12:15:23 2012 -0500

    Merge topic 'findpythoninterp-version-detection' into next
    
    7d6db93 FindPythonInterp: rework the version detection


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=7d6db93de9ffc6e6092fa722aaf9c057dadcd634
commit 7d6db93de9ffc6e6092fa722aaf9c057dadcd634
Author:     Rolf Eike Beer <eike at sf-mail.de>
AuthorDate: Sun Feb 26 09:29:02 2012 +0100
Commit:     Rolf Eike Beer <eike at sf-mail.de>
CommitDate: Mon Feb 27 18:15:01 2012 +0100

    FindPythonInterp: rework the version detection
    
    There are versions out there that neither understand --version nor -V. Try a
    completely different approach: execute a small python script that prints the
    version number (and only that) in an easily reusable way using
    sys.version_info. This is documented to work since Python 2.0. Use sys.version
    for older versions, which is documented to exist since 1.5. If even that
    doesn't work then simply assume we are on 1.4.0.

diff --git a/Modules/FindPythonInterp.cmake b/Modules/FindPythonInterp.cmake
index 5c1d56b..babbd4b 100644
--- a/Modules/FindPythonInterp.cmake
+++ b/Modules/FindPythonInterp.cmake
@@ -15,6 +15,7 @@
 #=============================================================================
 # Copyright 2005-2010 Kitware, Inc.
 # Copyright 2011 Bjoern Ricks <bjoern.ricks at gmail.com>
+# Copyright 2012 Rolf Eike Beer <eike at sf-mail.de>
 #
 # Distributed under the OSI-approved BSD License (the "License");
 # see accompanying file Copyright.txt for details.
@@ -88,24 +89,42 @@ endif()
 
 # determine python version string
 if(PYTHON_EXECUTABLE)
-    execute_process(COMMAND "${PYTHON_EXECUTABLE}" --version
-                    ERROR_VARIABLE _VERSION
+    execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c
+                            "import sys; sys.stdout.write(';'.join([str(x) for x in sys.version_info[:3]]))"
+                    OUTPUT_VARIABLE _VERSION
                     RESULT_VARIABLE _PYTHON_VERSION_RESULT
-                    OUTPUT_QUIET
-                    ERROR_STRIP_TRAILING_WHITESPACE)
-    if(_PYTHON_VERSION_RESULT)
-        execute_process(COMMAND "${PYTHON_EXECUTABLE}" -V
-                        ERROR_VARIABLE _VERSION
+                    ERROR_QUIET)
+    if(NOT _PYTHON_VERSION_RESULT)
+        string(REPLACE ";" "." PYTHON_VERSION_STRING "${_VERSION}")
+        list(GET _VERSION 0 PYTHON_VERSION_MAJOR)
+        list(GET _VERSION 1 PYTHON_VERSION_MINOR)
+        list(GET _VERSION 2 PYTHON_VERSION_PATCH)
+        if(PYTHON_VERSION_PATCH EQUAL 0)
+            # it's called "Python 2.7", not "2.7.0"
+            string(REGEX REPLACE "\\.0$" "" PYTHON_VERSION_STRING "${PYTHON_VERSION_STRING}")
+        endif()
+    else()
+        # sys.version predates sys.version_info, so use that
+        execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c "import sys; sys.stdout.write(sys.version)"
+                        OUTPUT_VARIABLE _VERSION
                         RESULT_VARIABLE _PYTHON_VERSION_RESULT
-                        OUTPUT_QUIET
-                        ERROR_STRIP_TRAILING_WHITESPACE)
-    endif(_PYTHON_VERSION_RESULT)
-    if(NOT _PYTHON_VERSION_RESULT AND _VERSION MATCHES "^Python [0-9]+\\.[0-9]+.*")
-        string(REPLACE "Python " "" PYTHON_VERSION_STRING "${_VERSION}")
-        string(REGEX REPLACE "^([0-9]+)\\.[0-9]+.*" "\\1" PYTHON_VERSION_MAJOR "${PYTHON_VERSION_STRING}")
-        string(REGEX REPLACE "^[0-9]+\\.([0-9])+.*" "\\1" PYTHON_VERSION_MINOR "${PYTHON_VERSION_STRING}")
-        if(PYTHON_VERSION_STRING MATCHES "^[0-9]+\\.[0-9]+\\.[0-9]+.*")
-            string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" PYTHON_VERSION_PATCH "${PYTHON_VERSION_STRING}")
+                        ERROR_QUIET)
+        if(NOT _PYTHON_VERSION_RESULT)
+            string(REGEX REPLACE " .*" "" PYTHON_VERSION_STRING "${_VERSION}")
+            string(REGEX REPLACE "^([0-9]+)\\.[0-9]+.*" "\\1" PYTHON_VERSION_MAJOR "${PYTHON_VERSION_STRING}")
+            string(REGEX REPLACE "^[0-9]+\\.([0-9])+.*" "\\1" PYTHON_VERSION_MINOR "${PYTHON_VERSION_STRING}")
+            if(PYTHON_VERSION_STRING MATCHES "^[0-9]+\\.[0-9]+\\.[0-9]+.*")
+                string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" PYTHON_VERSION_PATCH "${PYTHON_VERSION_STRING}")
+            else()
+                set(PYTHON_VERSION_PATCH "0")
+            endif()
+        else()
+            # sys.version was first documented for Python 1.5, so assume
+            # this is older.
+            set(PYTHON_VERSION_STRING "1.4")
+            set(PYTHON_VERSION_MAJOR "1")
+            set(PYTHON_VERSION_MAJOR "4")
+            set(PYTHON_VERSION_MAJOR "0")
         endif()
     endif()
     unset(_PYTHON_VERSION_RESULT)

-----------------------------------------------------------------------

Summary of changes:


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list