[BUG]: cmake: pybind11::embed target doesn't link to Python libs if find_package(Python) has been called previously
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
Required prerequisites
- Make sure you've read the documentation. Your issue may be addressed there.
- Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- Consider asking first in the Gitter chat room or in a Discussion.
What version (or hash if on master) of pybind11 are you using?
3.0.4
Problem description
If find_package(pybind11) is called after a previous find_package(Python) without the development component, then the pybind11::embed target is missing a link to the Python::Python target.
Test case:
cmake_minimum_required(VERSION 3.5)
include(CMakePrintHelpers)
find_package(Python COMPONENTS Interpreter)
find_package(pybind11 REQUIRED)
cmake_print_properties(
TARGETS pybind11::embed
PROPERTIES INTERFACE_LINK_LIBRARIES
)
Output:
Properties for TARGET pybind11::embed:
pybind11::embed.INTERFACE_LINK_LIBRARIES = "pybind11::pybind11"
Note that Python::Python is missing. In https://github.com/pybind/pybind11/blob/v3.0.4/tools/pybind11NewTools.cmake#L96 _Python is set to Python without a check for the Python::Python target (which only exists if the Development component has been requested in the find_package(Python) call), but then this target is needed in https://github.com/pybind/pybind11/blob/v3.0.4/tools/pybind11NewTools.cmake#L227.
The previous find_package(Python) may have been issued by some dependency, so this is not always under the project's control.
Reproducible example code
Is this a regression? Put the last known working version here if it is.
Not a regression
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with tools/pybind11NewTools.cmake around lines 96 and 227, then reproduce the issue using the CMakeLists.txt example with an earlier find_package(Python COMPONENTS Interpreter). Inspect the existing CMake test coverage for pybind11::embed; done means the target links Python::Python even when Python was previously found without the Development component.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, cpp, python
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 74/100