Build VTK 8.1.0 with Qt in Mac

This is the second time I try to build the VTK in Mac. One month ago, I took a lot of time to find how to compile it with CMake and built it successfully, but it is much easier to forget the process. Here I record the entire compiling process.

First step is to download the VTK from the VTK official website. Then, unzip the package to a folder. Here I put it into the folder called “VTK-8.1.0”. By the way, you should also install CMake from the CMake website (Please ensure that the Qt and Xcode are installed in your Mac). Now, create another folder called “VTK_Build”. This is the target folder to save the files generated by CMake. Open CMake and set the “source code” and “binaries” folder:

Cd63a2.png

Click “Configure” button, and set the generator for the source code, I just use the default selection. This means we will use make and make install to compile the code:

NG50h6.png

After click “Done”, CMake will configure the code:

EY42u0.png

Now, we create another folder called “VTK_Bin” which is used to install VTK libraries. In CMake, we need change two options:

CMAKE_INSTALL_PREFIX: /User/zhudongping/Documents/Code/VTK_Bin
VTK_Group_Qt: ON

Qv92O9.png

Click “Configure” again, and CMake will tell you it cannot found the Qt5_DIR:

Lq67P7.png

Set the Qt5_DIR: /Applications/Qt/5.10.0/clang_64/lib/cmake/Qt5 and click “Configure” again. you will see:

Br47o0.png

Now, you need click “Configure” again, CMake will finish the final configuration. Dx12h2.png

Then, Click “Generate” in the panel to generate the binaries into “VTK_Build”. Use Mac terminal to find this folder and type make command. If you want to use multithreading, type make -j8 command. Mac will compile the files generated by CMake:

HY83i2.png

After the make command, you just need to type make install command to install the VTK libraries into “VTK_Bin” folder:

Iu03h2.png

Now, we successfully build the source code of VTK 8.1.0:

Gs52h7.png

For using VTK in Qt 5.10.0, Remember to put the following code into main function:

QSurfaceFormat::setDefaultFormat(QVTKOpenGLWidget::defaultFormat());

Leave a Reply