# alternatives to vtkWrapPython.cmake

**URL:** https://discourse.vtk.org/t/alternatives-to-vtkwrappython-cmake/3229
**Category:** Support
**Created:** [May 7, 2020, 1:39am UTC](https://discourse.vtk.org/t/alternatives-to-vtkwrappython-cmake/3229 "2020-05-07T01:39:00Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![kayarre](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kayarre/32/808_2.png) [@kayarre](https://discourse.vtk.org/u/kayarre)
#### Post date: [May 7, 2020, 1:39am UTC](https://discourse.vtk.org/t/alternatives-to-vtkwrappython-cmake/3229/1 "2020-05-07T01:39:00Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [May 7, 2020, 3:16pm UTC](https://discourse.vtk.org/t/alternatives-to-vtkwrappython-cmake/3229/2 "2020-05-07T15:16:29Z")

</div>

The [module system docs](https://vtk.org/doc/nightly/html/md__home_kitware_dashboards_buildbot_vtk_nightly-master-ike-linux-shared-release_doc_nightly_osm749dd663df9981384f2598c108aac3b0.html) 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.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [May 7, 2020, 3:16pm UTC](https://discourse.vtk.org/t/alternatives-to-vtkwrappython-cmake/3229/3 "2020-05-07T15:16:54Z")

</div>

Feedback on the docs is welcome.

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [May 7, 2020, 6:36pm UTC](https://discourse.vtk.org/t/alternatives-to-vtkwrappython-cmake/3229/4 "2020-05-07T18:36:45Z")

</div>

Hi Kurt,

When I adapted vtk-python for VTK 9, I first wrote a [vtk.module](https://github.com/dgobbi/vtk-dicom/blob/master/Source/dicom.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](https://github.com/dgobbi/vtk-dicom/blob/master/CMakeLists.txt#L185). What I did still needs some cleanup, but it should provide a rough starting point.

---

<div class="post-metadata">

### Author: ![kayarre](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kayarre/32/808_2.png) [@kayarre](https://discourse.vtk.org/u/kayarre)
#### Post date: [May 20, 2020, 3:06am UTC](https://discourse.vtk.org/t/alternatives-to-vtkwrappython-cmake/3229/5 "2020-05-20T03:06:46Z")

</div>

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

```auto
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})

```

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [May 20, 2020, 3:31am UTC](https://discourse.vtk.org/t/alternatives-to-vtkwrappython-cmake/3229/6 "2020-05-20T03:31:36Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

### Author: ![kayarre](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kayarre/32/808_2.png) [@kayarre](https://discourse.vtk.org/u/kayarre)
#### Post date: [May 20, 2020, 4:26am UTC](https://discourse.vtk.org/t/alternatives-to-vtkwrappython-cmake/3229/7 "2020-05-20T04:26:27Z")

</div>

> [@dgobbi](#):
>
> vtk\_module\_add\_module(VTK::CommonColor CLASSES ${classes})

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. 😀

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [May 20, 2020, 11:02am UTC](https://discourse.vtk.org/t/alternatives-to-vtkwrappython-cmake/3229/8 "2020-05-20T11:02:20Z")

</div>

> [@kayarre](#):
>
> is it required that `VTK::CommonColor` be named starting with `VTK::` or can it be anything.

It should match the `PACKAGE` argument you give to `vtk_module_build`.

> [@kayarre](#):
>
> It would be nice to have an example project that has all this without the cruft.

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

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [May 20, 2020, 11:03am UTC](https://discourse.vtk.org/t/alternatives-to-vtkwrappython-cmake/3229/9 "2020-05-20T11:03:54Z")

</div>

> [@kayarre](#):
>
> where do I need to look in order to put several modules together i think `kit` is the word used in the documentation.

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.

---

<div class="post-metadata">

### Author: ![Ranglage](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ranglage/32/6642_2.png) [@Ranglage](https://discourse.vtk.org/u/Ranglage)
#### Post date: [February 27, 2023, 11:08am UTC](https://discourse.vtk.org/t/alternatives-to-vtkwrappython-cmake/3229/10 "2023-02-27T11:08:49Z")

</div>

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

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [March 2, 2023, 1:10pm UTC](https://discourse.vtk.org/t/alternatives-to-vtkwrappython-cmake/3229/11 "2023-03-02T13:10:27Z")

</div>

The [VTK Python wrapper in vtkAddon](https://github.com/Slicer/vtkAddon/blob/main/CMake/vtkWrapPython.cmake) 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.
