summaryrefslogtreecommitdiffstats
path: root/Modules/FindPythonInterp.cmake
diff options
context:
space:
mode:
authorRolf Eike Beer <eike@sf-mail.de>2012-01-19 22:31:38 (GMT)
committerRolf Eike Beer <eike@sf-mail.de>2012-01-19 22:59:48 (GMT)
commitaa11536c38846b08c8adef6c6a55f0f249cae439 (patch)
tree2fed9f55f04f296c3725174b893f41a2b615c7e5 /Modules/FindPythonInterp.cmake
parent0fe4d69b6f5cfa4c2cd7afc6c0a42eb03638b712 (diff)
downloadCMake-aa11536c38846b08c8adef6c6a55f0f249cae439.zip
CMake-aa11536c38846b08c8adef6c6a55f0f249cae439.tar.gz
CMake-aa11536c38846b08c8adef6c6a55f0f249cae439.tar.bz2
FindPythonInterp: fix version parsing
On dashmacmini2 the test showed output like this: -- Found PythonInterp: /usr/bin/python (found version "Unknown option: -- usage: /usr/bin/python [option] ... [-c cmd | file | -] [arg] ... Try `python -h' for more information.") On my machine where python outputs "Python 2.7" this worked, but PYTHON_VERSION_MAJOR, PYTHON_VERSION_MINOR, and PYTHON_VERSION_PATCH were all set to "2.7". Add some checks that the version output has the expected form before using it.
Diffstat (limited to 'Modules/FindPythonInterp.cmake')
-rw-r--r--Modules/FindPythonInterp.cmake14
1 files changed, 9 insertions, 5 deletions
diff --git a/Modules/FindPythonInterp.cmake b/Modules/FindPythonInterp.cmake
index 128dcd5..d5a2a5e 100644
--- a/Modules/FindPythonInterp.cmake
+++ b/Modules/FindPythonInterp.cmake
@@ -89,11 +89,15 @@ endif()
# determine python version string
if(PYTHON_EXECUTABLE)
execute_process(COMMAND "${PYTHON_EXECUTABLE}" --version ERROR_VARIABLE _VERSION OUTPUT_QUIET ERROR_STRIP_TRAILING_WHITESPACE)
- string(REPLACE "Python " "" PYTHON_VERSION_STRING "${_VERSION}")
- string(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" PYTHON_VERSION_MAJOR "${PYTHON_VERSION_STRING}")
- string(REGEX REPLACE "^[0-9]+\\.([0-9])+\\.[0-9]+.*" "\\1" PYTHON_VERSION_MINOR "${PYTHON_VERSION_STRING}")
- string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" PYTHON_VERSION_PATCH "${PYTHON_VERSION_STRING}")
-endif()
+ if(_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}")
+ endif()
+ endif()
+endif(PYTHON_EXECUTABLE)
# handle the QUIETLY and REQUIRED arguments and set PYTHONINTERP_FOUND to TRUE if
# all listed variables are TRUE