In older cmake versions, we would use find_package(PythonInterp 3.4 REQUIRED) find_package(PythonLibs 3.4 REQUIRED) with cmake >= 3.12 we can replace that with find_package(Python3 3.4 REQUIRED COMPONENTS Interpreter Development) The old method will find the python version matching the python version set in DEFAULT_VERSIONS The newer python3 method always gets the largest python version installed, not the default version. example using old method (CORRECT) - find_package(PythonLibs 3.4 REQUIRED) -- Found PythonLibs: /usr/local/lib/libpython3.7m.so (found suitable version "3.7.9", minimum required is "3.4") change this to new method (WRONG) - find_package(Python3 3.4 REQUIRED COMPONENTS Interpreter Development) -- Found Python3: /usr/local/bin/python3.9 (found suitable version "3.9.0", minimum required is "3.4") found components: Interpreter Development Development.Module Development.Embed The new way should find the same py3.7 This is using cmake 3.18.5 and still applies to 3.19.2 found in bug #251920
So, is this a bug against cmake, or a bug against the ports that use cmake? It is not clear to me from the description.
Against cmake, any port that calls find_package(python3 ...) will get the wrong version. At least when more than one python version is installed. The old method using find_package(PythonInterp ...) still works as expected. The newer method find_package(Python3 ...) does not find the default version, it always finds the newest python version. This differs from the previous methods behaviour. This new method was added to cmake v3.12 and has not yet been adopted by every port using cmake and python.