Bug 252277 - cmake find_package(python3...) fails to get default python version
Summary: cmake find_package(python3...) fails to get default python version
Status: New
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-ports-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-12-30 00:01 UTC by Shane
Modified: 2020-12-31 00:12 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Shane 2020-12-30 00:01:12 UTC
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
Comment 1 Mark Linimon freebsd_committer freebsd_triage 2020-12-30 11:36:42 UTC
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.
Comment 2 Shane 2020-12-31 00:12:55 UTC
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.