summaryrefslogtreecommitdiffstats
path: root/Modules/FindPythonInterp.cmake
diff options
context:
space:
mode:
authorMatt McCormick <matt.mccormick@kitware.com>2014-03-05 22:01:26 (GMT)
committerBrad King <brad.king@kitware.com>2014-03-14 13:09:58 (GMT)
commita9e6de2acc1ac2e51b4d737b3abbeee3bf43832c (patch)
treed13b9bd7192b74d23fa8ec6f075e027abceb7f7d /Modules/FindPythonInterp.cmake
parentbf28ff1f422407f10ecc283f03ce8c5ee57f1812 (diff)
downloadCMake-a9e6de2acc1ac2e51b4d737b3abbeee3bf43832c.zip
CMake-a9e6de2acc1ac2e51b4d737b3abbeee3bf43832c.tar.gz
CMake-a9e6de2acc1ac2e51b4d737b3abbeee3bf43832c.tar.bz2
FindPythonInterp: Use consistent version with PythonLibs (#13794)
If find_package(PythonLibs) find_package(PythonInterp) is called, help PythonInterp to get a version of PYTHON_EXECUTABLE consistent with the library versions found by PythonLibs.
Diffstat (limited to 'Modules/FindPythonInterp.cmake')
-rw-r--r--Modules/FindPythonInterp.cmake23
1 files changed, 14 insertions, 9 deletions
diff --git a/Modules/FindPythonInterp.cmake b/Modules/FindPythonInterp.cmake
index 8da848c..780cda8 100644
--- a/Modules/FindPythonInterp.cmake
+++ b/Modules/FindPythonInterp.cmake
@@ -71,18 +71,23 @@ if(PythonInterp_FIND_VERSION)
else()
set(_PYTHON_FIND_OTHER_VERSIONS ${_PYTHON3_VERSIONS} ${_PYTHON2_VERSIONS} ${_PYTHON1_VERSIONS})
endif()
-
-list(APPEND _Python_NAMES python)
-
-# Search for the current active python version first
find_program(PYTHON_EXECUTABLE NAMES ${_Python_NAMES})
# Set up the versions we know about, in the order we will search. Always add
# the user supplied additional versions to the front.
-set(_Python_VERSIONS
- ${Python_ADDITIONAL_VERSIONS}
- ${_PYTHON_FIND_OTHER_VERSIONS}
- )
+set(_Python_VERSIONS ${Python_ADDITIONAL_VERSIONS})
+# If FindPythonInterp has already found the major and minor version,
+# insert that version next to get consistent versions of the interpreter and
+# library.
+if(DEFINED PYTHONLIBS_VERSION_STRING)
+ string(REPLACE "." ";" _PYTHONLIBS_VERSION "${PYTHONLIBS_VERSION_STRING}")
+ list(GET _PYTHONLIBS_VERSION 0 _PYTHONLIBS_VERSION_MAJOR)
+ list(GET _PYTHONLIBS_VERSION 1 _PYTHONLIBS_VERSION_MINOR)
+ list(APPEND _Python_VERSIONS ${_PYTHONLIBS_VERSION_MAJOR}.${_PYTHONLIBS_VERSION_MINOR})
+endif()
+# Search for the current active python version first
+list(APPEND _Python_VERSIONS ";")
+list(APPEND _Python_VERSIONS ${_PYTHON_FIND_OTHER_VERSIONS})
unset(_PYTHON_FIND_OTHER_VERSIONS)
unset(_PYTHON1_VERSIONS)
@@ -91,7 +96,7 @@ unset(_PYTHON3_VERSIONS)
# Search for newest python version if python executable isn't found
if(NOT PYTHON_EXECUTABLE)
- foreach(_CURRENT_VERSION ${_Python_VERSIONS})
+ foreach(_CURRENT_VERSION IN LISTS _Python_VERSIONS)
set(_Python_NAMES python${_CURRENT_VERSION})
if(WIN32)
list(APPEND _Python_NAMES python)