[Cmake-commits] CMake branch, next, updated. v2.8.7-2888-gf260055
Rolf Eike Beer
eike at sf-mail.de
Sun Feb 26 08:48:48 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 f26005559a37e4218464ce00f9b3df2e690ea3eb (commit)
via 5f3a3501baf437fb33ec851edb7934f74e6c3f68 (commit)
from 44d142836b8c6e397156365be45dbf1bb3122c6e (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=f26005559a37e4218464ce00f9b3df2e690ea3eb
commit f26005559a37e4218464ce00f9b3df2e690ea3eb
Merge: 44d1428 5f3a350
Author: Rolf Eike Beer <eike at sf-mail.de>
AuthorDate: Sun Feb 26 08:48:33 2012 -0500
Commit: CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Sun Feb 26 08:48:33 2012 -0500
Merge topic 'findpythoninterp-version-detection' into next
5f3a350 FindPythonInterp: rework the version detection
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=5f3a3501baf437fb33ec851edb7934f74e6c3f68
commit 5f3a3501baf437fb33ec851edb7934f74e6c3f68
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: Sun Feb 26 14:38:32 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..a2d6224 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,38 @@ 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)
+ 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:
Modules/FindPythonInterp.cmake | 47 ++++++++++++++++++++++++++-------------
1 files changed, 31 insertions(+), 16 deletions(-)
hooks/post-receive
--
CMake
More information about the Cmake-commits
mailing list