# VTK CMake Usage

**URL:** https://discourse.vtk.org/t/vtk-cmake-usage/3275
**Category:** Support
**Created:** [May 11, 2020, 8:43pm UTC](https://discourse.vtk.org/t/vtk-cmake-usage/3275 "2020-05-11T20:43:30Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![webbbn](https://discourse.vtk.org/user_avatar/discourse.vtk.org/webbbn/32/1773_2.png) [@webbbn](https://discourse.vtk.org/u/webbbn)
#### Post date: [May 11, 2020, 8:43pm UTC](https://discourse.vtk.org/t/vtk-cmake-usage/3275/1 "2020-05-11T20:43:30Z")

</div>

How does one find and use VTK in CMake with 9.0.0. I’m using find\_package(VTK REQUIRED …), and it’s seems happy, although the only output appears to be finding X11 and Xt. All the documentation that I can find is conflicting, and appears to be outdated.

I would appreciate it if someone could point me to up-to-date documentation or an example. I just need to know what variable to use to get the include/library paths, and libraries.

---

<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, 2020, 10:56pm UTC](https://discourse.vtk.org/t/vtk-cmake-usage/3275/2 "2020-05-11T22:56:00Z")

</div>

Great timing. I just wrote up [this document](https://gitlab.kitware.com/vtk/vtk/-/merge_requests/6881/diffs) which details how to do it. Do you have any feedback on what else could go into it before it gets merged (it’ll be in 9.0.1)? It looks a bit weird and links are broken because it’s actually a Doxygen input (where it will ultimately end up).

I know the wiki is out-of-date; it needs a sweep to put banners about that and the still-pertinent information migrated into the repository.

---

<div class="post-metadata">

### Author: ![webbbn](https://discourse.vtk.org/user_avatar/discourse.vtk.org/webbbn/32/1773_2.png) [@webbbn](https://discourse.vtk.org/u/webbbn)
#### Post date: [May 12, 2020, 2:14pm UTC](https://discourse.vtk.org/t/vtk-cmake-usage/3275/3 "2020-05-12T14:14:23Z")

</div>

That is exactly what I was looking for, and it’s working perfectly. Thank you!

---

<div class="post-metadata">

### Author: ![codeling](https://discourse.vtk.org/user_avatar/discourse.vtk.org/codeling/32/3792_2.png) [@codeling](https://discourse.vtk.org/u/codeling)
#### Post date: [May 12, 2020, 6:37pm UTC](https://discourse.vtk.org/t/vtk-cmake-usage/3275/4 "2020-05-12T18:37:09Z")

</div>

Quick question: usage of `VTK_LIBRARIES` is discouraged in [https://gitlab.kitware.com/vtk/vtk/-/blob/1abfe43a7b32b4606964005627b6c40723883a2e/Documentation/Doxygen/ModuleMigration.md](https://gitlab.kitware.com/vtk/vtk/-/blob/1abfe43a7b32b4606964005627b6c40723883a2e/Documentation/Doxygen/ModuleMigration.md), but why exactly?  
It contains all libraries needed to fulfill what was requested as components in the `find_package` call, right?  
So why would I not just use this list, and instead again separately list the libraries in the `target_link_library` and the `vtk_module_autoinit`

---

<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 12, 2020, 7:01pm UTC](https://discourse.vtk.org/t/vtk-cmake-usage/3275/5 "2020-05-12T19:01:31Z")

</div>

If you only have one set of VTK requirements, it’s fine. But it can lead to overlinking:

```auto
add_library(needscore ...)
target_link_libraries(needscore PRIVATE VTK::CommonCore)

add_library(needsrendering ...)
target_link_libraries(needsrendering PRIVATE VTK::RenderingOpenGL2)

```

Using `${VTK_LIBRARIES}` instead means that `needscore` all of a sudden ends up needing X, OpenGL, Cocoa, etc. (depending on the platform). Explicit usage is recommended so that you don’t end up adding extra links if you have another VTK-using target that needs a new component (“explicit is better than implicit”).

---

<div class="post-metadata">

### Author: ![codeling](https://discourse.vtk.org/user_avatar/discourse.vtk.org/codeling/32/3792_2.png) [@codeling](https://discourse.vtk.org/u/codeling)
#### Post date: [May 12, 2020, 7:07pm UTC](https://discourse.vtk.org/t/vtk-cmake-usage/3275/6 "2020-05-12T19:07:02Z")

</div>

@ben.boeckel thanks for clarifying, makes sense!

---

<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 17, 2020, 2:20am UTC](https://discourse.vtk.org/t/vtk-cmake-usage/3275/7 "2020-05-17T02:20:20Z")

</div>

@ben.boeckel Should a mention also be made about `VTK/Utilities/Maintenance/FindNeededModules.py`? This is definitely useful for determining what modules your code needs in the new system.

---

<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 17, 2020, 10:59am UTC](https://discourse.vtk.org/t/vtk-cmake-usage/3275/8 "2020-05-17T10:59:02Z")

</div>

That is only available in the build tree (the needed JSON file is not installed), so not as immediately useful without some further work.

---

<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 17, 2020, 9:58pm UTC](https://discourse.vtk.org/t/vtk-cmake-usage/3275/9 "2020-05-17T21:58:56Z")

</div>

I didn’t know that as I always use the build tree. I must admit I find it quite useful.
