[PATCH] FindPythonInterp: make major version selectable

Rolf Eike Beer eike at sf-mail.de
Tue Jan 17 13:20:10 EST 2012


This allows the developer to tell FindPythonInterp which Python major version
should be searched for. This allows the right version to be chosen for a
project without user assistance if there are specific requirements.
---
 Modules/FindPythonInterp.cmake |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/Modules/FindPythonInterp.cmake b/Modules/FindPythonInterp.cmake
index a10ec23..87b537f 100644
--- a/Modules/FindPythonInterp.cmake
+++ b/Modules/FindPythonInterp.cmake
@@ -11,6 +11,10 @@
 #  PYTHON_VERSION_PATCH       - Python patch version found e.g. 2
 #
 #  Python_ADDITIONAL_VERSIONS - list of additional Python versions to search for
+#
+# You may specify either PYTHONINTERP_PREFER_PYTHON2 or
+# PYTHONINTERP_PREFER_PYTHON3 to tell the module to probe for a specific
+# python major version first.
 
 #=============================================================================
 # Copyright 2005-2010 Kitware, Inc.
@@ -26,8 +30,16 @@
 # (To distribute this file outside of CMake, substitute the full
 #  License text for the above reference.)
 
+set(_Python_NAMES python)
+
+if (PYTHONINTERP_PREFER_PYTHON2)
+    list(INSERT _Python_NAMES 0 "python2")
+elseif (PYTHONINTERP_PREFER_PYTHON3)
+    list(INSERT _Python_NAMES 0 "python3")
+endif()
+
 # Search for the current active python version first
-find_program(PYTHON_EXECUTABLE NAMES python)
+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.
-- 
1.7.7.3

--nextPart1405933.hDJdUHqbHm--

--nextPart4455805.1uQlExhJS4
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: This is a digitally signed message part.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.18 (GNU/Linux)

iEYEABECAAYFAk8VwvEACgkQXKSJPmm5/E7wVgCeLdQny2T8DySR3vo7E0BlU1ck
WHsAn2j7/GY2UxEP9hZbhzFsAaZ6x5qL
=yBTc
-----END PGP SIGNATURE-----

--nextPart4455805.1uQlExhJS4--



More information about the cmake-developers mailing list