Commit 20980ef56a847fec7922983257fd5be467b689bd changed the FindPythonInterp 
to search for "python" first, instead of prefering the most recent (python 2) 
version. This was intended to allow the user to have a different default 
python than the newest version. But for the same reason it is as wrong :/

Today a user was in #cmake that had a system default python that was some 3.x 
version, and therefore /usr/bin/python was a symlink to /usr/bin/python3. The 
current module has no possiblity for a developer to specify that 
FindPythonInterp should search for python2 first. So I wrote the attached 
patch which allow the developer to say that a python2 or python3 major version 
should be preferred.

This is actually a bit hacky, but nevertheless "works for him"(tm). But 
actually I think the whole version selection stuff in this module needs an 
overhaul. If the user says he needs e.g. version 2.5 the first look should be 
python2.5, and then check python2, python, and whatever. Instead python is 
checked first (may be 3.x), if that is not found e.g. 2.7 is checked (which 
may be wrong for the same reason as stated in the above commit).

At the end this thing finds "some" python version and then lets FPHSA check if 
that version matches the user desired version. Instead it should _first_ 
actually try to find the desired version (which is rather easy for python), 
and later call FPHSA.

Also this module doesn't know at all about python 3 major versions, so with a 
system default python of python2 (like Gentoo currently has) a requested 
version of 3.0 will always fail if the user does not explicitely specify the 
correct python interpreter on the command line.

Opinions?

Eike
>From 68fd2901923ea97f547edcf298bda819bec4bce4 Mon Sep 17 00:00:00 2001
From: Rolf Eike Beer <e...@sf-mail.de>
Date: Tue, 17 Jan 2012 19:20:10 +0100
Subject: [PATCH] FindPythonInterp: make major version selectable

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

Attachment: signature.asc
Description: This is a digitally signed message part.

--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers

Reply via email to