I’m not completely certain, but I think the basic workings of autoinit are the same for VTK 9. But the dependencies might have been shuffled around a bit.
Before #include <vtkAutoInit.h>, you will need definitions like this:
Things do compile down to VTK_MODULE_INIT, but the interface generated is the code shown above. I think you need to include a header from the module you want to initialize as well, but I’m not sure. I figured it out once to write the new module system’s autoinit support, but it’s way too complicated to stick for long.
I’m afraid I’m not getting much out of the module system documentation. Is there some way to find out which autoinit #defines I need, perhaps from a list of which vtk headers I’m including in my C++ code? Or is there a list of what the options are, so that I can experiment to see which ones eliminate the build errors?
Is it possible to download all of the C++ examples in bulk? I could build them and see what definitions cmake generates for the examples that use the parts of vtk that I need. Would that work?
Did you try the #defines that I suggested? You might have missed them if you’re reading through email, since I edited my response via discourse rather than sending an additional reply.
Run on the VTK source file Filters/Modeling/Testing/Cxx/TestRotationalExtrusion.cxx, it produces
find_package(VTK
COMPONENTS
CommonCore
FiltersCore
FiltersModeling
FiltersSources
RenderingCore
TestingCore
TestingRendering
# These modules are suggested since they implement an existing module.
# Uncomment those you need.
# FiltersParallel # implements VTK::FiltersCore
# FiltersParallelGeometry # implements VTK::FiltersCore
# InteractionStyle # implements VTK::RenderingCore
# RenderingFreeType # implements VTK::RenderingCore
# RenderingOpenGL2 # implements VTK::RenderingCore
# RenderingUI # implements VTK::RenderingCore
)
While this generates a find_package call meant for use in CMake, you can extract the module names listed under COMPONENTS, prepend “vtk” onto them, and you’ve got at least the module dependencies.
Cory – this looks like it’s sending me in the right direction. Do I need to use the results to construct the #defines that David suggested, somehow? Do the commented out lines give me choices of different implementations, where I’m supposed to pick just one?
I’m sorry if I’m being dim. I feel that there are fundamental topics here that I don’t understand, and haven’t found the right references for.
Yeah, it’s more focused on how to use its APIs rather than on how its APIs work internally.
Once you have the WhatModulesVTK.py output (uncommenting some of the implementation modules if you need them), you can write a small project:
cmake_minimum_required(VERSION 3.13)
project(vtktest C CXX)
find_package(VTK) # see WhatModulesVTK.py output
add_library(foo dummy.cxx)
target_link_libraries(foo) # link what VTK libraries you want
vtk_module_autoinit(TARGETS foo MODULES …) # same VTK libraries as above
When you generate this project, there’s a header named vtkModuleAutoInit_<md5hash>.h in the build tree. This is the set of defines you need.
I appreciate all the help, but I still have a bunch of questions.
I think I’ve done what Ben suggested above, but I’m getting errors like
CMake Error at /home/langer/lib/cmake/vtk-9.0/vtkModule.cmake:1136 (message):
Failed to determine the real target for the `CommonCore` module. Is a
`find_package` missing a required component?
Does the word “component” in the error message mean that something is missing from the COMPONENTS section of the find_package arguments, or is it being used in a non-technical sense to mean that some other arguments are missing?
CMakeError.log only contains errors regarding pthreads (?!), but none of the fixes for that that I found on-line made any difference. Is that something I need to be worried about?
Is foo in the example a literal foo or do I need to replace it with something? I have been assuming it’s a placeholder for something that doesn’t matter because I’m not actually building anything with this code.
The Ubuntu 18 system that I’m using only has cmake 3.10, so I changed the minimum version number. Will that matter? I got the same results on a newer Ubuntu with a newer cmake, > 3.13.
VTK provides its usage API as CMake code and a CMake API. Other build systems would need to figure out how to utilize VTK’s autoinit system on their own. It doesn’t change that often, so doing the “see what VTK’s CMake API does and copy it into a static header in my project” is probably sufficient.
As for the error you’re seeing, it looks like VTK::CommonCore is not a target at some location. Could you please provide the full callstack?
CMake Error at /home/langer/lib/cmake/vtk-9.0/vtkModule.cmake:1136 (message):
Failed to determine the real target for the `CommonCore` module. Is a
`find_package` missing a required component?
Call Stack (most recent call first):
/home/langer/lib/cmake/vtk-9.0/vtkModule.cmake:2865 (_vtk_module_real_target)
CMakeLists.txt:43 (vtk_module_autoinit)
That was very helpful, in that it did generate a .h file containing the right sort of #defines, but when they’re inserted into my program before #include <vtkAutoInit.h> I still get the same errors.
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-gnDdqE/python2.7-2.7.17=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -g -UNDEBUG -DDEBUG -I/usr/include/python2.7 -I/home/langer/include/vtk-9.0 -Ibuild/temp.linux-x86_64-2.7-3d/SRC -ISRC -I/usr/include/python2.7 -I/home/langer/include/vtk-9.0 -c ./SRC/common/IO/vtkutils.C -o build/temp.linux-x86_64-2.7-3d/./SRC/common/IO/vtkutils.o -std=c++11
In file included from ./SRC/common/IO/vtkutils.C:60:0:
./SRC/common/IO/vtkutils.C: In function ‘void initialize_vtk()’:
/home/langer/include/vtk-9.0/vtkAutoInit.h:88:3: error: expected identifier before ‘{’ token
{ \
^
./SRC/common/IO/vtkutils.C:83:5: note: in expansion of macro ‘VTK_MODULE_INIT’
VTK_MODULE_INIT(CommonCore);
^~~~~~~~~~~~~~~
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
Has the syntax for VTK_MODULE_INIT changed? I assume I need a VTK_MODULE_INIT line for each of the components that I got from FindNeededModules. I’ve tried prefixing “vtk” or “vtk::” to the module name but even if that’s what’s wrong it doesn’t change the results.
I think you can just drop VTK_MODULE_INIT if you’re using the code that got generated. I don’t think VTK generates that macro at all (other than through the expansions in vtkAutoInit.h.