VTK_DIR beginner, hello

Hi, How do I specify a permanent VTK_DIR in the makefile or for CMAKE so that I don’t have to keep typing it into CMAKE everytime I try a new example?

You can either set the VTK_DIR from command line when you call cmake

cmake -DVTK_DIR:PATH=/home/me/vtk_build ..

(as shown in many of the examples like here) or you can modify the cmake file included with the example.

As far as I know there is no way of setting some environment variable such that all examples automatically know where VTK is located.

You can also use cmake presets: https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html

Are you talking about cmakelists.txt ? In the gui the variables are saved in CMakeCache.txt but where are they originally read from in the gui?

The variables that you see in the gui before setting anything manually are default values that are specified in the CMakeLists.txt of that project you are building. They are often defined as an option (https://cmake.org/cmake/help/latest/command/option.html) but the VTK_DIR variable is slightly different. It just gives cmake the location where it can find a certain package. These types of variables are used to find other packages that your project requires. You can see that command in all the CMakeLists.txt files of the vtk examples.

They look like similar to this:

find_package(VTK COMPONENTS 

I am still not quite sure what you are trying to do? Are you testing different examples and you believe its taking too long to set each of them up?

Thanks I think it’s the statement: option( “<help_text>” [value])
in cmakelists.txt. I added this:
option(VTK_DIR “VTK’s build or make folder” C:/VTK/VTK-9.0.3/build )

I had a few errors and the error message was incorrect but I could figure it out.
Now I need to specify the sdk build for windows which defaults somehow (the platform).

I need to set these two variables in the project (change from what their default is):
(the .vcxproj file)


and this one:


Are these also possible option variables? I can change these in Visual Studio itself I suppose…

Can you explain in more detail what your project setup is? Because what you are doing there seems very uncommon to me.

When using cmake you dont usually modify the .vcxproj files as far as I know since these are generated by cmake for you. Thats the purpose of cmake. It generates build files for different platforms.

Hi thanks for reply!
Well, I’m specifying the VTK folder so that it is known and can be moved to another PC.
in VS2017 or VS2019, (two computers, home and work), How much detail do you want?
It needs to specify the windows platform and sdk. WindowsTargetPlatform and PlatformToolset. The project will be built with a preexisting windows project that is being built using those specific variables. The VTK project will be integrated with code that has existed up to 30 years. (an ECG application) I help the company migrate old code to new. (32 bit to 64. Old windows to new, etc). The project settings I can modify in VS after the CMake builds them. I was just hoping that they could be specified in CMake itself. many xml entries in the ‘vcxproj’ files are build settings that should be set to create them.

I am building the SurfacePlot sample (for starters), with the intention to modify it for a work application that is an application that goes back over 20 years, and the functionality will gradually integrate with preexisting code and company’s (commercial) application. Hopefully vtk will be used to replace more functionality as it migrates. It is a custom old-style windows (monolithic) app.

Plus I can simply comment that the CMakeLists.txt file is nice but there are often syntax errors that are hard to find (I just back out and think about it) because the messages are off-target. It would be best I think to actually SHOW the file in CMake itself (the gui) so at least one could view it, but this is a SMALL issue for me, but might help new users to get accustomed to it. It works great even if errors are hard to decypher sometimes…

So you are trying to integrate VTK into the old application?

Is this old application build with cmake?

Right now it is to build SurfacePlot example. The integrate will come later.
I had it built but now I have the error:
1>C:\VTK\VTK-9.0.3\build\Rendering\Core\vtkRenderingCoreModule.h(47): fatal error C1083: Cannot open include file: ‘C:/Users/tamnt/Documents/Visual Studio 2019/SurfacePlot/SurfacePlot/build/CMakeFiles/vtkModuleAutoInit_04d683062bbc5774e34e8c62b13e1a5a.h’: No such file or directory
another problem.

All right I think I understand now. So right now all you trying to do is compile the example?

If you have not fixed the error by now please make sure that you have followed the steps in this configure and build tutorial for vtk: https://vtk.org/Wiki/VTK/Configure_and_Build
I set up my vtk installation like that. Then downloaded the example, extracted it, used cmake gui to configure it (the same way as in the tutorial above). Then I opened it in visual studio and was able to compile and run after telling it where the vtk .dll’s are it worked. If these steps dont work for you please tell us what you did and what kind of modifications you did to the example or vtk (if you did any).

Additionally regarding the setting of the VTK_DIR variable I might have explained it a little bit wrong. This shows you a very simple CMakeLists.txt where the VTK_DIR variable is set within the file.