Skip to content

Commit

Permalink
PR #8176 from Nir: Clone pybind11 V2.6.1 as part of CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel committed Jan 21, 2021
2 parents aa6d0d7 + e4d4e40 commit ea575ed
Show file tree
Hide file tree
Showing 43 changed files with 56 additions and 13,817 deletions.
20 changes: 20 additions & 0 deletions third-party/pybind11/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# minimum required cmake version: 3.1.0
cmake_minimum_required(VERSION 3.1.0)

project(pybind11-download NONE)

include(ExternalProject)
ExternalProject_Add(
pybind11
PREFIX .
GIT_REPOSITORY "https://github.com/pybind/pybind11.git"
GIT_TAG "f1abf5d9159b805674197f6bc443592e631c9130" # v2.6.1
SOURCE_DIR "${CMAKE_BINARY_DIR}/third-party/pybind11"
# Override default steps with no action, we just want the clone step.
UPDATE_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)


6 changes: 5 additions & 1 deletion wrappers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ project(RealsenseWrappers)
set(DEPENDENCIES realsense2)

if (BUILD_PYTHON_BINDINGS OR BUILD_PYTHON_DOCS)
add_subdirectory(python)
if (NOT INTERNET_CONNECTION)
message(WARNING "No internet connection. Cloning Python bindings may fail")
endif()
add_subdirectory(python)

endif()

if (BUILD_NODEJS_BINDINGS)
Expand Down
43 changes: 31 additions & 12 deletions wrappers/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@ 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)
# In order for the external project clone to occur during cmake configure step(rather than during compilation, as would normally happen),
# we copy the external project declaration to the build folder and then execute it
configure_file(${CMAKE_SOURCE_DIR}/third-party/pybind11/CMakeLists.txt ${CMAKE_BINARY_DIR}/external-projects/pybind11/CMakeLists.txt)
execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/external-projects/pybind11"
)
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/external-projects/pybind11"
)

add_subdirectory(third_party/pybind11)
# Add pybind11 makefile
add_subdirectory("${CMAKE_BINARY_DIR}/third-party/pybind11"
"${CMAKE_BINARY_DIR}/third-party/pybind11"
EXCLUDE_FROM_ALL
)

set(PYBIND11_CPP_STANDARD -std=c++11)
include_directories(${CMAKE_BINARY_DIR}/third-party/pybind11/include)

set(PYRS_CPP
python.cpp
Expand All @@ -41,6 +46,20 @@ set(PYRS_CPP
)

pybind11_add_module(pyrealsense2 SHARED python.hpp ${PYRS_CPP})

# pybind11 version 2.6.1 require find_package to run after pybind11_add_module call,
# This way the pybind takes the python version set in PYTHON_EXECUTABLE variable.
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()

target_link_libraries(pyrealsense2 PRIVATE ${DEPENDENCIES})
set_target_properties(pyrealsense2 PROPERTIES VERSION
${REALSENSE_VERSION_STRING} SOVERSION "${REALSENSE_VERSION_MAJOR}.${REALSENSE_VERSION_MINOR}")
Expand Down
155 changes: 0 additions & 155 deletions wrappers/python/third_party/pybind11/CMakeLists.txt

This file was deleted.

36 changes: 0 additions & 36 deletions wrappers/python/third_party/pybind11/LICENSE

This file was deleted.

2 changes: 0 additions & 2 deletions wrappers/python/third_party/pybind11/MANIFEST.in

This file was deleted.

Loading

0 comments on commit ea575ed

Please sign in to comment.