Skip to content

[BUG]: CMake target missing Python in CONFIG mode #4400

@mablanchard

Description

@mablanchard

Required prerequisites

What version (or hash if on master) of pybind11 are you using?

2.9.2

Problem description

From discussion #4309:

Looking for pybind11 in CMake CONFIG mode multiple times from separate directories doesn't seem to produce the same targets

From pybind11Common.cmake comments, pybind11 CMake script shall declare regular (ie. non-global) targets. It seems like pybind11NewTools.cmake is using a global include guard though, which explains why the second pybind11::embed targets does not get linked with Python::Python...

Reproducible example code

In FindPython mode, the following snippet:

find_package(
  Python
  COMPONENTS
    Interpreter Development
  QUIET)
find_package(
  pybind11 CONFIG # ${PYBIND11_VERSION} EXACT
  HINTS "${pybind11_ROOT}"
  QUIET)

get_target_property(
  __linkLibraries pybind11::embed INTERFACE_LINK_LIBRARIES)
message("pybind11::embed::INTERFACE_LINK_LIBRARIES=${__linkLibraries }")

Gives from first execution in the first directory the expected:

pybind11::embed::INTERFACE_LINK_LIBRARIES=pybind11::pybind11;Python::Python

But later gives, from the second execution in another directory, the unexpected (Python::Python missing) :

pybind11::embed::INTERFACE_LINK_LIBRARIES=pybind11::pybind11

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions