Determine python version

Use PYTHON_EXECUTABLE to determine PYTHON_VERSION_STRING,
PYTHON_VERSION_MINOR, PYTHON_VERSION_MAJOR and PYTHON_VERSION_PATCH
This commit is contained in:
Björn Ricks 2011-07-14 11:43:47 +02:00
parent 20980ef56a
commit 4fd1e28495
1 changed files with 7 additions and 0 deletions

View File

@ -43,6 +43,13 @@ if(NOT PYTHON_EXECUTABLE)
endforeach() endforeach()
endif() endif()
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()
# handle the QUIETLY and REQUIRED arguments and set PYTHONINTERP_FOUND to TRUE if # handle the QUIETLY and REQUIRED arguments and set PYTHONINTERP_FOUND to TRUE if
# all listed variables are TRUE # all listed variables are TRUE