From 6e3e8515e79f418dc9185acfa4a69947964ac903 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 26 May 2025 12:26:08 -0400 Subject: [PATCH] fix(cmake): regression in include gaurd (#5691) Signed-off-by: Henry Schreiner --- tools/pybind11Common.cmake | 7 +++++-- tools/pybind11Tools.cmake | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/pybind11Common.cmake b/tools/pybind11Common.cmake index b207c9b8a..7ca700f50 100644 --- a/tools/pybind11Common.cmake +++ b/tools/pybind11Common.cmake @@ -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, @@ -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) + set(optional_global "") endif() # If not run in Python mode, we still would like this to at least diff --git a/tools/pybind11Tools.cmake b/tools/pybind11Tools.cmake index b4df3df5b..8ef2dbb84 100644 --- a/tools/pybind11Tools.cmake +++ b/tools/pybind11Tools.cmake @@ -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)