On 11. april 2013 21:31, Matthew Woehlke wrote:
>> Where do I submit the merge request? Open a bug report?
>
> I would recommend following the 'share a topic' instructions at
> http://www.cmake.org/Wiki/CMake/Git/Develop. 

Thanks for the link, but I feel this is more for module keepers, and
this is not my module. I think Eike is responsible for this module (at
least he has the last commits), so I would prefer if he or someone else
with commit access could push it to the stage repository for review (if
they agree with the patch).

In case you find it easier I also attach the patches. Note that the
second patch reverts the changes in the first patch (which is the one I
sent earlier).

Best Regards,
Yngve
>From 861cfe1ee2b65e99d2b402b2dcdca84fac71a14a Mon Sep 17 00:00:00 2001
From: Yngve Inntjore Levinsen <[email protected]>
Date: Thu, 11 Apr 2013 19:59:55 +0200
Subject: [PATCH 1/2] first proposal (not ideal)

---
 Modules/FindPythonInterp.cmake | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Modules/FindPythonInterp.cmake b/Modules/FindPythonInterp.cmake
index 7fb65b8..60a0f53 100644
--- a/Modules/FindPythonInterp.cmake
+++ b/Modules/FindPythonInterp.cmake
@@ -39,15 +39,17 @@ if(PythonInterp_FIND_VERSION)
     if(PythonInterp_FIND_VERSION MATCHES "^[0-9]+\\.[0-9]+(\\.[0-9]+.*)?$")
         string(REGEX REPLACE "^([0-9]+\\.[0-9]+).*" "\\1" _PYTHON_FIND_MAJ_MIN "${PythonInterp_FIND_VERSION}")
         string(REGEX REPLACE "^([0-9]+).*" "\\1" _PYTHON_FIND_MAJ "${_PYTHON_FIND_MAJ_MIN}")
-        list(APPEND _Python_NAMES python${_PYTHON_FIND_MAJ_MIN} python${_PYTHON_FIND_MAJ})
+        list(APPEND _Python_NAMES python${_PYTHON_FIND_MAJ_MIN})
         unset(_PYTHON_FIND_OTHER_VERSIONS)
         if(NOT PythonInterp_FIND_VERSION_EXACT)
             foreach(_PYTHON_V ${_PYTHON${_PYTHON_FIND_MAJ}_VERSIONS})
                 if(NOT _PYTHON_V VERSION_LESS _PYTHON_FIND_MAJ_MIN)
                     list(APPEND _PYTHON_FIND_OTHER_VERSIONS ${_PYTHON_V})
+                    list(APPEND _Python_NAMES python${_PYTHON_V})
                 endif()
              endforeach()
         endif()
+        list(APPEND _Python_NAMES python${_PYTHON_FIND_MAJ})
         unset(_PYTHON_FIND_MAJ_MIN)
         unset(_PYTHON_FIND_MAJ)
     else()
-- 
1.8.0.2

>From 46bba97a2b3de429fecc1ec3413721b6d288c604 Mon Sep 17 00:00:00 2001
From: Yngve Inntjore Levinsen <[email protected]>
Date: Thu, 11 Apr 2013 20:34:15 +0200
Subject: [PATCH 2/2] second proposal I think this is not breaking old logic
 while fixing issue with python/python2 being too old

Tested on my system, which has python/python2 = 2.4,
but also python2.6 available.

Before, 'find_package(PythonInterp 2.5)' would find
python2 and note that it was too old. Now, it finds
python2.6
---
 Modules/FindPythonInterp.cmake | 90 ++++++++++++++++++++++++------------------
 1 file changed, 52 insertions(+), 38 deletions(-)

