# How to get VTK headers from VTK\_LIBRARIES returned by cmake find\_package()?

**URL:** https://discourse.vtk.org/t/how-to-get-vtk-headers-from-vtk-libraries-returned-by-cmake-find-package/8608
**Category:** Support
**Created:** [May 27, 2022, 2:11am UTC](https://discourse.vtk.org/t/how-to-get-vtk-headers-from-vtk-libraries-returned-by-cmake-find-package/8608 "2022-05-27T02:11:09Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Tomasso](https://discourse.vtk.org/user_avatar/discourse.vtk.org/tomasso/32/5786_2.png) [@Tomasso](https://discourse.vtk.org/u/Tomasso)
#### Post date: [May 27, 2022, 2:11am UTC](https://discourse.vtk.org/t/how-to-get-vtk-headers-from-vtk-libraries-returned-by-cmake-find-package/8608/1 "2022-05-27T02:11:09Z")

</div>

I’m running cmake version 3.23.0-rc1, on ubuntu 20.04. I built vtk-9.0 from source; cmake, make, then ‘make install’. Now I am trying to find the VTK package for my own application, using cmake’s find\_package(VTK). The application’s CMakeLists.txt contains this:

```auto
find_package(VTK)

```

Result is that VTK\_LIBRARIES contains many entries, but VTK\_INCLUDE\_DIRS is blank/empty.

```auto
VTK_LIBRARIES: VTK::WrappingTools;VTK::ViewsQt;VTK::ViewsInfovis;VTK::CommonColor;VTK::ViewsContext2D;VTK::loguru;VTK::TestingRendering;VTK::TestingCore;VTK::vtksys;VTK::RenderingQt;VTK::PythonContext2D;VTK::RenderingVolumeOpenGL2;VTK::RenderingOpenGL2;VTK::glew;VTK::opengl;VTK::PythonInterpreter;VTK::Python;VTK::RenderingLabel;VTK::octree;VTK::RenderingLOD;VTK::RenderingImage;VTK::RenderingContextOpenGL2;VTK::IOVeraOut;VTK::hdf5;VTK::IOTecplotTable;VTK::IOSegY;VTK::IOParallelXML;VTK::IOPLY;VTK::IOOggTheora;VTK::theora;VTK::ogg;VTK::IONetCDF;VTK::netcdf;VTK::IOMotionFX;VTK::pegtl;VTK::IOParallel;VTK::jsoncpp;VTK::IOMINC;VTK::IOLSDyna;VTK::IOInfovis;VTK::libxml2;VTK::zlib;VTK::IOImport;VTK::IOGeometry;VTK::IOVideo;VTK::IOMovie;VTK::IOExportPDF;VTK::libharu;VTK::IOExportGL2PS;VTK::RenderingGL2PSOpenGL2;VTK::gl2ps;VTK::png;VTK::IOExport;VTK::RenderingVtkJS;VTK::RenderingSceneGraph;VTK::IOExodus;VTK::exodusII;VTK::IOEnSight;VTK::IOCityGML;VTK::pugixml;VTK::IOAsynchronous;VTK::IOAMR;VTK::InteractionImage;VTK::ImagingStencil;VTK::ImagingStatistics;VTK::ImagingMorphological;VTK::ImagingMath;VTK::GUISupportQtSQL;VTK::IOSQL;VTK::sqlite;VTK::GUISupportQt;VTK::GeovisCore;VTK::libproj;VTK::InfovisLayout;VTK::ViewsCore;VTK::InteractionWidgets;VTK::RenderingVolume;VTK::RenderingAnnotation;VTK::ImagingHybrid;VTK::ImagingColor;VTK::InteractionStyle;VTK::FiltersTopology;VTK::FiltersSelection;VTK::FiltersSMP;VTK::FiltersPython;VTK::FiltersProgrammable;VTK::FiltersPoints;VTK::FiltersVerdict;VTK::verdict;VTK::FiltersParallelImaging;VTK::FiltersImaging;VTK::ImagingGeneral;VTK::FiltersHyperTree;VTK::FiltersGeneric;VTK::FiltersFlowPaths;VTK::FiltersAMR;VTK::FiltersParallel;VTK::FiltersTexture;VTK::FiltersModeling;VTK::FiltersHybrid;VTK::RenderingUI;VTK::DomainsChemistry;VTK::CommonPython;VTK::WrappingPythonCore;VTK::ChartsCore;VTK::InfovisCore;VTK::FiltersExtraction;VTK::ParallelDIY;VTK::diy2;VTK::IOXML;VTK::IOXMLParser;VTK::expat;VTK::ParallelCore;VTK::IOLegacy;VTK::IOCore;VTK::doubleconversion;VTK::lz4;VTK::lzma;VTK::utf8;VTK::FiltersStatistics;VTK::eigen;VTK::ImagingFourier;VTK::ImagingSources;VTK::IOImage;VTK::DICOMParser;VTK::jpeg;VTK::metaio;VTK::tiff;VTK::RenderingContext2D;VTK::RenderingFreeType;VTK::freetype;VTK::kwiml;VTK::RenderingCore;VTK::FiltersSources;VTK::ImagingCore;VTK::FiltersGeometry;VTK::FiltersGeneral;VTK::CommonComputationalGeometry;VTK::FiltersCore;VTK::CommonExecutionModel;VTK::CommonDataModel;VTK::CommonSystem;VTK::CommonMisc;VTK::CommonTransforms;VTK::CommonMath;VTK::CommonCore

```

I see that find\_package(VTK) no longer sets VTK\_INCLUDE\_DIRS variable, as the comments in `vtk-config.cmake` script [CMake/vtk-config.cmake.in](https://github.com/Kitware/VTK/blob/master/CMake/vtk-config.cmake.in) make no mention of `VTK_INCLUDE_DIRS`.

Someone on another forum notes that `VTK_LIBRARIES` variable contains IMPORTED targets (in form of `VTK::foo`), and linking an executable with the content of that variable using `target_link_libraries` will automatically provide include directories. But I am building a static library whose source files include VTK headers; in this case CMakeLists.txt doesn’t call target\_link\_libraries(), but looks like this:

```auto
set(src
    Camera.cpp
    MBQuickItem.cpp
    ColorMap.cpp)

# Static library
add_library(MBGui
            STATIC
            ${src})
            
# Source files include VTK headers - where to find them?
target_include_directories(MBGui
                           PUBLIC
                           .
                           ${MB_HOME}/src/mbio
                           ${OPENGL_INCLUDE_DIR}
                           ${GMT_INCLUDE_DIR}
                           ${QT5_INCLUDE_DIR})

set_target_properties(MBGui PROPERTIES
 POSITION_INDEPENDENT_CODE ON)

```

How do I specify VTK includes in target\_include\_directories(), if VTK\_INCLUDE\_DIRS is blank? What do you think, @ben.boeckel?

Thanks!

---

<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 27, 2022, 1:18pm UTC](https://discourse.vtk.org/t/how-to-get-vtk-headers-from-vtk-libraries-returned-by-cmake-find-package/8608/2 "2022-05-27T13:18:40Z")

</div>

> [@Tomasso](#):
>
> How do I specify VTK includes in target\_include\_directories(),

You don’t. Just use `target_link_libraries()` to link to the targets you need. The includes will be added that way.

---

<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 27, 2022, 1:19pm UTC](https://discourse.vtk.org/t/how-to-get-vtk-headers-from-vtk-libraries-returned-by-cmake-find-package/8608/3 "2022-05-27T13:19:10Z")

</div>

> [@Tomasso](#):
>
> But I am building a static library whose source files include VTK headers

You still need to link to VTK here.

---

<div class="post-metadata">

### Author: ![Tomasso](https://discourse.vtk.org/user_avatar/discourse.vtk.org/tomasso/32/5786_2.png) [@Tomasso](https://discourse.vtk.org/u/Tomasso)
#### Post date: [May 27, 2022, 5:13pm UTC](https://discourse.vtk.org/t/how-to-get-vtk-headers-from-vtk-libraries-returned-by-cmake-find-package/8608/4 "2022-05-27T17:13:39Z")

</div>

Most un-intuitive thing ever - but it works! Thanks @ben.boeckel

---

<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 27, 2022, 6:22pm UTC](https://discourse.vtk.org/t/how-to-get-vtk-headers-from-vtk-libraries-returned-by-cmake-find-package/8608/5 "2022-05-27T18:22:06Z")

</div>

Note that include directories are not the only thing you may need to use a module. Compiler definitions, linker flags, etc. are also part of these usage requirements. See [this part of the tutorial](https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20Usage%20Requirements%20for%20a%20Library.html).
