Skip to content

Commit

Permalink
fix: reduce target collision in add_submodule mode
Browse files Browse the repository at this point in the history
Closes #2420
  • Loading branch information
henryiii committed Aug 21, 2020
1 parent 56df3c4 commit 6b95e2e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
16 changes: 9 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,10 @@ set(PYBIND11_INCLUDE_DIR
# This section builds targets, but does *not* touch Python

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

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

Expand All @@ -172,11 +174,11 @@ endif()

# Fill in headers target
target_include_directories(
headers ${pybind11_system} INTERFACE $<BUILD_INTERFACE:${PYBIND11_INCLUDE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
pybind11_headers ${pybind11_system} INTERFACE $<BUILD_INTERFACE:${PYBIND11_INCLUDE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

target_compile_features(headers INTERFACE cxx_inheriting_constructors cxx_user_literals
cxx_right_angle_brackets)
target_compile_features(pybind11_headers INTERFACE cxx_inheriting_constructors cxx_user_literals
cxx_right_angle_brackets)

if(PYBIND11_INSTALL)
install(DIRECTORY ${PYBIND11_INCLUDE_DIR}/pybind11 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
Expand Down Expand Up @@ -222,7 +224,7 @@ if(PYBIND11_INSTALL)
set(PYBIND11_EXPORT_NAME "${PROJECT_NAME}Targets")
endif()

install(TARGETS headers EXPORT "${PYBIND11_EXPORT_NAME}")
install(TARGETS pybind11_headers EXPORT "${PYBIND11_EXPORT_NAME}")

install(
EXPORT "${PYBIND11_EXPORT_NAME}"
Expand Down
3 changes: 3 additions & 0 deletions tools/pybind11Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ if(TARGET pybind11::python_link_helper)
return()
endif()

# Easier to use / remember
add_library(pybind11::headers ALIAS pybind11::pybind11_headers)

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

include("${CMAKE_CURRENT_LIST_DIR}/pybind11Common.cmake")
Expand Down

0 comments on commit 6b95e2e

Please sign in to comment.