fix: cross-compilation updates #5829
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR updates the Android linking workaround in pybind11NewTools.cmake to be compatible with vcpkg, as discussed at #5733 (review). I've also submitted an upstream fix to CMake, so this workaround can eventually be removed.
However, most of the PR is about CMake policy CMP0190, which prohibits calling FindPython with both the
Interpreter
andDevelopment
components at the same time when cross-compiling:Enabled
PYBIND11_USE_CROSSCOMPILING
whenever CMP0190 is in effect.Updated pybind11NewTools.cmake so it no longer requires the
Interpreter
component, whether cross-compiling or not. This allows packages to use the same configuration for both cases.Improved pybind11GuessPythonExtSuffix.cmake:
SKBUILD_SOABI
as another possible source of the Python module suffix.CACHE
, just as they are when they're detected from the interpreter. Previously they were set to thePARENT_SCOPE
, but that's the module scope of pybind11NewTools.cmake, which isn't accessible when calling functions from a different module. As a result, modules created usingpybind11_add_module
were being built with no extension at all!To encourage packages to be compatible with cross-compilation, I've removed
Interpreter
from all the documentation, examples and tests, except for the places which actually needed it.The new policy can be tested by changing the
cmake_minimum_required
upper limit in CMakeLists.txt from 4.0 to 4.1, and then using cibuildwheel to build thetests
project. However, I haven't changed thecmake_minimum_required
in this PR, because I'm not sure what other effects it might have.See also:
Suggested changelog entry:
Interpreter
andDevelopment
components at the same time when cross-compiling.📚 Documentation preview 📚: https://pybind11--5829.org.readthedocs.build/