Skip to content

Commit f967396

Browse files
committed
fix: Python include directory was missing from DIRS
1 parent 06a5401 commit f967396

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

CMakeLists.txt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,17 @@ endif()
142142
string(REPLACE "include/" "${CMAKE_CURRENT_SOURCE_DIR}/include/" PYBIND11_HEADERS
143143
"${PYBIND11_HEADERS}")
144144

145-
# Cache variables so pybind11_add_module can be used in parent projects
146-
set(PYBIND11_INCLUDE_DIR
145+
# Cache variable so this can be used in parent projects
146+
set(pybind11_INCLUDE_DIR
147147
"${CMAKE_CURRENT_LIST_DIR}/include"
148-
CACHE INTERNAL "")
148+
CACHE INTERNAL "Directory where pybind11 headers are located")
149+
150+
# Backward compatible variable for add_subdirectory mode
151+
if(NOT PYBIND11_MASTER_PROJECT)
152+
set(PYBIND11_INCLUDE_DIR
153+
"${pybind11_INCLUDE_DIR}"
154+
CACHE INTERNAL "")
155+
endif()
149156

150157
# Note: when creating targets, you cannot use if statements at configure time -
151158
# you need generator expressions, because those will be placed in the target file.
@@ -170,14 +177,14 @@ endif()
170177

171178
# Fill in headers target
172179
target_include_directories(
173-
pybind11_headers ${pybind11_system} INTERFACE $<BUILD_INTERFACE:${PYBIND11_INCLUDE_DIR}>
180+
pybind11_headers ${pybind11_system} INTERFACE $<BUILD_INTERFACE:${pybind11_INCLUDE_DIR}>
174181
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
175182

176183
target_compile_features(pybind11_headers INTERFACE cxx_inheriting_constructors cxx_user_literals
177184
cxx_right_angle_brackets)
178185

179186
if(PYBIND11_INSTALL)
180-
install(DIRECTORY ${PYBIND11_INCLUDE_DIR}/pybind11 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
187+
install(DIRECTORY ${pybind11_INCLUDE_DIR}/pybind11 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
181188
set(PYBIND11_CMAKECONFIG_INSTALL_DIR
182189
"${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}"
183190
CACHE STRING "install path for pybind11Config.cmake")
@@ -259,8 +266,5 @@ endif()
259266
if(NOT PYBIND11_MASTER_PROJECT)
260267
set(pybind11_FOUND
261268
TRUE
262-
CACHE INTERNAL "true if pybind11 and all required components found on the system")
263-
set(pybind11_INCLUDE_DIR
264-
"${PYBIND11_INCLUDE_DIR}"
265-
CACHE INTERNAL "Directory where pybind11 headers are located")
269+
CACHE INTERNAL "True if pybind11 and all required components found on the system")
266270
endif()

tools/pybind11Common.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ if(NOT is_config)
3636
set(optional_global GLOBAL)
3737
endif()
3838

39+
# If not run in Python mode, we still would like this to at least
40+
# include pybind11's include directory:
41+
set(pybind11_INCLUDE_DIRS
42+
"${pybind11_INCLUDE_DIR}"
43+
CACHE INTERNAL "Include directory for pybind11 (Python not requested)")
44+
3945
# --------------------- Shared targets ----------------------------
4046

4147
# Build an interface library target:

tools/pybind11NewTools.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ if(DEFINED ${_Python}_INCLUDE_DIRS)
130130
TARGET pybind11::pybind11
131131
APPEND
132132
PROPERTY INTERFACE_INCLUDE_DIRECTORIES $<BUILD_INTERFACE:${${_Python}_INCLUDE_DIRS}>)
133+
set(pybind11_INCLUDE_DIRS
134+
"${pybind11_INCLUDE_DIR}" "${${_Python}_INCLUDE_DIRS}"
135+
CACHE INTERNAL "Directories where pybind11 and possibly Python headers are located")
133136
endif()
134137

135138
if(DEFINED ${_Python}_VERSION AND ${_Python}_VERSION VERSION_LESS 3)

tools/pybind11Tools.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ set_property(
8787
APPEND
8888
PROPERTY INTERFACE_INCLUDE_DIRECTORIES $<BUILD_INTERFACE:${PYTHON_INCLUDE_DIRS}>)
8989

90+
set(pybind11_INCLUDE_DIRS
91+
"${pybind11_INCLUDE_DIR}" "${PYTHON_INCLUDE_DIRS}"
92+
CACHE INTERNAL "Directories where pybind11 and possibly Python headers are located")
93+
9094
# Python debug libraries expose slightly different objects before 3.8
9195
# https://docs.python.org/3.6/c-api/intro.html#debugging-builds
9296
# https://stackoverflow.com/questions/39161202/how-to-work-around-missing-pymodule-create2-in-amd64-win-python35-d-lib

0 commit comments

Comments
 (0)