CMake: support a custom export group (#970)

When Pybind11 is used via `add_subdirectory`, when targets are installed
from the parent project, CMake wants all of the dependencies built by
the project in the same export set. Projects may now set
`PYBIND11_EXPORT_NAME` to have Pybind11 put it targets into the
project's export set. If so, do not install Pybind11's export file.
This commit is contained in:
Ben Boeckel 2017-08-07 16:32:35 -04:00 committed by Dean Moldovan
parent ebd6ad588b
commit 017a747da6

View File

@ -19,6 +19,9 @@ set(PYBIND11_MASTER_PROJECT OFF)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(PYBIND11_MASTER_PROJECT ON) set(PYBIND11_MASTER_PROJECT ON)
endif() endif()
if (NOT PYBIND11_EXPORT_NAME)
set(PYBIND11_EXPORT_NAME "${PROJECT_NAME}Targets")
endif ()
option(PYBIND11_INSTALL "Install pybind11 header files?" ${PYBIND11_MASTER_PROJECT}) option(PYBIND11_INSTALL "Install pybind11 header files?" ${PYBIND11_MASTER_PROJECT})
option(PYBIND11_TEST "Build pybind11 test suite?" ${PYBIND11_MASTER_PROJECT}) option(PYBIND11_TEST "Build pybind11 test suite?" ${PYBIND11_MASTER_PROJECT})
@ -131,9 +134,11 @@ if (PYBIND11_INSTALL)
if(NOT (CMAKE_VERSION VERSION_LESS 3.0)) if(NOT (CMAKE_VERSION VERSION_LESS 3.0))
install(TARGETS pybind11 module embed install(TARGETS pybind11 module embed
EXPORT "${PROJECT_NAME}Targets") EXPORT "${PYBIND11_EXPORT_NAME}")
install(EXPORT "${PROJECT_NAME}Targets" if(PYBIND11_MASTER_PROJECT)
NAMESPACE "${PROJECT_NAME}::" install(EXPORT "${PYBIND11_EXPORT_NAME}"
DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR}) NAMESPACE "${PROJECT_NAME}::"
DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})
endif()
endif() endif()
endif() endif()