[CMake] CMake finds the wrong Python interpreter on Windows
Michael Wild
themiwi at gmail.com
Fri Feb 26 03:05:58 EST 2010
On 25. Feb, 2010, at 22:39 , James Amundson wrote:
> On 02/25/2010 12:29 PM, Bill Hoffman wrote:
>> OK, so that is the problem....
>>
>> It looks for names in this order:
>>
>> NAMES python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0 python1.6 python1.5 python
>>
> Coincidently, I had a bug report that arose from the above ordering just this afternoon. It makes no sense to me. I think "python" should be the first choice, not the last choice. What's the logic there?
>
> --Jim Amundson
Probably the idea was that one wants to find the newest Python version first, and with the versioned pythonX.Y names this is relatively easy. With the unversioned name, it's not that easy...
Perhaps something like this (completely untested)?
set(_fpi_versions 2.6 2.5 2.4 2.3 2.2 2.1 2.0 1.6 1.5)
foreach(_fpi_v IN LISTS _fpi_versions)
string(REPLACE "." "" _fpi_n python${_fpi_v})
if(WIN32)
# on WIN32 search registered installations first
find_executable(PYTHON_${_fpi_n}_EXECUTABLE python
PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_fpi_v}\\InstallPath]
NO_DEFAULT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH
NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH NO_CMAKE_FIND_ROOT_PATH)
endif()
# then proceed to normal search
find_executable(PYTHON_${_fpi_n}_EXECUTABLE NAMES python${_fpi_v} python)
if(PYTHON_${_fpi_n}_EXECUTABLE)
# if we found a python interpreter, set PYTHON_EXECUTABLE and don't search further
set(PYTHON_EXECUTABLE "${PYTHON_${_fpi_n}_EXECUTABLE}")
break()
endif()
endforeach()
Of course, FindPythonLibs.cmake should be smartened up to first search for PythonInterp, and then use that result to come up with good guesses used in HINT. Also it should fail if it can't find the libraries/headers that match the interpreter that has been discovered...
Michael
More information about the CMake
mailing list