@@ -142,10 +142,17 @@ endif()
142
142
string (REPLACE "include/" "${CMAKE_CURRENT_SOURCE_DIR} /include/" PYBIND11_HEADERS
143
143
"${PYBIND11_HEADERS} " )
144
144
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
147
147
"${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 ()
149
156
150
157
# Note: when creating targets, you cannot use if statements at configure time -
151
158
# you need generator expressions, because those will be placed in the target file.
@@ -170,14 +177,14 @@ endif()
170
177
171
178
# Fill in headers target
172
179
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 } >
174
181
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >)
175
182
176
183
target_compile_features (pybind11_headers INTERFACE cxx_inheriting_constructors cxx_user_literals
177
184
cxx_right_angle_brackets)
178
185
179
186
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} )
181
188
set (PYBIND11_CMAKECONFIG_INSTALL_DIR
182
189
"${CMAKE_INSTALL_DATAROOTDIR} /cmake/${PROJECT_NAME} "
183
190
CACHE STRING "install path for pybind11Config.cmake" )
@@ -259,8 +266,5 @@ endif()
259
266
if (NOT PYBIND11_MASTER_PROJECT)
260
267
set (pybind11_FOUND
261
268
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" )
266
270
endif ()
0 commit comments