Skip to content

Commit c58f7b7

Browse files
authored
fix: reduce target collision in add_submodule mode (#2423)
* fix: reduce target collision in add_submodule mode Closes #2420 * fix: update CMakeLists.txt
1 parent 56df3c4 commit c58f7b7

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

CMakeLists.txt

+9-7
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,10 @@ set(PYBIND11_INCLUDE_DIR
154154
# This section builds targets, but does *not* touch Python
155155

156156
# Build the headers-only target (no Python included):
157-
add_library(headers INTERFACE)
158-
add_library(pybind11::headers ALIAS headers) # to match exported target
157+
# (long name used here to keep this from clashing in subdirectory mode)
158+
add_library(pybind11_headers INTERFACE)
159+
add_library(pybind11::pybind11_headers ALIAS pybind11_headers) # to match exported target
160+
add_library(pybind11::headers ALIAS pybind11_headers) # easier to use/remember
159161

160162
include("${CMAKE_CURRENT_SOURCE_DIR}/tools/pybind11Common.cmake")
161163

@@ -172,11 +174,11 @@ endif()
172174

173175
# Fill in headers target
174176
target_include_directories(
175-
headers ${pybind11_system} INTERFACE $<BUILD_INTERFACE:${PYBIND11_INCLUDE_DIR}>
176-
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
177+
pybind11_headers ${pybind11_system} INTERFACE $<BUILD_INTERFACE:${PYBIND11_INCLUDE_DIR}>
178+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
177179

178-
target_compile_features(headers INTERFACE cxx_inheriting_constructors cxx_user_literals
179-
cxx_right_angle_brackets)
180+
target_compile_features(pybind11_headers INTERFACE cxx_inheriting_constructors cxx_user_literals
181+
cxx_right_angle_brackets)
180182

181183
if(PYBIND11_INSTALL)
182184
install(DIRECTORY ${PYBIND11_INCLUDE_DIR}/pybind11 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
@@ -222,7 +224,7 @@ if(PYBIND11_INSTALL)
222224
set(PYBIND11_EXPORT_NAME "${PROJECT_NAME}Targets")
223225
endif()
224226

225-
install(TARGETS headers EXPORT "${PYBIND11_EXPORT_NAME}")
227+
install(TARGETS pybind11_headers EXPORT "${PYBIND11_EXPORT_NAME}")
226228

227229
install(
228230
EXPORT "${PYBIND11_EXPORT_NAME}"

tools/pybind11Config.cmake.in

+5
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ endif()
130130

131131
include("${CMAKE_CURRENT_LIST_DIR}/pybind11Targets.cmake")
132132

133+
# Easier to use / remember
134+
add_library(pybind11::headers IMPORTED INTERFACE)
135+
set_target_properties(pybind11::headers PROPERTIES INTERFACE_LINK_LIBRARIES
136+
pybind11::pybind11_headers)
137+
133138
include("${CMAKE_CURRENT_LIST_DIR}/pybind11Common.cmake")
134139

135140
if(NOT pybind11_FIND_QUIETLY)

0 commit comments

Comments
 (0)