diff --git a/Modules/FindPythonInterp.cmake b/Modules/FindPythonInterp.cmake
index 60a0f53..3703f6c 100644
--- a/Modules/FindPythonInterp.cmake
+++ b/Modules/FindPythonInterp.cmake
@@ -39,17 +39,15 @@ if(PythonInterp_FIND_VERSION)
     if(PythonInterp_FIND_VERSION MATCHES "^[0-9]+\\.[0-9]+(\\.[0-9]+.*)?$")
         string(REGEX REPLACE "^([0-9]+\\.[0-9]+).*" "\\1" _PYTHON_FIND_MAJ_MIN "${PythonInterp_FIND_VERSION}")
         string(REGEX REPLACE "^([0-9]+).*" "\\1" _PYTHON_FIND_MAJ "${_PYTHON_FIND_MAJ_MIN}")
-        list(APPEND _Python_NAMES python${_PYTHON_FIND_MAJ_MIN})
+        list(APPEND _Python_NAMES python${_PYTHON_FIND_MAJ_MIN} python${_PYTHON_FIND_MAJ})
         unset(_PYTHON_FIND_OTHER_VERSIONS)
         if(NOT PythonInterp_FIND_VERSION_EXACT)
             foreach(_PYTHON_V ${_PYTHON${_PYTHON_FIND_MAJ}_VERSIONS})
                 if(NOT _PYTHON_V VERSION_LESS _PYTHON_FIND_MAJ_MIN)
                     list(APPEND _PYTHON_FIND_OTHER_VERSIONS ${_PYTHON_V})
-                    list(APPEND _Python_NAMES python${_PYTHON_V})
                 endif()
              endforeach()
         endif()
-        list(APPEND _Python_NAMES python${_PYTHON_FIND_MAJ})
         unset(_PYTHON_FIND_MAJ_MIN)
         unset(_PYTHON_FIND_MAJ)
     else()
@@ -77,8 +75,8 @@ unset(_PYTHON1_VERSIONS)
 unset(_PYTHON2_VERSIONS)
 unset(_PYTHON3_VERSIONS)
 
-# Search for newest python version if python executable isn't found
-if(NOT PYTHON_EXECUTABLE)
+# This macro will search for all versions specified in input argument list
+macro(_Find_Other_Versions)
     foreach(_CURRENT_VERSION ${_Python_VERSIONS})
       set(_Python_NAMES python${_CURRENT_VERSION})
       if(WIN32)
@@ -89,50 +87,66 @@ if(NOT PYTHON_EXECUTABLE)
         PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]
         )
     endforeach()
+endmacro()
+
+# Search for newest python version if python executable isn't found
+if(NOT PYTHON_EXECUTABLE)
+    _Find_Other_Versions(${_Python_VERSIONS})
 endif()
 
 # determine python version string
-if(PYTHON_EXECUTABLE)
-    execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c
-                            "import sys; sys.stdout.write(';'.join([str(x) for x in sys.version_info[:3]]))"
-                    OUTPUT_VARIABLE _VERSION
-                    RESULT_VARIABLE _PYTHON_VERSION_RESULT
-                    ERROR_QUIET)
-    if(NOT _PYTHON_VERSION_RESULT)
-        string(REPLACE ";" "." PYTHON_VERSION_STRING "${_VERSION}")
-        list(GET _VERSION 0 PYTHON_VERSION_MAJOR)
-        list(GET _VERSION 1 PYTHON_VERSION_MINOR)
-        list(GET _VERSION 2 PYTHON_VERSION_PATCH)
-        if(PYTHON_VERSION_PATCH EQUAL 0)
-            # it's called "Python 2.7", not "2.7.0"
-            string(REGEX REPLACE "\\.0$" "" PYTHON_VERSION_STRING "${PYTHON_VERSION_STRING}")
-        endif()
-    else()
-        # sys.version predates sys.version_info, so use that
-        execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c "import sys; sys.stdout.write(sys.version)"
+macro(_Determine_Python_Version)
+    if(PYTHON_EXECUTABLE)
+        execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c
+                                "import sys; sys.stdout.write(';'.join([str(x) for x in sys.version_info[:3]]))"
                         OUTPUT_VARIABLE _VERSION
                         RESULT_VARIABLE _PYTHON_VERSION_RESULT
                         ERROR_QUIET)
         if(NOT _PYTHON_VERSION_RESULT)
