pybind / pybind11

Seamless operability between C++11 and Python
https://pybind11.readthedocs.io/
Other
15.11k stars 2.05k forks source link

[BUG]: Cannot overwrite PYTHON_MODULE_EXTENSION when FindPython3.cmake is used #4854

Closed ilya-lavrenov closed 6 months ago

ilya-lavrenov commented 9 months ago

Required prerequisites

What version (or hash if on master) of pybind11 are you using?

v2.11.1

Problem description

I'm trying to migrate our project from old FindPythonInterp and FindPythonLibs cmake modules to new FindPython3. We are using cross-compilation in our project to compile ARM64 C++ and Python binaries.

In order to have a proper python extension for compiled modules, I used PYTHON_MODULE_EXTENSION. But with migration to new cmake python modules, it triggers different code path inside pybind11. In fact, PYTHON_MODULE_EXTENSION ignores my value set via cmake cmd.

This because of first run, pybind11 checks: https://github.com/pybind/pybind11/blob/5891867ee4ad1d671e0f54c5fb30f62d1322d8d0/tools/pybind11NewTools.cmake#L76-L83 While PYBIND11_PYTHON_EXECUTABLE_LAST is empty and unsets user-specified value for PYTHON_MODULE_EXTENSION. And later it sets PYTHON_MODULE_EXTENSION which results in build platform prefix: https://github.com/pybind/pybind11/blob/5891867ee4ad1d671e0f54c5fb30f62d1322d8d0/tools/pybind11NewTools.cmake#L98-L128

pybind11 has a cmake option PYBIND11_PYTHONLIBS_OVERWRITE, maybe we need to introduce something for FindPython3.cmake case? Or completely remove such under for the first cmake iteration.

Reproducible example code

See above

Is this a regression? Put the last known working version here if it is.

Not a regression