Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable shared library linking for open3d*.wheel #5931

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ option(BUILD_SHARED_LIBS "Build shared libraries" OFF
option(BUILD_EXAMPLES "Build Open3D examples programs" ON )
option(BUILD_UNIT_TESTS "Build Open3D unit tests" OFF)
option(BUILD_BENCHMARKS "Build the micro benchmarks" OFF)
option(BUILD_APPS "Build the Open3D Applications" OFF)
option(BUILD_PYTHON_MODULE "Build the python module" ON )
option(BUILD_CUDA_MODULE "Build the CUDA module" OFF)
option(BUILD_COMMON_CUDA_ARCHS "Build for common CUDA GPUs (for release)" OFF)
Expand Down Expand Up @@ -141,6 +142,23 @@ if (NOT DEVELOPER_BUILD)
endif()
endif()

if(UNIX)
if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w")
set(CMAKE_MACOSX_RPATH ON)
set(_rpath_portable_origin "@loader_path/../lib")
else()
set(_rpath_portable_origin $ORIGIN/../lib)
endif()
# Use separate rpaths during build and install phases.
set(CMAKE_SKIP_BUILD_RPATH FALSE)
# Don't use the install-rpath during the build phase.
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "${_rpath_portable_origin}")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif()
message(STATUS "CMAKE_INSTALL_RPATH: " ${CMAKE_INSTALL_RPATH})

# Default build type on single-config generators.
# For multi-config generators (e.g. Visual Studio), CMAKE_CONFIGURATION_TYPES
# will be set, and we don't specify a default CMAKE_BUILD_TYPE.
Expand Down
1 change: 1 addition & 0 deletions cmake/Open3DPrintConfigurationSummary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function(open3d_print_configuration_summary)
endif()
open3d_aligned_print("Build Unit Tests" "${BUILD_UNIT_TESTS}")
open3d_aligned_print("Build Examples" "${BUILD_EXAMPLES}")
open3d_aligned_print("Build Applications" "${BUILD_APPS}")
open3d_aligned_print("Build Python Module" "${BUILD_PYTHON_MODULE}")
open3d_aligned_print("Build Jupyter Extension" "${BUILD_JUPYTER_EXTENSION}")
open3d_aligned_print("Build TensorFlow Ops" "${BUILD_TENSORFLOW_OPS}")
Expand Down
4 changes: 3 additions & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
add_subdirectory(open3d)
add_subdirectory(tools)
add_subdirectory(apps)
if(BUILD_APPS)
add_subdirectory(apps)
endif()
if (BUILD_UNIT_TESTS)
add_subdirectory(tests)
endif()
Expand Down
13 changes: 13 additions & 0 deletions cpp/pybind/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ if (BUNDLE_OPEN3D_ML)
list(APPEND GENERATED_OUTPUTS open3d_ml)
endif()

# pybind*.so must be install to change the rpath such that it can find the
# installed libOpen3D.so after install to python environment.
if (BUILD_SHARED_LIBS)
set(BUILD_TYPE "cpu")
if(BUILD_CUDA_MODULE)
set(BUILD_TYPE "cuda")
endif()
install(TARGETS pybind DESTINATION ${PYTHON_PACKAGE_DST_DIR}/open3d/${BUILD_TYPE})
endif()

configure_file("_build_config.py.in"
"${CMAKE_BINARY_DIR}/lib/_build_config.py.in")
file(GENERATE
Expand Down Expand Up @@ -212,6 +222,9 @@ add_custom_target(python-package
-DPROJECT_VERSION_THREE_NUMBER=${PROJECT_VERSION_THREE_NUMBER}
-DPYPI_PACKAGE_NAME=${PYPI_PACKAGE_NAME}
-P ${CMAKE_CURRENT_SOURCE_DIR}/make_python_package.cmake
COMMAND ${CMAKE_COMMAND} --install
${CMAKE_BINARY_DIR}
--prefix ${PYTHON_PACKAGE_DST_DIR}/open3d
VERBATIM
DEPENDS ${GENERATED_OUTPUTS}
)
Expand Down