Skip to content

Commit b3264a7

Browse files
Add support for packaging VTK SDK as a wheel
This pulls a tar.xz archive from https://vtk.org/files/wheel-sdks and package it as a wheel using scikit-build-core. This wheel will then be added to a pip repository to be fetch through build requirements.
1 parent 1adb2c5 commit b3264a7

9 files changed

Lines changed: 69 additions & 48 deletions

File tree

CMakeLists.txt

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,58 @@
1-
cmake_minimum_required(VERSION 3.15...3.26)
2-
project(${SKBUILD_PROJECT_NAME} LANGUAGES CXX)
1+
cmake_minimum_required(VERSION 3.21)
32

4-
set(PYBIND11_FINDPYTHON ON)
5-
find_package(pybind11 CONFIG REQUIRED)
3+
set(VTK_VERSION "9.2.5" CACHE STRING "VTK SDK version to package")
4+
project(vtk-sdk
5+
VERSION ${VTK_VERSION}
6+
DESCRIPTION "VTK SDK python distributions"
7+
HOMEPAGE_URL "https://github.com/Kitware/vtk-sdk-python-distributions"
8+
LANGUAGES NONE
9+
)
610

7-
pybind11_add_module(_core MODULE src/main.cpp)
8-
install(TARGETS _core DESTINATION ${SKBUILD_PROJECT_NAME})
11+
find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)
12+
13+
include(cmake/vtk-sdk-urls.cmake)
14+
include(FetchContent)
15+
16+
set(download_dir ${PROJECT_BINARY_DIR})
17+
set(extract_dir ${PROJECT_BINARY_DIR}/vtk-wheel-sdk)
18+
# FetchContent will download and extract our archive!
19+
FetchContent_Populate(vtkwheelsdk
20+
URL ${VTK_SDK_BINARY_URL}
21+
DOWNLOAD_DIR ${download_dir}
22+
SOURCE_DIR ${extract_dir}
23+
)
24+
25+
configure_file(
26+
${CMAKE_CURRENT_SOURCE_DIR}/cmake/vtk-config.cmake.in
27+
${CMAKE_CURRENT_BINARY_DIR}/vtk_sdk/cmake/vtk-config.cmake
28+
@ONLY
29+
)
30+
31+
configure_file(
32+
${CMAKE_CURRENT_SOURCE_DIR}/cmake/vtk-config-version.cmake.in
33+
${CMAKE_CURRENT_BINARY_DIR}/vtk_sdk/cmake/vtk-config-version.cmake
34+
@ONLY
35+
)
36+
37+
# "/" after ${extract_dir} is required so the folder content is copied to dest, instead of the folder itself!
38+
install(DIRECTORY ${extract_dir}/
39+
DESTINATION vtk_sdk
40+
PATTERN "bin/*"
41+
EXCLUDE
42+
)
43+
44+
install(DIRECTORY ${extract_dir}/bin/
45+
DESTINATION vtk_sdk/bin
46+
PATTERN "*"
47+
PERMISSIONS
48+
OWNER_READ OWNER_WRITE OWNER_EXECUTE
49+
GROUP_READ GROUP_EXECUTE
50+
WORLD_READ WORLD_EXECUTE
51+
)
52+
53+
install(FILES
54+
${CMAKE_CURRENT_SOURCE_DIR}/src/vtk_sdk/cmake/__init__.py
55+
${CMAKE_CURRENT_BINARY_DIR}/vtk_sdk/cmake/vtk-config.cmake
56+
${CMAKE_CURRENT_BINARY_DIR}/vtk_sdk/cmake/vtk-config-version.cmake
57+
DESTINATION vtk_sdk/cmake
58+
)

cmake/vtk-config-version.cmake.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include(${CMAKE_CURRENT_LIST_DIR}/../vtk-@[email protected]/headers/cmake/vtk-config-version.cmake)

cmake/vtk-config.cmake.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include(${CMAKE_CURRENT_LIST_DIR}/../vtk-@[email protected]/headers/cmake/vtk-config.cmake)

cmake/vtk-sdk-urls.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# VTK SDK is currently stored as a tar.xz archive on a Kitware hosted server
2+
set(python_cp "cp${Python_VERSION_MAJOR}${Python_VERSION_MINOR}")
3+
4+
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") # enable any linux to download the right tar.xz
5+
set(VTK_SDK_BINARY_URL "https://vtk.org/files/wheel-sdks/vtk-wheel-sdk-${VTK_VERSION}-${python_cp}-${python_cp}-manylinux_2_17_x86_64.manylinux2014_x86_64.tar.xz") # base URL
6+
else()
7+
set(VTK_SDK_BINARY_URL "https://vtk.org/files/wheel-sdks/vtk-wheel-sdk-${VTK_VERSION}-${python_cp}-${Python_SOABI}.tar.xz")
8+
endif()

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ Homepage = "https://github.com/Kitware/vtk-sdk-python-distributions"
5656
Discussions = "https://github.com/Kitware/vtk-sdk-python-distributions/discussions"
5757
Changelog = "https://github.com/Kitware/vtk-sdk-python-distributions/releases"
5858

59+
[project.entry-points."cmake.prefix"]
60+
any = "vtk_sdk.cmake"
5961

6062
[tool.scikit-build]
6163
minimum-version = "0.8.2"

src/main.cpp

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/vtk_sdk/_core.pyi

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/vtk_sdk/cmake/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This module is here because the path of the actual vtk-config.cmake file is not a valid module name

tests/test_compiled.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)