alternatives to vtkWrapPython.cmake

The vmtk project relied on the cmake file vtkWrapPython.cmake and it looks that has gone away, which I have no preference about and imagine the newer stuff makes more sense, however in desiring to build vmtk with the newest versions of VTK and ITK, I am not sure where to start with modifying the build system to accommodate the updates to the vtk python wrapping.

Where is a good place to start?

The module system docs are the place to start. I never got around to migration docs, so following the docs on the new module system is the easiest thing to do.

Feedback on the docs is welcome.

Hi Kurt,

When I adapted vtk-python for VTK 9, I first wrote a vtk.module file for the subdirectory that contained the classes that I wanted to be wrapped, and then used the new VTK module macros to build the module and do the wrapping. What I did still needs some cleanup, but it should provide a rough starting point.

it looks like if one is only targeting vtk 9.0 and python, most of stuff in the CMakeLists for a library is pretty smalll and the rest is cruft for older versions? am I interpreting this correctly?

from vtk-dicom/blob/master/Source/CMakeLists.txt

if(DEFINED VTK_MODULE_ENABLE_VTK_DICOM)
  # When building as a module for VTK 8.90 or later
  set(LIB_SRC_HDRS)
  foreach(_src ${LIB_SRCS})
    get_filename_component(_base ${_src} NAME_WE)
    list(APPEND LIB_SRC_HDRS ${_base}.h)
  endforeach()
  vtk_module_add_module(VTK::DICOM
    SOURCES ${LIB_SRCS}
    HEADERS ${LIB_SRC_HDRS} ${LIB_HDRS})
  vtk_module_link(VTK::DICOM
    PRIVATE ${GDCM_LIBS} ${DCMTK_LIBS} ${SQLITE_LIBS})

Yes. In fact, take a look at some of VTK’s own modules to see how simple it can be. Here’s the entire CMakeLists.txt for Common/Color:

set(classes
  vtkColorSeries
  vtkNamedColors)

vtk_module_add_module(VTK::CommonColor
  CLASSES ${classes})

I only used SOURCES and HEADERS because I had some special-purpose headers.

is it required that VTK::CommonColor be named starting with VTK:: or can it be anything.

where do I need to look in order to put several modules together i think kit is the word used in the documentation. I suppose I can just look at the modules in vtk.

It would be nice to have an example project that has all this without the cruft. :grinning:

It should match the PACKAGE argument you give to vtk_module_build.

There are a few under VTK’s Examples/ directory.

1 Like

Just adding a KIT kitname and a corresponding vtk.kit file should do it. Note that you’ll need to make sure you sill don’t have any dependency loops between kits. CMake will detect problems with messages about circular dependencies between non-static libraries. The module docs have more details.

1 Like

the same question with vmtk build…
have you resolved the problem?
will you share the cmake code?
thanks

The VTK Python wrapper in vtkAddon is used for Python wrapping of VMTK and several other VTK-based libraries that are built outside VTK. You should be able to use it the same way as it is done in VMTK.