Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: CMake invalid include guard in pybind11Common.cmake #5393

Open
3 tasks done
petersteneteg opened this issue Sep 30, 2024 · 0 comments
Open
3 tasks done

[BUG]: CMake invalid include guard in pybind11Common.cmake #5393

petersteneteg opened this issue Sep 30, 2024 · 0 comments
Labels
triage New bug, unverified

Comments

@petersteneteg
Copy link

Required prerequisites

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

2.13.6

Problem description

pybind11Common.cmake defines a set of imported targets pybind11::pybind11 etc, They are guarded behind a global include guard. But the defined targets only have directory scope. Hence if one runs find_package(pybind11) from different subdirectories, the first one will run and pybind11Common.cmake and define the targets, the second one will bail at the global include guard, but the targets are not available since they where defined in a different directory and are not global.

This will need to an hard error, since the needed targets are now missing in the second subdirectory.

Changing the guard to "DIRECTORY" solves the issues. But one might still run into issues if one subdirectory would promote one or more targets to global scope. Generally I think each targets should be guarded by a if(NOT TARGET ..)That seems safer to me. Generally I would prefer of handle it more in line with how the autogenerated pybind11Targets.cmake handle it.
Basically it has a list of all the expected targets, and checks if all are defined, then it can return early, or if none is defined, then it can add them. Everything else is a fatal error.

The relevant line,

include_guard(GLOBAL)

which was introduced in a recent change. 28dbce4

Reproducible example code

No response

Is this a regression? Put the last known working version here if it is.

2.13.5

@petersteneteg petersteneteg added the triage New bug, unverified label Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage New bug, unverified
Projects
None yet
Development

No branches or pull requests

1 participant