summaryrefslogtreecommitdiff
path: root/Modules/FindPythonInterp.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2014-03-14 09:30:24 -0400
committerCMake Topic Stage <kwrobot@kitware.com>2014-03-14 09:30:24 -0400
commit92b423fc2f504c645405669ffa5659c2268c6445 (patch)
tree6eb5a6581864b4dd2bfd7d3aa2aad08bd57c50a9 /Modules/FindPythonInterp.cmake
parent32b7d2ed8a4286de5db18883b1db7cdc4f902598 (diff)
parent59220198022d2e081ddba164c1ec62a6e9d438eb (diff)
downloadcmake-92b423fc2f504c645405669ffa5659c2268c6445.tar.gz
Merge topic 'different-python-header-libs-exe-0013794'
59220198 FindPython*: Document suggested find_package order (#13794) a9e6de2a FindPythonInterp: Use consistent version with PythonLibs (#13794)
Diffstat (limited to 'Modules/FindPythonInterp.cmake')
-rw-r--r--Modules/FindPythonInterp.cmake27
1 files changed, 18 insertions, 9 deletions
diff --git a/Modules/FindPythonInterp.cmake b/Modules/FindPythonInterp.cmake
index e23a58b3ed..c41f3a7f61 100644
--- a/Modules/FindPythonInterp.cmake
+++ b/Modules/FindPythonInterp.cmake
@@ -27,6 +27,10 @@
# of version numbers that should be taken into account when searching
# for Python. You need to set this variable before calling
# find_package(PythonInterp).
+#
+# If also calling find_package(PythonLibs), call find_package(PythonInterp)
+# first to get the currently active Python version by default with a consistent
+# version of PYTHON_LIBRARIES.
#=============================================================================
# Copyright 2005-2010 Kitware, Inc.
@@ -71,18 +75,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 +100,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)