Could NOT find LibPROJ

I am working with a new install of VTK 9.5.0 from MacPorts. Then I try to build GDCM, an application that uses VTK. I get this error at the CMake configuration stage:

CMake Error at /opt/local/share/cmake-3.31/Modules/FindPackageHandleStandardArgs.cmake:233 (message):
  Could NOT find LibPROJ (missing: LibPROJ_LIBRARY LibPROJ_INCLUDE_DIR)
Call Stack (most recent call first):
  /opt/local/share/cmake-3.31/Modules/FindPackageHandleStandardArgs.cmake:603 (_FPHSA_FAILURE_MESSAGE)
  /opt/local/lib/cmake/vtk-9.5/FindLibPROJ.cmake:42 (find_package_handle_standard_args)
  /opt/local/lib/cmake/vtk-9.5/VTK-vtk-module-find-packages.cmake:356 (find_package)
  /opt/local/lib/cmake/vtk-9.5/vtk-config.cmake:170 (include)
  CMakeLists.txt:661 (find_package)

VTK was built successfully with the following. LibPROJ_ROOT is a custom location for PROJ object and config files:

VTK_MODULE_USE_EXTERNAL_VTK_libproj:BOOL=ON
LibPROJ_ROOT=/opt/local/lib/proj9

So I would expect that this VTK build would remember where to find LibPROJ directories, but apparently it does not. Which VTK installed file should contain this embedded information? What is missing from this VTK build?

Looks like a bug indeed. VTK should be forwarding these CMake configuration in the vtk-config.cmake.

@ben.boeckel what do you think ?

This might be a false alarm, because I think that GDCM configure should never be calling FindLibPROJ in the first place. It looks like GDCM configure is invoking parts of VTK CMake configure for no reason that I can understand.

The correct place for PROJ linkage should be embedded in the VTK binary library file, not in any CMake files produced by the VTK build. This is proper encapsulation. I might be wrong, I am very unfamiliar with CMake details.

So the short answer is, don’t spend your time looking for this ghost, unless I come up with something more specific. I need to take a closer look at the GDCM build system.

The proj error occurs because of the way that GDCM requests VTK:

find_package(VTK REQUIRED)

This is, essentially, requesting every component that VTK was configured for, regardless of which VTK components GDCM actually needs. GDCM does not need the vtk libraries that use proj.

GDCM could instead request only the VTK components that it needs:

find_package(VTK COMPONENTS CommonCore ImagingCore IOImage ...)

Also note that building GDCM with GDCM_USE_VTK can have a knock-on effect in this regard. If other packages do find_package(GDCM REQUIRED) then cmake automatically looks for all GDCM components, including vtkgdcm, even if the user only wants the basic GDCM libraries.


TLDR: the best way to ensure that cmake plays nice in any package-management system is for all packages to use find_package(X COMPONENTS ...) for any multi-component dependencies. But this is a bit of a battle, since each package has its own project management team.

@dgobbi That is great information. I will tinker with the GDCM build, see what I can do.

My other circumstantial evidence is that the CMake build for OpenEMS is apparently configured correctly for successful build with VTK, without hitting this LibPROJ error.

I find that simply find_package(VTK) allows the GDCM build to proceed, although Could NOT find LibPROJ is still issued as a warning. This may be an acceptable workaround, because GDCM component configuration is not trivial.

Back to my original question. When a custom location is used for LibPROJ_ROOT, where in the VTK build should the custom location be embedded? Somewhere besides the library object file, so that CMake can find it? Am I specifying this incorrectly in my CMake setup for the VTK build?