Skip to content

Commit 582a743

Browse files
committed
Issue #33: Trying to remove opencv from deployed wheel, and fix python version in wheel
1 parent 195e728 commit 582a743

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ set(BUILD_opencv_python_bindings_generator OFF CACHE BOOL "" FORCE)
3939
set(BUILD_opencv_python_tests OFF CACHE BOOL "" FORCE)
4040
set(BUILD_opencv_ts OFF CACHE BOOL "" FORCE)
4141
set(BUILD_opencv_world OFF CACHE BOOL "" FORCE)
42+
set(OPENCV_PYTHON_SKIP_DETECTION ON CACHE BOOL "" FORCE)
4243

4344
# Disable all optional I/O and hardware backends
4445
set(WITH_FFMPEG OFF CACHE BOOL "" FORCE)
@@ -75,6 +76,17 @@ set(CV_DISABLE_OPTIMIZATION OFF CACHE BOOL "" FORCE)
7576
set(CPU_DISPATCH "" CACHE STRING "" FORCE)
7677
set(ENABLE_PRECOMPILED_HEADERS OFF CACHE BOOL "" FORCE)
7778

79+
# Disable OpenCV's install rules to prevent polluting our wheel
80+
set(INSTALL_CREATE_DISTRIB OFF CACHE BOOL "" FORCE)
81+
set(OPENCV_BIN_INSTALL_PATH "opencv_unused" CACHE STRING "" FORCE)
82+
set(OPENCV_LIB_INSTALL_PATH "opencv_unused" CACHE STRING "" FORCE)
83+
set(OPENCV_3P_LIB_INSTALL_PATH "opencv_unused" CACHE STRING "" FORCE)
84+
set(OPENCV_INCLUDE_INSTALL_PATH "opencv_unused" CACHE STRING "" FORCE)
85+
set(OPENCV_OTHER_INSTALL_PATH "opencv_unused" CACHE STRING "" FORCE)
86+
set(OPENCV_LICENSES_INSTALL_PATH "opencv_unused" CACHE STRING "" FORCE)
87+
set(OPENCV_SAMPLES_SRC_INSTALL_PATH "opencv_unused" CACHE STRING "" FORCE)
88+
set(OPENCV_CONFIG_INSTALL_PATH "opencv_unused" CACHE STRING "" FORCE)
89+
7890
FetchContent_Declare(
7991
opencv
8092
GIT_REPOSITORY https://github.com/opencv/opencv.git
@@ -85,6 +97,9 @@ FetchContent_MakeAvailable(opencv)
8597

8698
# --- pybind11 ---
8799
if(BUILD_PYTHON_BINDINGS)
100+
# Find Python first so pybind11 uses the correct interpreter
101+
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module NumPy)
102+
88103
FetchContent_Declare(
89104
pybind11
90105
GIT_REPOSITORY https://github.com/pybind/pybind11.git

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ Repository = "https://github.com/UCL/scikit-surgeryopencvcpp"
3636
cmake.version = ">=3.15"
3737
cmake.build-type = "Release"
3838
wheel.packages = []
39+
wheel.exclude = ["include/**", "lib/**", "lib64/**", "bin/**", "share/**", "etc/**", "x64/**", "opencv_unused/**"]
40+
install.strip = false
3941

4042
[tool.scikit-build.cmake.define]
4143
BUILD_TESTING = "OFF"
44+
BUILD_PYTHON_BINDINGS = "ON"
4245

4346
[tool.cibuildwheel]
4447
build = "cp39-* cp310-* cp311-* cp312-* cp313-*"

src/python/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module NumPy)
1+
# Python is already found in the top-level CMakeLists.txt
22

33
pybind11_add_module(sksurgeryopencvpython bindings.cpp ndarray_converter.cpp)
44

55
target_link_libraries(sksurgeryopencvpython PRIVATE sksurgeryopencvcpp)
66
target_include_directories(sksurgeryopencvpython PRIVATE ${Python_NumPy_INCLUDE_DIRS})
77

8+
# scikit-build-core sets CMAKE_INSTALL_PREFIX; DESTINATION . puts the module
9+
# at the wheel root (site-packages level).
810
install(TARGETS sksurgeryopencvpython DESTINATION .)

0 commit comments

Comments
 (0)