summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2019-01-21 15:41:59 (GMT)
committerBrad King <brad.king@kitware.com>2019-01-22 15:43:08 (GMT)
commit08dee696b5831a8cba0a70df5e6b072f91d0c6f8 (patch)
tree67ccb4d47e3257efa27ea4078891b2ebbd89b8dc
parent02f7e997e939dbd0c753514edcd580083cebd37c (diff)
downloadCMake-08dee696b5831a8cba0a70df5e6b072f91d0c6f8.zip
CMake-08dee696b5831a8cba0a70df5e6b072f91d0c6f8.tar.gz
CMake-08dee696b5831a8cba0a70df5e6b072f91d0c6f8.tar.bz2
FindPythonInterp: Do not assume any version if test script fails
The Python version is retrieved by executing a small python script. If, for any reason, script fails to execute, leave the `PYTHON_VERSION_*` variables undefined instead of assuming version 1.4. Fixes: #18799
-rw-r--r--Modules/FindPythonInterp.cmake14
1 files changed, 7 insertions, 7 deletions
diff --git a/Modules/FindPythonInterp.cmake b/Modules/FindPythonInterp.cmake
index d1f7b31..da33301 100644
--- a/Modules/FindPythonInterp.cmake
+++ b/Modules/FindPythonInterp.cmake
@@ -130,7 +130,9 @@ if(PYTHON_EXECUTABLE)
endif()
else()
# sys.version predates sys.version_info, so use that
- execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c "import sys; sys.stdout.write(sys.version)"
+ # sys.version was first documented for Python 1.5, so assume version 1.4
+ # if retrieving sys.version fails.
+ execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c "try: import sys; sys.stdout.write(sys.version)\nexcept: sys.stdout.write(\"1.4.0\")"
OUTPUT_VARIABLE _VERSION
RESULT_VARIABLE _PYTHON_VERSION_RESULT
ERROR_QUIET)
@@ -144,12 +146,10 @@ if(PYTHON_EXECUTABLE)
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_MINOR "4")
- set(PYTHON_VERSION_PATCH "0")
+ unset(PYTHON_VERSION_STRING)
+ unset(PYTHON_VERSION_MAJOR)
+ unset(PYTHON_VERSION_MINOR)
+ unset(PYTHON_VERSION_PATCH)
endif()
endif()
unset(_PYTHON_VERSION_RESULT)