Skip to content

Commit

Permalink
Add support for packaging VTK SDK as a wheel
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AlexyPellegrini committed Mar 26, 2024
1 parent 1adb2c5 commit 3b56e25
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 48 deletions.
65 changes: 59 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,61 @@
cmake_minimum_required(VERSION 3.15...3.26)
project(${SKBUILD_PROJECT_NAME} LANGUAGES CXX)
cmake_minimum_required(VERSION 3.21)

set(PYBIND11_FINDPYTHON ON)
find_package(pybind11 CONFIG REQUIRED)
set(VTK_VERSION
"9.2.6"
CACHE STRING "VTK SDK version to package")
project(
vtk-sdk
VERSION ${VTK_VERSION}
DESCRIPTION "VTK SDK python distributions"
HOMEPAGE_URL "https://github.com/Kitware/vtk-sdk-python-distributions"
LANGUAGES NONE)

pybind11_add_module(_core MODULE src/main.cpp)
install(TARGETS _core DESTINATION ${SKBUILD_PROJECT_NAME})
find_package(
Python
COMPONENTS Interpreter Development.Module
REQUIRED)

include(cmake/vtk-sdk-urls.cmake)
include(FetchContent)

set(download_dir ${PROJECT_BINARY_DIR})
set(extract_dir ${PROJECT_BINARY_DIR}/vtk-wheel-sdk)
# FetchContent will download and extract our archive!
FetchContent_Populate(
vtkwheelsdk
URL ${VTK_SDK_BINARY_URL} DOWNLOAD_DIR ${download_dir}
SOURCE_DIR ${extract_dir})

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/vtk-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/vtk_sdk/cmake/vtk-config.cmake @ONLY)

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/vtk-config-version.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/vtk_sdk/cmake/vtk-config-version.cmake @ONLY)

# "/" after ${extract_dir} is required so the folder content is copied to dest,
# instead of the folder itself!
install(
DIRECTORY ${extract_dir}/
DESTINATION vtk_sdk
PATTERN "bin/*" EXCLUDE)

install(
DIRECTORY ${extract_dir}/bin/
DESTINATION vtk_sdk/bin
PATTERN
"*"
PERMISSIONS
OWNER_READ
OWNER_WRITE
OWNER_EXECUTE
GROUP_READ
GROUP_EXECUTE
WORLD_READ
WORLD_EXECUTE)

install(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/vtk_sdk/cmake/__init__.py
${CMAKE_CURRENT_BINARY_DIR}/vtk_sdk/cmake/vtk-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/vtk_sdk/cmake/vtk-config-version.cmake
DESTINATION vtk_sdk/cmake)
1 change: 1 addition & 0 deletions cmake/vtk-config-version.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include(${CMAKE_CURRENT_LIST_DIR}/../vtk-@[email protected]/headers/cmake/vtk-config-version.cmake)
1 change: 1 addition & 0 deletions cmake/vtk-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include(${CMAKE_CURRENT_LIST_DIR}/../vtk-@[email protected]/headers/cmake/vtk-config.cmake)
13 changes: 13 additions & 0 deletions cmake/vtk-sdk-urls.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# VTK SDK is currently stored as a tar.xz archive on a Kitware hosted server
set(python_cp "cp${Python_VERSION_MAJOR}${Python_VERSION_MINOR}")

# enable any linux to download the right tar.xz
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
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"
)
else()
set(VTK_SDK_BINARY_URL
"https://vtk.org/files/wheel-sdks/vtk-wheel-sdk-${VTK_VERSION}-${python_cp}-${Python_SOABI}.tar.xz"
)
endif()
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Homepage = "https://github.com/Kitware/vtk-sdk-python-distributions"
Discussions = "https://github.com/Kitware/vtk-sdk-python-distributions/discussions"
Changelog = "https://github.com/Kitware/vtk-sdk-python-distributions/releases"

[project.entry-points."cmake.prefix"]
any = "vtk_sdk.cmake"

[tool.scikit-build]
minimum-version = "0.8.2"
Expand Down
27 changes: 0 additions & 27 deletions src/main.cpp

This file was deleted.

4 changes: 0 additions & 4 deletions src/vtk_sdk/_core.pyi

This file was deleted.

1 change: 1 addition & 0 deletions src/vtk_sdk/cmake/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This module is here because the path of the actual vtk-config.cmake file is not a valid module name
11 changes: 0 additions & 11 deletions tests/test_compiled.py

This file was deleted.

0 comments on commit 3b56e25

Please sign in to comment.