# How to determine the CMake VTK "COMPONENTS" necessary for a class?

**URL:** https://discourse.vtk.org/t/how-to-determine-the-cmake-vtk-components-necessary-for-a-class/11429
**Category:** Development
**Created:** [May 10, 2023, 4:29pm UTC](https://discourse.vtk.org/t/how-to-determine-the-cmake-vtk-components-necessary-for-a-class/11429 "2023-05-10T16:29:24Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![rexthor](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rexthor/32/6481_2.png) [@rexthor](https://discourse.vtk.org/u/rexthor)
#### Post date: [May 10, 2023, 4:29pm UTC](https://discourse.vtk.org/t/how-to-determine-the-cmake-vtk-components-necessary-for-a-class/11429/1 "2023-05-10T16:29:24Z")

</div>

I haven’t written a CMakeLists.txt file for VTK in a while, and things seem to have evolved somewhat. I’m sure that the reasons are important, and the results are great, but it did take me a while to figure out why I was getting link errors on `vtkXMLPolyDataReader`. My original code:

```auto
find_package(VTK COMPONENTS
    CommonCore)

```

The fixed code:

```auto
find_package(VTK COMPONENTS
    CommonCore
    IOXML)

```

Granted `IOXML` is fairly easy to figure out, but there is nothing on the [documentation page](https://vtk.org/doc/nightly/html/classvtkXMLPolyDataReader.html) that mentions that I needed this …

---

<div class="post-metadata">

### Author: ![Christos\_Tsolakis](https://discourse.vtk.org/user_avatar/discourse.vtk.org/christos_tsolakis/32/2076_2.png) [@Christos\_Tsolakis](https://discourse.vtk.org/u/Christos_Tsolakis)
#### Post date: [May 10, 2023, 5:10pm UTC](https://discourse.vtk.org/t/how-to-determine-the-cmake-vtk-components-necessary-for-a-class/11429/2 "2023-05-10T17:10:15Z")

</div>

Hi @rexthor ,

since you are using `vtkXMLPolyDataReader` you need to include the vtk module that defines this class. Notice that in the VTK source tree the header is located under `IO/XML` which is where the `IOXML` name comes from.

Another way to find the module name is the [vtk.module](https://gitlab.kitware.com/vtk/vtk/-/blob/master/IO/XML/vtk.module) file in the same directory with the header. This is where the module is defined.

Check also this [script](https://kitware.github.io/vtk-examples/site/Python/Utilities/VTKModulesForCxx) from vtk-examples website that creates the “find\_package” string for you.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [May 11, 2023, 7:22am UTC](https://discourse.vtk.org/t/how-to-determine-the-cmake-vtk-components-necessary-for-a-class/11429/3 "2023-05-11T07:22:01Z")

</div>

Hi agree with @rexthor , the needed module dependencies should be listed in the class doc.

Should be added in the automatic documentation process imo.

---

<div class="post-metadata">

### Author: ![rexthor](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rexthor/32/6481_2.png) [@rexthor](https://discourse.vtk.org/u/rexthor)
#### Post date: [May 11, 2023, 12:08pm UTC](https://discourse.vtk.org/t/how-to-determine-the-cmake-vtk-components-necessary-for-a-class/11429/4 "2023-05-11T12:08:32Z")

</div>

Since people in general are quick to say what they don’t like, and often don’t say what they do like: VTK has _great_ documentation, and even lots of examples … so … kudos to all involved.

---

<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 11, 2023, 12:37pm UTC](https://discourse.vtk.org/t/how-to-determine-the-cmake-vtk-components-necessary-for-a-class/11429/5 "2023-05-11T12:37:00Z")

</div>

> [@mwestphal](#):
>
> Should be added in the automatic documentation process imo.

Note that some classes will require module X to compile, but to get real implementations, another module will be needed (e.g., `VTK::RenderingOpenGL2` is rarely used directly rather than via `VTK::RenderingCore` factory classes).

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [May 11, 2023, 12:46pm UTC](https://discourse.vtk.org/t/how-to-determine-the-cmake-vtk-components-necessary-for-a-class/11429/6 "2023-05-11T12:46:30Z")

</div>

Good point, but better to have something than nothing I think.

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [May 12, 2023, 5:47am UTC](https://discourse.vtk.org/t/how-to-determine-the-cmake-vtk-components-necessary-for-a-class/11429/7 "2023-05-12T05:47:40Z")

</div>

This is why [VTKModulesForCxx](https://kitware.github.io/vtk-examples/site/Python/Utilities/VTKModulesForCxx/) generates a series of commented out modules that the user may need to uncomment.  
e.g.

```plaintext
    # These modules are suggested since they implement an existing module.
    # You may need to uncomment one or more of these.
    # If vtkRenderWindow is used and you want to use OpenGL,
    # you also need the RenderingOpenGL2 module.
    # If vtkRenderWindowInteractor is used,
    # uncomment RenderingUI and possibly InteractionStyle.
    # If text rendering is used, uncomment RenderingFreeType
    #
    # FiltersParallel # implements VTK::FiltersCore
    # FiltersParallelDIY2 # implements VTK::FiltersCore
    # RenderingCellGrid # implements VTK::RenderingCore
    # RenderingFreeType # implements VTK::RenderingCore
    # RenderingOpenGL2 # implements VTK::RenderingCore
    # RenderingUI # implements VTK::RenderingCore

```

SImilarly with [VTKImportsForPython](https://kitware.github.io/vtk-examples/site/Python/Utilities/VTKImportsForPython/) you get:

```plaintext
# You may need to uncomment one or more of the following imports.
# If vtkRenderWindow is used and you want to use OpenGL,
# you also need the vtkRenderingOpenGL2 module.
# If vtkRenderWindowInteractor is used, uncomment vtkInteractionStyle
# If text rendering is used, uncomment vtkRenderingFreeType.
#
# If using PyCharm, preface each one you select with this line:
# noinspection PyUnresolvedReferences
#
# import vtkmodules.vtkInteractionStyle
# import vtkmodules.vtkRenderingContextOpenGL2
# import vtkmodules.vtkRenderingFreeType
# import vtkmodules.vtkRenderingOpenGL2
# import vtkmodules.vtkRenderingUI
# import vtkmodules.vtkRenderingVolumeOpenGL2

```

I’m not sure if this can be improved on.

---

<div class="post-metadata">

### Author: ![rexthor](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rexthor/32/6481_2.png) [@rexthor](https://discourse.vtk.org/u/rexthor)
#### Post date: [May 12, 2023, 1:39pm UTC](https://discourse.vtk.org/t/how-to-determine-the-cmake-vtk-components-necessary-for-a-class/11429/8 "2023-05-12T13:39:47Z")

</div>

As infrequently as I make new C++ projects, the script solution you guys mention would work for me. I can only imagine how much of a headache it would be to go back and annotate all of the documents.

---

<div class="post-metadata">

### Author: ![fghoussen](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/ecd19e/32.png) [@fghoussen](https://discourse.vtk.org/u/fghoussen)
#### Post date: [May 24, 2023, 5:54pm UTC](https://discourse.vtk.org/t/how-to-determine-the-cmake-vtk-components-necessary-for-a-class/11429/9 "2023-05-24T17:54:45Z")

</div>

> [@Christos\_Tsolakis](#):
>
> ples website that creates

`python3 "$VTK_ROOT/Utilities/Maintenance/FindNeededModules.py" -j $VTK_ROOT/build/modules.json -s vtkHelloworld.cpp` worked for me: [VTK-9: How to know which VTK COMPONENT contains which VTK class?](https://discourse.vtk.org/t/vtk-9-how-to-know-which-vtk-component-contains-which-vtk-class/11533).

Not sure what is the recommended way to go
