Skip to content

fix(cmake): regression in include guard #5691

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

Merged
merged 1 commit into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions tools/pybind11Common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ Adds the following functions::

#]======================================================]

include_guard(GLOBAL)

# If we are in subdirectory mode, all IMPORTED targets must be GLOBAL. If we
# are in CONFIG mode, they should be "normal" targets instead.
# In CMake 3.11+ you can promote a target to global after you create it,
Expand All @@ -28,8 +26,13 @@ get_property(
is_config
TARGET pybind11::headers
PROPERTY IMPORTED)

if(NOT is_config)
include_guard(GLOBAL)
set(optional_global GLOBAL)
else()
include_guard(DIRECTORY)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I think this would have been safe to put DIRECTORY here, since there's already a GLOBAL on the main CMakeLists.txt. But this is safer for now, especially in RC.

set(optional_global "")
endif()

# If not run in Python mode, we still would like this to at least
Expand Down
2 changes: 1 addition & 1 deletion tools/pybind11Tools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.

include_guard(GLOBAL)
include_guard(DIRECTORY)

if(pybind11_FIND_QUIETLY)
set(_pybind11_quiet QUIET)
Expand Down
Loading