Skip to content

Commit cc0db2e

Browse files
authored
Merge pull request #37 from IvDmNe/master
Separate building and python install
2 parents cb3d254 + 236ab96 commit cc0db2e

7 files changed

Lines changed: 82 additions & 36 deletions

File tree

CMakeLists.txt

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,38 @@ else()
1717
list(PREPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
1818
endif()
1919

20-
include(FetchContent)
21-
include(pybind11)
2220

23-
find_package(Eigen3 REQUIRED QUIET)
24-
find_package(Open3D HINTS ${CMAKE_INSTALL_PREFIX}/lib/CMake)
2521
list(APPEND Open3D_LIBRARIES dl)
2622

27-
message(STATUS "Found Open3D ${Open3D_VERSION}")
28-
link_directories(${Open3D_LIBRARY_DIRS})
29-
3023
add_subdirectory(patchworkpp)
31-
add_subdirectory(python_wrapper)
3224

33-
add_executable(demo_visualize examples/cpp/demo_visualize.cpp)
34-
target_link_libraries(demo_visualize PRIVATE PATCHWORK::patchworkpp ${Open3D_LIBRARIES} "stdc++fs")
35-
target_include_directories(demo_visualize PUBLIC ${Open3D_INCLUDE_DIRS})
36-
set_target_properties(demo_visualize PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/build/examples/cpp")
25+
if (INCLUDE_PYTHON_WRAPPER)
26+
27+
message(STATUS "Building Python wrapper")
28+
find_package(Python3 REQUIRED COMPONENTS Interpreter Development.Module)
29+
include(FetchContent)
30+
include(pybind11)
31+
add_subdirectory(python_wrapper)
32+
33+
endif()
34+
35+
if (INCLUDE_EXAMPLES)
3736

38-
add_executable(demo_sequential examples/cpp/demo_sequential.cpp)
39-
target_link_libraries(demo_sequential PRIVATE PATCHWORK::patchworkpp ${Open3D_LIBRARIES} "stdc++fs")
40-
target_include_directories(demo_sequential PUBLIC ${Open3D_INCLUDE_DIRS})
41-
set_target_properties(demo_sequential PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/build/examples/cpp")
37+
message(STATUS "Building examples for c++")
38+
find_package(Open3D REQUIRED HINTS ${CMAKE_INSTALL_PREFIX}/lib/CMake)
4239

40+
list(APPEND Open3D_LIBRARIES dl)
41+
link_directories(${Open3D_LIBRARY_DIRS})
42+
message(STATUS "Found Open3D ${Open3D_VERSION}")
43+
44+
add_executable(demo_visualize examples/cpp/demo_visualize.cpp)
45+
target_link_libraries(demo_visualize PRIVATE PATCHWORK::patchworkpp ${Open3D_LIBRARIES} "stdc++fs")
46+
target_include_directories(demo_visualize PUBLIC ${Open3D_INCLUDE_DIRS})
47+
set_target_properties(demo_visualize PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/build/examples/cpp")
48+
49+
add_executable(demo_sequential examples/cpp/demo_sequential.cpp)
50+
target_link_libraries(demo_sequential PRIVATE PATCHWORK::patchworkpp ${Open3D_LIBRARIES} "stdc++fs")
51+
target_include_directories(demo_sequential PUBLIC ${Open3D_INCLUDE_DIRS})
52+
set_target_properties(demo_sequential PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/build/examples/cpp")
53+
54+
endif()

examples/python/demo_sequential.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
import os
2-
import sys
32
import open3d as o3d
43
import numpy as np
5-
# import pypatchworkpp
4+
import pypatchworkpp
65

76
cur_dir = os.path.dirname(os.path.abspath(__file__))
87
data_dir = os.path.join(cur_dir, '../../data/')
98

10-
try:
11-
patchwork_module_path = os.path.join(cur_dir, "../../build/python_wrapper")
12-
sys.path.insert(0, patchwork_module_path)
13-
import pypatchworkpp
14-
except ImportError:
15-
print("Cannot find pypatchworkpp!")
16-
exit(1)
179

1810
def read_bin(bin_path):
1911
scan = np.fromfile(bin_path, dtype=np.float32)

examples/python/demo_visualize.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,11 @@
22
import sys
33
import open3d as o3d
44
import numpy as np
5-
# import pypatchworkpp
5+
import pypatchworkpp
66

77
cur_dir = os.path.dirname(os.path.abspath(__file__))
88
input_cloud_filepath = os.path.join(cur_dir, '../../data/000000.bin')
99

10-
try:
11-
patchwork_module_path = os.path.join(cur_dir, "../../build/python_wrapper")
12-
sys.path.insert(0, patchwork_module_path)
13-
import pypatchworkpp
14-
except ImportError:
15-
print("Cannot find pypatchworkpp!")
16-
exit(1)
1710

1811
def read_bin(bin_path):
1912
scan = np.fromfile(bin_path, dtype=np.float32)

install_open3d.bash

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
set -e
2+
3+
VERSION=0.15.1
4+
5+
[ ! -d Open3D ] && git clone https://github.com/isl-org/Open3D.git -b v$VERSION || echo "Skip pulling repo"
6+
7+
[ ! -d Open3D/build ] && mkdir Open3D/build
8+
cd Open3D/build
9+
10+
cmake .. \
11+
-DCMAKE_BUILD_TYPE=Release \
12+
-Wno-dev \
13+
-DBUILD_EXAMPLES=OFF \
14+
-DBUILD_PYTHON_MODULE=OFF \
15+
-DBUILD_ISPC_MODULE=OFF \
16+
-DBUILD_WEBRTC=OFF
17+
18+
19+
make -j$(nproc)
20+
21+
echo "Applying 'sudo make install'. Enter password"
22+
sudo make install

patchworkpp/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ project(patchworkpp_src)
22

33
include(GNUInstallDirs)
44

5-
add_library(patchworkpp SHARED src/patchworkpp.cpp)
5+
find_package(Eigen3 REQUIRED QUIET)
6+
7+
add_library(patchworkpp STATIC src/patchworkpp.cpp)
8+
set_target_properties(patchworkpp PROPERTIES POSITION_INDEPENDENT_CODE ON)
9+
610
target_include_directories(patchworkpp PUBLIC
711
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
812
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>

pyproject.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[build-system]
2+
requires = ["scikit_build_core", "pybind11"]
3+
build-backend = "scikit_build_core.build"
4+
5+
[project]
6+
name = "pypatchworkpp"
7+
version = "0.0.1"
8+
requires-python = ">=3.8"
9+
description = "ground segmentation"
10+
dependencies = [
11+
"numpy>=1.23"
12+
]
13+
14+
[project.optional-dependencies]
15+
demo = [
16+
"open3d-cpu>=0.17"
17+
]
18+
19+
[tool.scikit-build]
20+
cmake.args = ["-DINCLUDE_PYTHON_WRAPPER=true"]
21+

python_wrapper/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
project(patchworkpp_python_wrapper)
1+
project(patchworkpp_python_wrapper LANGUAGES CXX)
22

33
pybind11_add_module(pypatchworkpp pybinding.cpp)
44

55
target_link_libraries(pypatchworkpp PUBLIC PATCHWORK::patchworkpp)
66

77
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
88
target_compile_options(pypatchworkpp PUBLIC -fsized-deallocation)
9-
endif()
9+
endif()
10+
11+
install(TARGETS pypatchworkpp DESTINATION .)

0 commit comments

Comments
 (0)