-            string(REGEX REPLACE " .*" "" PYTHON_VERSION_STRING "${_VERSION}")
-            string(REGEX REPLACE "^([0-9]+)\\.[0-9]+.*" "\\1" PYTHON_VERSION_MAJOR "${PYTHON_VERSION_STRING}")
-            string(REGEX REPLACE "^[0-9]+\\.([0-9])+.*" "\\1" PYTHON_VERSION_MINOR "${PYTHON_VERSION_STRING}")
-            if(PYTHON_VERSION_STRING MATCHES "^[0-9]+\\.[0-9]+\\.[0-9]+.*")
-                string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" PYTHON_VERSION_PATCH "${PYTHON_VERSION_STRING}")
-            else()
-                set(PYTHON_VERSION_PATCH "0")
+            string(REPLACE ";" "." PYTHON_VERSION_STRING "${_VERSION}")
+            list(GET _VERSION 0 PYTHON_VERSION_MAJOR)
+            list(GET _VERSION 1 PYTHON_VERSION_MINOR)
+            list(GET _VERSION 2 PYTHON_VERSION_PATCH)
+            if(PYTHON_VERSION_PATCH EQUAL 0)
+                # it's called "Python 2.7", not "2.7.0"
+                string(REGEX REPLACE "\\.0$" "" PYTHON_VERSION_STRING "${PYTHON_VERSION_STRING}")
             endif()
         else()
-            # sys.version was first documented for Python 1.5, so assume
-            # this is older.
-            set(PYTHON_VERSION_STRING "1.4")
-            set(PYTHON_VERSION_MAJOR "1")
-            set(PYTHON_VERSION_MAJOR "4")
-            set(PYTHON_VERSION_MAJOR "0")
+            # sys.version predates sys.version_info, so use that
+            execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c "import sys; sys.stdout.write(sys.version)"
+                            OUTPUT_VARIABLE _VERSION
+                            RESULT_VARIABLE _PYTHON_VERSION_RESULT
+                            ERROR_QUIET)
+            if(NOT _PYTHON_VERSION_RESULT)
+                string(REGEX REPLACE " .*" "" PYTHON_VERSION_STRING "${_VERSION}")
+                string(REGEX REPLACE "^([0-9]+)\\.[0-9]+.*" "\\1" PYTHON_VERSION_MAJOR "${PYTHON_VERSION_STRING}")
+                string(REGEX REPLACE "^[0-9]+\\.([0-9])+.*" "\\1" PYTHON_VERSION_MINOR "${PYTHON_VERSION_STRING}")
+                if(PYTHON_VERSION_STRING MATCHES "^[0-9]+\\.[0-9]+\\.[0-9]+.*")
+                    string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" PYTHON_VERSION_PATCH "${PYTHON_VERSION_STRING}")
+                else()
+                    set(PYTHON_VERSION_PATCH "0")
+                endif()
+            else()
+                # sys.version was first documented for Python 1.5, so assume
+                # this is older.
+                set(PYTHON_VERSION_STRING "1.4")
+                set(PYTHON_VERSION_MAJOR "1")
+                set(PYTHON_VERSION_MAJOR "4")
+                set(PYTHON_VERSION_MAJOR "0")
+            endif()
         endif()
+        unset(_PYTHON_VERSION_RESULT)
+        unset(_VERSION)
     endif()
-    unset(_PYTHON_VERSION_RESULT)
-    unset(_VERSION)
+endmacro()
+
+_Determine_Python_Version()
+
+# In case we found a python executable, but it is too old
+if(${PYTHON_VERSION_STRING} VERSION_LESS ${PythonInterp_FIND_VERSION})
+   unset(PYTHON_EXECUTABLE CACHE)
+    _Find_Other_Versions(${_Python_VERSIONS})
+    _Determine_Python_Version()
 endif()
 
 # handle the QUIETLY and REQUIRED arguments and set PYTHONINTERP_FOUND to TRUE if
-- 
1.8.0.2

--

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://www.cmake.org/mailman/listinfo/cmake

Reply via email to