From 322d8cfcf1950c4f57dcd9aa09de3e91ee33232c Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 7 Dec 2020 20:38:38 -0500 Subject: [PATCH 1/2] fix: regression with installed pybind11 overriding discovered one Closes #2709 --- tools/pybind11NewTools.cmake | 12 +++++++++++- tools/pybind11Tools.cmake | 12 ++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/tools/pybind11NewTools.cmake b/tools/pybind11NewTools.cmake index dd1b972c0f..b3537d3c36 100644 --- a/tools/pybind11NewTools.cmake +++ b/tools/pybind11NewTools.cmake @@ -127,10 +127,20 @@ endif() # Check on every access - since Python2 and Python3 could have been used - do nothing in that case. if(DEFINED ${_Python}_INCLUDE_DIRS) + # Only add Python for build - must be added during the import for config + # since it has to be re-discovered. + # + # This needs to be an target to it is included after the local pybind11 + # directory, just in case there are multiple versions of pybind11, we want + # the one we expect. + add_library(pybind11::python_headers INTERFACE IMPORTED) + set_property( + TARGET pybind11::python_headers PROPERTY INTERFACE_INCLUDE_DIRECTORIES + "$") set_property( TARGET pybind11::pybind11 APPEND - PROPERTY INTERFACE_INCLUDE_DIRECTORIES $) + PROPERTY INTERFACE_LINK_LIBRARIES pybind11::python_headers) set(pybind11_INCLUDE_DIRS "${pybind11_INCLUDE_DIR}" "${${_Python}_INCLUDE_DIRS}" CACHE INTERNAL "Directories where pybind11 and possibly Python headers are located") diff --git a/tools/pybind11Tools.cmake b/tools/pybind11Tools.cmake index 23cff98e89..cdd1979597 100644 --- a/tools/pybind11Tools.cmake +++ b/tools/pybind11Tools.cmake @@ -81,11 +81,19 @@ if(PYBIND11_MASTER_PROJECT) endif() endif() -# Only add Python for build - must be added during the import for config since it has to be re-discovered. +# Only add Python for build - must be added during the import for config since +# it has to be re-discovered. +# +# This needs to be an target to it is included after the local pybind11 +# directory, just in case there are multiple versions of pybind11, we want the +# one we expect. +add_library(pybind11::python_headers INTERFACE IMPORTED) +set_property(TARGET pybind11::python_headers PROPERTY INTERFACE_INCLUDE_DIRECTORIES + "$") set_property( TARGET pybind11::pybind11 APPEND - PROPERTY INTERFACE_INCLUDE_DIRECTORIES $) + PROPERTY INTERFACE_LINK_LIBRARIES pybind11::python_headers) set(pybind11_INCLUDE_DIRS "${pybind11_INCLUDE_DIR}" "${PYTHON_INCLUDE_DIRS}" From 32155ff8d192b7c8b489182f89a97ac72cee4485 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Fri, 11 Dec 2020 12:35:16 -0500 Subject: [PATCH 2/2] docs: wording incorrect --- tools/pybind11NewTools.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/pybind11NewTools.cmake b/tools/pybind11NewTools.cmake index b3537d3c36..686450bc38 100644 --- a/tools/pybind11NewTools.cmake +++ b/tools/pybind11NewTools.cmake @@ -130,9 +130,9 @@ if(DEFINED ${_Python}_INCLUDE_DIRS) # Only add Python for build - must be added during the import for config # since it has to be re-discovered. # - # This needs to be an target to it is included after the local pybind11 - # directory, just in case there are multiple versions of pybind11, we want - # the one we expect. + # This needs to be a target to be included after the local pybind11 + # directory, just in case there there is an installed pybind11 sitting + # next to Python's includes. It also ensures Python is a SYSTEM library. add_library(pybind11::python_headers INTERFACE IMPORTED) set_property( TARGET pybind11::python_headers PROPERTY INTERFACE_INCLUDE_DIRECTORIES