File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -127,10 +127,20 @@ endif()
127127# Check on every access - since Python2 and Python3 could have been used - do nothing in that case.
128128
129129if (DEFINED ${_Python} _INCLUDE_DIRS)
130+ # Only add Python for build - must be added during the import for config
131+ # since it has to be re-discovered.
132+ #
133+ # This needs to be a target to be included after the local pybind11
134+ # directory, just in case there there is an installed pybind11 sitting
135+ # next to Python's includes. It also ensures Python is a SYSTEM library.
136+ add_library (pybind11::python_headers INTERFACE IMPORTED )
137+ set_property (
138+ TARGET pybind11::python_headers PROPERTY INTERFACE_INCLUDE_DIRECTORIES
139+ "$<BUILD_INTERFACE:${${_Python} _INCLUDE_DIRS}>" )
130140 set_property (
131141 TARGET pybind11::pybind11
132142 APPEND
133- PROPERTY INTERFACE_INCLUDE_DIRECTORIES $<BUILD_INTERFACE:${ ${_Python} _INCLUDE_DIRS}> )
143+ PROPERTY INTERFACE_LINK_LIBRARIES pybind11::python_headers )
134144 set (pybind11_INCLUDE_DIRS
135145 "${pybind11_INCLUDE_DIR} " "${${_Python} _INCLUDE_DIRS}"
136146 CACHE INTERNAL "Directories where pybind11 and possibly Python headers are located" )
Original file line number Diff line number Diff line change @@ -81,11 +81,19 @@ if(PYBIND11_MASTER_PROJECT)
8181 endif ()
8282endif ()
8383
84- # Only add Python for build - must be added during the import for config since it has to be re-discovered.
84+ # Only add Python for build - must be added during the import for config since
85+ # it has to be re-discovered.
86+ #
87+ # This needs to be an target to it is included after the local pybind11
88+ # directory, just in case there are multiple versions of pybind11, we want the
89+ # one we expect.
90+ add_library (pybind11::python_headers INTERFACE IMPORTED )
91+ set_property (TARGET pybind11::python_headers PROPERTY INTERFACE_INCLUDE_DIRECTORIES
92+ "$<BUILD_INTERFACE:${PYTHON_INCLUDE_DIRS} >" )
8593set_property (
8694 TARGET pybind11::pybind11
8795 APPEND
88- PROPERTY INTERFACE_INCLUDE_DIRECTORIES $<BUILD_INTERFACE: ${PYTHON_INCLUDE_DIRS} > )
96+ PROPERTY INTERFACE_LINK_LIBRARIES pybind11::python_headers )
8997
9098set (pybind11_INCLUDE_DIRS
9199 "${pybind11_INCLUDE_DIR} " "${PYTHON_INCLUDE_DIRS} "
You can’t perform that action at this time.
0 commit comments