PointCloudLibrary / pcl

Point Cloud Library (PCL)
https://pointclouds.org/
Other
9.98k stars 4.62k forks source link

io & 2d CMake configs fail to ignore VTK even when WITH_VTK set to OFF #2649

Open catskul opened 5 years ago

catskul commented 5 years ago

Environment

Context

PCL built with WITH_VTK=OFF OS has VTK libraries installed, but with no intention of using them here. Linking against PCL_IO with ${PCL_IO_LIBRARIES} after a find_package(PCL NO_MODULE REQUIRED COMPONENTS io)

Expected Behavior

PCL compiled with WITH_VTK=OFF should not attempt to link against VTK, nor cause dependants to try to link against VTK

Current Behavior

When compiling a system against a custom build of PCL with WITH_VTK=OFF, linking to PCL_IO using

target_link_libraries(mytarget ${PCL_IO_LIBRARIES}) Causes the mytarget to link against VTK despite my intentions to prevent this.

Possible Solution

I'm not a CMake expert so I hesitate to suggest a solution or to submit a pull request, but If my diagnosis is correct, then:

PCLConfig.cmake.in uses @PCLCONFIG_EXTERNAL_DEPENDENCIES@ To dump in

set(pcl_io_opt_dep openni openni2 ensenso davidSDK dssdk pcap png vtk libusb-1.0 )
set(pcl_2d_opt_dep vtk )

into PCLConfig.cmake causing anyone linking against anything dependant on pcl_io or pcl_2d to try to link against VTK.

This appears to happe because of io/CMakeLists.txt line 10 where we see: PCL_SUBSYS_DEPEND(build "${SUBSYS_NAME}" DEPS ${SUBSYS_DEPS} OPT_DEPS openni openni2 ensenso davidSDK dssdk pcap png vtk libusb-1.0)

And 2d/CMakeLists.txt line '7' where we see: PCL_SUBSYS_DEPEND(build "${SUBSYS_NAME}" DEPS ${SUBSYS_DEPS} OPT_DEPS vtk)

regardless of whether WITH_VTK is OFF or ON

Adding a check for WITH_VTK around that PCL_SUBSYS_DEPEND line might do the trick.

simonschmeisser commented 5 years ago

this is very unfortunate as I cannot figure out how NOT to load the IO module. It is defined as an optional dependency of kdtree here https://github.com/PointCloudLibrary/pcl/blob/214bb392559b229964c043b400f9590d09ef9e5e/test/kdtree/CMakeLists.txt#L4