pybind / pybind/pybind11

[BUG]: cmake: pybind11::embed target doesn't link to Python libs if find_package(Python) has been called previously

Open
#6,063 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

triage
Dominant language
C++
Stars
18k
Forks
2.3k
Avg merge
5d 17h
Merged PRs (30d)
10

Description

Required prerequisites
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.