Skip to content

Commit 496f990

Browse files
committed
export only >3.0.1 cmake
1 parent 186eaa7 commit 496f990

File tree

1 file changed

+33
-29
lines changed

1 file changed

+33
-29
lines changed

CMakeLists.txt

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -182,38 +182,42 @@ endif()
182182
include(GNUInstallDirs)
183183
include(CMakePackageConfigHelpers)
184184

185-
# Build an interface library target:
186-
# Though any project using pybind11 will need to include python headers and
187-
# define c++11/14-ness, these are not included as interface includes or compile
188-
# defs because (1) that's really the domain of the upstream project to decide,
189-
# (2) we can get away with it since installation (headers) don't care about
190-
# python version or C++ standard, and (3) this will make the easily target relocatable.
191-
add_library(pb11 INTERFACE)
192-
set_target_properties(pb11 PROPERTIES EXPORT_NAME "pybind11")
193-
target_include_directories(pb11 INTERFACE $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
194-
if(APPLE)
195-
target_link_libraries(pb11 INTERFACE "-undefined dynamic_lookup")
185+
if(CMAKE_VERSION VERSION_GREATER 3.0.1)
186+
# Build an interface library target:
187+
# Though any project using pybind11 will need to include python headers and
188+
# define c++11/14-ness, these are not included as interface includes or compile
189+
# defs because (1) that's really the domain of the upstream project to decide,
190+
# (2) we can get away with it since installation (headers) don't care about
191+
# python version or C++ standard, and (3) this will make the easily target relocatable.
192+
add_library(pb11 INTERFACE)
193+
set_target_properties(pb11 PROPERTIES EXPORT_NAME "pybind11")
194+
target_include_directories(pb11 INTERFACE $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
195+
if(APPLE)
196+
target_link_libraries(pb11 INTERFACE "-undefined dynamic_lookup")
197+
endif()
196198
endif()
197199

198200
if (PYBIND11_INSTALL)
199201
install(FILES ${PYBIND11_HEADERS}
200202
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/pybind11)
201-
install(TARGETS pb11
202-
EXPORT "${PROJECT_NAME}Targets")
203-
204-
# explicit "share" not "DATADIR" for CMake search path
205-
set(CMAKECONFIG_INSTALL_DIR "share/cmake/${PROJECT_NAME}")
206-
configure_package_config_file(tools/${PROJECT_NAME}Config.cmake.in
207-
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
208-
INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR})
209-
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
210-
VERSION 1.8
211-
#VERSION ${${PROJECT_NAME}_VERSION}
212-
COMPATIBILITY AnyNewerVersion)
213-
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
214-
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
215-
DESTINATION ${CMAKECONFIG_INSTALL_DIR})
216-
install(EXPORT "${PROJECT_NAME}Targets"
217-
NAMESPACE "${PROJECT_NAME}::"
218-
DESTINATION ${CMAKECONFIG_INSTALL_DIR})
203+
if(CMAKE_VERSION VERSION_GREATER 3.0.1)
204+
install(TARGETS pb11
205+
EXPORT "${PROJECT_NAME}Targets")
206+
207+
# explicit "share" not "DATADIR" for CMake search path
208+
set(CMAKECONFIG_INSTALL_DIR "share/cmake/${PROJECT_NAME}")
209+
configure_package_config_file(tools/${PROJECT_NAME}Config.cmake.in
210+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
211+
INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR})
212+
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
213+
VERSION 1.8
214+
#VERSION ${${PROJECT_NAME}_VERSION}
215+
COMPATIBILITY AnyNewerVersion)
216+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
217+
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
218+
DESTINATION ${CMAKECONFIG_INSTALL_DIR})
219+
install(EXPORT "${PROJECT_NAME}Targets"
220+
NAMESPACE "${PROJECT_NAME}::"
221+
DESTINATION ${CMAKECONFIG_INSTALL_DIR})
222+
endif()
219223
endif()

0 commit comments

Comments
 (0)