Our top level cmake command succeeded on Rocky9 linux when using a manual build of vtk 8.2. But now when trying to switch to the native version of vtk 9.1.0 as installed on Rocky9 linux from the epel repo, anything in cmake that tries to link in vtk libraries via target_link_libraries(my_binary ${VTK_LIBRARIES}) fails the cmake command with an error “my_binary links to target “X11::X11” but the target was not found”. I’ve seen various postings saying this could be from missing X11 libraries, but I don’t see any missing packages. I believe I’m using the same Rocky9 image where the cmake command succeeds with vtk 8.2. It also looks to me like cmake reports the X11 variables to be the same as when the cmake command succeeds using vtk 8.2:
I believe that 9.1.0 had issues with the no-component variant of find_package(VTK). Can you try adding COMPONENTS … to your find_package(VTK) call that list the components you need?
Thank you Ben - that does work and has allowed me to successfully run a cmake command by specifying some components like CommonCore CommonTransforms IOXML in the list following the COMPONENTS keyword. But since cmake 8.2 did not require specifying components, I don’t know exactly what the component list should be for 9.1.0. As I fault thru our build I come across undefined references to, e.g., vtkRGBATransferFunction, which I do not see directly listed in the Rocky9 system file, /lib64/cmake/vtk/vtk-config.cmake. I have not found any *.modules file to maybe help with mapping that function back to a component. The /lib64/cmake/vtk/vtk-config.cmake does however list the following components,
Thanks - i was able to use the python script(s) from the 9.1.0 source code distribution as you suggested and get a list of Components to start with. I then added some other components, and now almost everything is compiling. The issue I currently have is that when I add in the component RenderingOpenGL2 the references to X11 once again break when running the top level cmake command, and cmake fails. I read that setting VTK_MODULE_ENABLE_VTK_RenderingContextOpenGL2=ON is necessary for Open GL2 (and so set that), but that makes no difference w.r.t the addition of RenderingOpenGL2 causing cmake to fail finding the X11 component. Is there an order dependency in how the components are listed? Right now I am trying to list them in lexicogrpahic order, i.e.,
No, there shouldn’t be. There’s a block of logic leading up to the find_package(X11) inside of VTK’s package. I’d trace that logic. I know there were bugs fixed since 9.1 that may affect this. Does a master build work as expected?
I’m trying to use the native vtk install on Rocky9 Linux. Not sure I understand why /lib64/cmake/vtk/VTK-vtk-module-find-packages.cmake apparently defines find_package(X11) twice - see listing below. In between there is some logic relating to RenderingOpenGL2 which is the module I’m trying to add that causes the X11 not found error to re-appear.
I thought I saw a posting that said it is preferable now to not use VTK_LIBRARIES when linking and instead, spell out the individual VTK components to link against for each application. Just wondering if that more explicit/specific instruction about what to link against might remedy this issue.
find_package(X11
${_vtk_module_find_package_quiet}
${_vtk_module_find_package_required}
COMPONENTS
OPTIONAL_COMPONENTS )
if (NOT X11_FOUND AND _vtk_module_find_package_fail_if_not_found)
if (NOT ${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
message(STATUS
"Could not find the ${CMAKE_FIND_PACKAGE_NAME} package due to a "
"missing dependency: X11")
endif ()
set("${CMAKE_FIND_PACKAGE_NAME}_RenderingOpenGL2_FOUND" 0)
list(APPEND "${CMAKE_FIND_PACKAGE_NAME}_RenderingOpenGL2_NOT_FOUND_MESSAGE"
"Failed to find the X11 package.")
endif ()
endif ()
unset(_vtk_module_find_package_fail_if_not_found)
unset(_vtk_module_find_package_enabled)
unset(_vtk_module_find_package_required)
set(_vtk_module_find_package_enabled OFF)
set(_vtk_module_find_package_is_required OFF)
set(_vtk_module_find_package_fail_if_not_found OFF)
if (_vtk_module_find_package_components)
if ("RenderingUI" IN_LIST _vtk_module_find_package_components)
set(_vtk_module_find_package_enabled ON)
if ("RenderingUI" IN_LIST _vtk_module_find_package_components_required)
set(_vtk_module_find_package_is_required "${${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED}")
set(_vtk_module_find_package_fail_if_not_found ON)
endif ()
endif ()
else ()
set(_vtk_module_find_package_enabled ON)
set(_vtk_module_find_package_is_required "${${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED}")
set(_vtk_module_find_package_fail_if_not_found ON)
endif ()
if (_vtk_module_find_package_enabled)
set(_vtk_module_find_package_required)
if (_vtk_module_find_package_is_required)
set(_vtk_module_find_package_required REQUIRED)
endif ()
find_package(X11
${_vtk_module_find_package_quiet}
${_vtk_module_find_package_required}
COMPONENTS
OPTIONAL_COMPONENTS )
if (NOT X11_FOUND AND _vtk_module_find_package_fail_if_not_found)
if (NOT ${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
message(STATUS
"Could not find the ${CMAKE_FIND_PACKAGE_NAME} package due to a "
"missing dependency: X11")
endif ()
set("${CMAKE_FIND_PACKAGE_NAME}_RenderingUI_FOUND" 0)
list(APPEND "${CMAKE_FIND_PACKAGE_NAME}_RenderingUI_NOT_FOUND_MESSAGE"
"Failed to find the X11 package.")
endif ()
endif ()
I tried setting target_link_libraries(appname VTK::component VTK::component …) as needed per application instead of listing all the vtk components used across all apps in a top level find_package VTK function. But as soon as I add either the GUISupport or RenderingOpenGL2 component into any applications target_link_libraries vtk component list, then the X11 include error happens. I see in the rocky9 system file VTK-targets.cmake that RenderingOpenGL2 lists X11:X11 in INTERFACE_LINK_LIBRARIES along with RenderingGUI. Then RenderingGUI lists X11:X11 again in its INTERFACE_LINK_LIBRARIES components. Eliminating those X11 references did not make any difference. As a workaround to not being able to add in the RenderingOpenGL2 component into target_link_libraries function for the application that needs it, I tried adding link_directories(path) to the system path where libvtkRenderingOpenGL2.so lives. With that addition, it does look like the linker is now finding that library. However, I am not sure this mixture of using both target_link_libraries(appname VTK::component VTK::component …) with deliberately excluded components that are needed - along with the added link_directories(systempath) - is going to work or be the correct way to build things. Finally, I see the rocky9 system has a file /lib64/cmake/vtk/patches /3.19/FindX11.cmake. That looks like a function to update the X11 definitions. I tried including that file to be read in the CMakeLists.txt for the application that needs the RenderingOpenGL2 component, but I still get the X11 include with RenderingOpenGL2 added into target_link_libraries. Not sure how to proceed at this point.