Skip to content

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

@antonio-rojas

Description

@antonio-rojas

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageNew bug, unverified

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions