FindPython3 and FindPython2 appear broken as of cmake 3.18.2
Hi all,
This issue started when I upgraded to cmake 3.18.2. I am not entirely sure what version I was on prior to this unfortunately.
I also have both Python2 and Python3 installed, both in /usr/bin
I am running the following on linux and the following errors have been seen on more than one machine, and reported in the wild.
The following code:
if(NOT CMAKE_VERSION VERSION_LESS 3.15.0)
set(Python3_FIND_STRATEGY LOCATION)
find_package(Python3 COMPONENTS Interpreter)
if(Python3_Interpreter_FOUND)
set(PROJECT_PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
endif()
else()
find_package(PythonInterp 3)
if(PYTHONINTERP_FOUND)
set(PROJECT_PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})
endif()
endif()
if(PROJECT_PYTHON_EXECUTABLE)
...
Worked prior to the update (obviously taking the top branch), but now can no longer find either Python 2 or 3 Interpreter. Interestingly it appears to have no issues finding Development
for either Python2 or Python3
If I use set(Python3_FIND_STRATEGY LOCATION)
(rather than VERSION
) then this works fine, and finds Python3, however this method is clearly deprecated.
If I use find_package(Python COMPONENTS Interpreter)
(rather than Python3) then this works, and finds Python3, however this is clearly not what we should be using here when we only want Python3.
All of the above appear to fail for find_package(Python2, COMPONENTS Interpreter)
as well.
This started at the same time as the warnings about CMP0011 started (which impacts find_package), so I strongly suspect this might be connected, however this appears to happen whether I use cmake_policy(SET CMP0011 OLD)
or cmake_policy(SET CMP0011 NEW)
What does appear to fix it is setting a max version, i.e. cmake_minimum_required(VERSION 2.6...3.18)
and this is what I will be using to fix this for the time being, as I say, people have reported this issue with our project.
Thanks in advance for any help!