Skip to content

fix: regression with installed pybind11 overriding local one #2716

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 2 commits into from
Dec 16, 2020
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
12 changes: 11 additions & 1 deletion tools/pybind11NewTools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 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
"$<BUILD_INTERFACE:${${_Python}_INCLUDE_DIRS}>")
set_property(
TARGET pybind11::pybind11
APPEND
PROPERTY INTERFACE_INCLUDE_DIRECTORIES $<BUILD_INTERFACE:${${_Python}_INCLUDE_DIRS}>)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

May have fixed a possible issue if using new FindPython and if Python's install dir had a space in it.

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")
Expand Down
12 changes: 10 additions & 2 deletions tools/pybind11Tools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
"$<BUILD_INTERFACE:${PYTHON_INCLUDE_DIRS}>")
set_property(
TARGET pybind11::pybind11
APPEND
PROPERTY INTERFACE_INCLUDE_DIRECTORIES $<BUILD_INTERFACE:${PYTHON_INCLUDE_DIRS}>)
PROPERTY INTERFACE_LINK_LIBRARIES pybind11::python_headers)

set(pybind11_INCLUDE_DIRS
"${pybind11_INCLUDE_DIR}" "${PYTHON_INCLUDE_DIRS}"
Expand Down