Building#
This page describes how to build and install VTK. It covers building for development, on both Unix-type systems (Linux, HP-UX, Solaris, macOS), and Windows. Note that Unix-like environments such as Cygwin and MinGW are not officially supported. However, patches to fix problems with these platforms will be considered for inclusion. It is recommended that users which require VTK to work on these platforms to submit nightly testing results for them.
A full-featured build of VTK depends on several open source tools and libraries such as Python, Qt, CGNS, HDF5, etc. Some of these are included in the VTK source itself (e.g., HDF5), while others are expected to be present on the machine on which VTK is being built (e.g., Python, Qt).
VTK supports all of the common generators supported by CMake. The Ninja, Makefiles, and Visual Studio generators are the most well-tested however.
Note that VTK does not support in-source builds, so you must have a build tree that is not the source tree.
Obtaining the sources#
There are two approaches:
Download the source release
VTK-X.Y.Z.tar.gz
from https://vtk.org/download/.Create a folder for VTK.
Extract the contents of the VTK folder in the downloaded archive to the subfolder called
source
To obtain VTK’s sources locally, clone the VTK repository using Git.
Open Git Bash
on Windows or a terminal on Linux and macOS and
execute the following:
mkdir -p ~/vtk
git clone --recursive https://gitlab.kitware.com/vtk/vtk.git ~/vtk/source
To use the latest features being developed or to make changes and contribute to VTK, download the source using Git Clone.
Prerequisites#
VTK only requires a few packages in order to build in general, however specific features may require additional packages to be provided to VTK’s build configuration.
Required:
-
Version 3.12 or newer, however, the latest version is always recommended. If the system package management utilities do not offer cmake or if the offered version is too old Precompiled binaries available on CMake’s download page.
Supported compiler
GCC 4.8 or newer
Clang 3.3 or newer
Apple Clang 7.0 (from Xcode 7.2.1) or newer
Microsoft Visual Studio 2015 or newer
Intel 14.0 or newer
Optional Additions#
ffmpeg When the ability to write
.avi
files is desired, and writing these files is not supported by the OS, VTK can use the ffmpeg library. This is generally true for Unix-like operating systems. Source code for ffmpeg can be obtained from the website.MPI To run VTK in parallel, an MPI implementation is required. If an MPI implementation that exploits special interconnect hardware is provided on your system, we suggest using it for optimal performance. Otherwise, on Linux/Mac, we suggest either OpenMPI or MPICH. On Windows, Microsoft MPI is required.
Python In order to use scripting, Python is required. The minimum supported version is 3.4. The instructions are using the system Python. On Ubuntu/Debian the required package is
python3-dev
. If you use a different Python implementation or a virtual environment make sure the environment you use is activated. On Ubuntu/Debian the required package for creating virtual environments ispython3-venv
.Qt5 VTK uses Qt as its GUI library (if the relevant modules are enabled). Precompiled binaries are available on Qt’s website. Note that on Windows, the compiler used for building VTK must match the compiler version used to build Qt. Version 5.9 or newer is required.
OSMesa Off-screen Mesa can be used as a software-renderer for running VTK on a server without hardware OpenGL acceleration. This is usually available in system packages on Linux. For example, the
libosmesa6-dev
package on Debian and Ubuntu. However, for older machines, building a newer version of Mesa is likely necessary for bug fixes and support. Its source and build instructions can be found on its website.
Creating the Build Environment#
Install CMake
Install Visual Studio Community Edition
During installation select the “desktop development with C++” workload.
Use “x64 Native Tools Command Prompt” for the installed Visual Studio version to configure with CMake and to build with ninja.
Get ninja. Unzip the binary and put it in
PATH
. Note that newer Visual Studio releases come with a version ofninja
already and should already exist inPATH
within the command prompt.
Install the following packages:
$ sudo apt install \
build-essential \
cmake \
cmake-curses-gui \
mesa-common-dev \
mesa-utils \
freeglut3-dev \
ninja-build
Install CMake
Install XCode
Ensure XCode command line tools are installed:
xcode-select --install
Note
ninja
is a more efficient alternative to Makefiles
or Visual Studio solution files. The
speed increase is the most noticeable when doing incremental build.
Configure#
In order to build, CMake requires two steps, configure and build. VTK itself does not support what are known as in-source builds, so the first step is to create a build directory.
Open “x64 Native Tools Command Prompt” for the installed Visual Studio:
ccmake -GNinja -S %HOMEPATH%\vtk\source -B %HOMEPATH%\vtk\build
Note that CMake GUI must also be launched from the “Native Tools Command Prompt”.
Use CMake to generate a Visual Studio solution file (.sln
).
Open CMake GUI, either by typing
cmake-gui
on the command prompt or from the start-menu.Enter the source and build directories
Click
[Configure]
You will now get a selection screen in which you can specify your “generator”. Select the one you need.
We are now presented with a few options that can be turned on or off as desired.
Click
[Configure]
to apply the changes.Click
[Generate]
. This will populate the “build” sub-folder.Finally, click
[Open Project]
to open the generated solution in Visual Studio.
mkdir -p ~/vtk/build
cd ~/vtk/build
ccmake -GNinja ../path/to/vtk/source
The parameter -GNinja
may be skipped to use the default generator (e.g Unix Makefiles
).
Missing dependencies
CMake may not find all dependencies automatically in all cases. The steps needed to find any given package depends on the package itself.
For general assistance, please see the documentation for
find_package
’s search procedure and
the relevant Find module (as available).
Hint
Different features can be enabled/disabled by setting the Build Settings during the configure stage.
Building#
To build VTK:
cmake --build %HOMEPATH%\vtk\build --config Release
Open the generated solution file.
Set the configuration to “Release”
On the menu bar, choose
Build
, and then chooseBuild Solution
.
cmake --build ~/vtk/build