VTK not finding FontConfig during application CMake configuration on Windows

Hi folks,

On one of our Windows build workers we have a FontConfig installation as follows:

C:\Users\Elvis\Dev\libfontconfig_2.13.1-4_msvc16\include\fontconfig\fontconfig.h
C:\Users\Elvis\Dev\libfontconfig_2.13.1-4_msvc16\bin\x64\fontconfig.dll

I’m in the process of porting our application from VTK 8 to 9.

During building of VTK itself, this installation is found fine, and the vtkRenderingFreeTypeFontConfig module which we want is built and linked against this FontConfig installation (confirmed with depends.exe on vtkRenderingFreeTypeFontConfig-9.2.dll).

However, during the CMake configuration of our own application, we’re now getting:

.
.
.
-- Found OpenGL: opengl32  found components: OpenGL 
-- Configuring incomplete, errors occurred!
See also "C:/Users/Elvis/Dev/buildbot_worker/b-insight-win/build/build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/Elvis/Dev/buildbot_worker/b-insight-win/build/build/CMakeFiles/CMakeError.log".
CMake Error at C:/Program Files/CMake/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:164 (message):
  Could NOT find FontConfig (missing: FONTCONFIG_LIBRARY
  FONTCONFIG_INCLUDE_DIR)
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:445 (_FPHSA_FAILURE_MESSAGE)
  C:/Users/Elvis/Dev/VTK-9.2.6-inst/lib/cmake/vtk-9.2/FindFontConfig.cmake:28 (find_package_handle_standard_args)
  C:/Users/Elvis/Dev/VTK-9.2.6-inst/lib/cmake/vtk-9.2/VTK-vtk-module-find-packages.cmake:303 (find_package)
  C:/Users/Elvis/Dev/VTK-9.2.6-inst/lib/cmake/vtk-9.2/vtk-config.cmake:152 (include)
  CMakeLists.txt:36 (find_package)

This used to work fine with VTK 8. I don’t believe VTK would try to find FontConfig during configuration of the application back in VTK 8 times - I can’t see how it could have, because we were not passing any special CMake or environment variables, so it wouldn’t know that FontConfig is under C:\Users\Elvis\Dev\libfontconfig_2.13.1-4_msvc16.

So there seems to possibly be some difference with the introduction of the new module system, and VTK is now looking for FontConfig even during configuration of a VTK-using application?

I looked at VTK’s CMake/FindFontConfig.cmake, and it’s doing (excerpt):

find_path(FONTCONFIG_INCLUDE_DIR fontconfig/fontconfig.h)

find_library(FONTCONFIG_LIBRARY NAMES fontconfig)

# handle the QUIETLY and REQUIRED arguments and set FONTCONFIG_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(FontConfig DEFAULT_MSG
  FONTCONFIG_LIBRARY  FONTCONFIG_INCLUDE_DIR)

So following CMake docs for find_path and find_library, I tried prepending C:\Users\Elvis\Dev\libfontconfig_2.13.1-4_msvc16\bin\x64 to the PATH environment variable and passing -DCMAKE_INCLUDE_PATH=C:/Users/Elvis/Dev/libfontconfig_2.13.1-4_msvc16, but the error is the same.

@ben.boeckel Do you have some idea what might be going on?

Answering myself here since I had both misunderstood the CMake docs with regard to how find_file searches, and missed that the fontconfig installation had a lib/x64 which contained the .lib file.

The correct way which works is:

    -DCMAKE_INCLUDE_PATH=C:/Users/Elvis/Dev/libfontconfig_2.13.1-4_msvc16/include
    -DCMAKE_LIBRARY_PATH=C:/Users/Elvis/Dev/libfontconfig_2.13.1-4_msvc16/lib/x64
1 Like

Still a bit curious what changed in VTK 9 so that we now have to pass these in.

Yes. VTK 9 uses imported targets for everything. While Fontconfig::Fontconfig is indeed linked PRIVATE, this is still needed in a static build (because it need to be linked into whatever executable ends up using VTK::RenderingFreeTypeFontConfig). I suppose I could add a PRIVATE_IF_SHARED argument to vtk_module_find_package to not export this need for shared builds.

You can use -DVTK_RELOCATABLE_INSTALL=OFF to have VTK export the variables it used for finding third party packages to its CMake configuration (see vtk-find-package-helpers.cmake).

FWIW, VTK 8 did not need to do this because it baked the build-time path into the list of required libraries at install time (as needed; CMake did the export of this information automatically). This means that consumers of VTK needed to have Fontconfig in the same location as when VTK built (this is a “non-relocatable” installation and why that flag does what it does).

1 Like

https://gitlab.kitware.com/vtk/vtk/-/merge_requests/10393

2 Likes