Skip to content

Commit

Permalink
Merge pull request #6220 from morxa/move-python-bindings-into-separat…
Browse files Browse the repository at this point in the history
…e-cmake-target

Move python bindings into separate cmake target
  • Loading branch information
ev-mp committed Jun 22, 2020
2 parents f58d6fc + 3a4d1e6 commit 76fe540
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 9 deletions.
10 changes: 10 additions & 0 deletions CMake/pyrealsense2Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@PACKAGE_INIT@

set(pyrealsense2_VERSION_MAJOR "@REALSENSE_VERSION_MAJOR@")
set(pyrealsense2_VERSION_MINOR "@REALSENSE_VERSION_MINOR@")
set(pyrealsense2_VERSION_PATCH "@REALSENSE_VERSION_PATCH@")

set(pyrealsense2_VERSION ${realsense2_VERSION_MAJOR}.${realsense2_VERSION_MINOR}.${realsense2_VERSION_PATCH})

include("${CMAKE_CURRENT_LIST_DIR}/pyrealsense2Targets.cmake")
set(realsense2_LIBRARY pyrealsense2::pyrealsense2)
47 changes: 38 additions & 9 deletions wrappers/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ if (NOT BUILD_PYTHON_BINDINGS)
message(WARNING "Python Bindings being built despite unset option because they are required for python documentation")
endif()

if (CMAKE_VERSION VERSION_LESS 3.12)
find_package(PythonInterp REQUIRED)
find_package(PythonLibs REQUIRED)
set(PYTHON_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/pyrealsense2" CACHE PATH "Installation directory for Python bindings")
set(CMAKECONFIG_PY_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/pyrealsense2")
else()
find_package(Python REQUIRED COMPONENTS Interpreter Development)
set(PYTHON_INSTALL_DIR "${Python_SITEARCH}/pyrealsense2" CACHE PATH "Installation directory for Python bindings")
set(CMAKECONFIG_PY_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/pyrealsense2")
endif()

set(DEPENDENCIES realsense2)

add_subdirectory(third_party/pybind11)
Expand Down Expand Up @@ -34,11 +45,6 @@ target_link_libraries(pyrealsense2 PRIVATE ${DEPENDENCIES})
set_target_properties(pyrealsense2 PROPERTIES VERSION
${REALSENSE_VERSION_STRING} SOVERSION "${REALSENSE_VERSION_MAJOR}.${REALSENSE_VERSION_MINOR}")
set_target_properties(pyrealsense2 PROPERTIES FOLDER Wrappers/python)
install(TARGETS pyrealsense2 EXPORT realsense2Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

set(RAW_RS
pybackend.cpp
Expand Down Expand Up @@ -128,13 +134,36 @@ set_target_properties(pybackend2 PROPERTIES
set_target_properties(pybackend2 PROPERTIES FOLDER Wrappers/python)
include_directories(pybackend2 ../../include)

install(TARGETS pybackend2
EXPORT realsense2Targets
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/pyrealsense2ConfigVersion.cmake"
VERSION ${REALSENSE_VERSION_STRING} COMPATIBILITY AnyNewerVersion)

configure_package_config_file(../../CMake/pyrealsense2Config.cmake.in pyrealsense2Config.cmake
INSTALL_DESTINATION ${CMAKECONFIG_PY_INSTALL_DIR}
INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}/bin
PATH_VARS CMAKE_INSTALL_INCLUDEDIR
)

install(TARGETS pybackend2 pyrealsense2
EXPORT pyrealsense2Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${PYTHON_INSTALL_DIR}
ARCHIVE DESTINATION ${PYTHON_INSTALL_DIR}
)

install(EXPORT pyrealsense2Targets
FILE pyrealsense2Targets.cmake
NAMESPACE pyrealsense2::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/pyrealsense2")

install(FILES "${CMAKE_BINARY_DIR}/wrappers/python/pyrealsense2Config.cmake"
DESTINATION ${CMAKECONFIG_PY_INSTALL_DIR}
)

install(FILES "${CMAKE_BINARY_DIR}/wrappers/python/pyrealsense2ConfigVersion.cmake"
DESTINATION ${CMAKECONFIG_PY_INSTALL_DIR}
)


if (BUILD_PYTHON_DOCS)
add_subdirectory(docs)
endif()

0 comments on commit 76fe540

Please sign in to comment.