fix(cmake): find missing Python development components#6116
Draft
henryiii wants to merge 1 commit into
Draft
Conversation
If a parent project called find_package(Python) without the development components, pybind11 skipped its own find, so pybind11_add_module failed and pybind11::embed did not link to Python::Python. Ask FindPython for the missing components instead, keeping the interpreter already selected. Assisted-by: ClaudeCode:claude-opus-5 Claude-Session: https://claude.ai/code/session_013JABmnjt9oAh29p1pytAB3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
I think this is both helpful and there are issues with it. Will investigate. See #6112.
🤖 AI text below 🤖
Description
pybind11NewTools.cmakeskipped its Python discovery ifPython_FOUNDorPython3_FOUNDwas set. A parent project that didfind_package(Python COMPONENTS Interpreter)(frequently out of the user's control) thus left pybind11 without the development components, which caused:pybind11_add_moduleto fail withUnknown CMake command "python_add_library"ortarget Python::Module is not defined,pybind11::embedto silently miss the link toPython::Python.pybind11 now asks FindPython for the missing development components instead of skipping the find. It keeps the name (
PythonorPython3) and the interpreter that the parent project selected, and it makes the new targets global in submodule mode. If the parent project already supplied the development components, the behavior does not change.The
subdirectory_embedCMake build test now does a partialfind_package(Python COMPONENTS Interpreter)first, which fails without this fix.Supersedes #5814, which removed the guard completely.
Fixes #5813
Fixes #5472
Fixes #6063
Suggested changelog entry:
find_package(Python)from a parent project without the development components no longer breakspybind11_add_moduleor thepybind11::embedlink to Python.https://claude.ai/code/session_013JABmnjt9oAh29p1pytAB3