CMake error with external freetype

I am trying to compile VTK using conan for installing the dependencies. However, the packages generated by conan already provide freetype, as its a dependency of Qt, and when I try to configure VTK, I get the following error:

[cmake] CMake Error at VTK/CMake/vtkModule.cmake:4139 (add_library):
[cmake]   add_library cannot create target "freetype" because an imported target with
[cmake]   the same name already exists.
[cmake] Call Stack (most recent call first):
[cmake]   VTK/ThirdParty/freetype/vtkfreetype/CMakeLists.txt:54 (vtk_module_add_module)

I have tried to set VTK_MODULE_USE_EXTERNAL_vtkfreetype and VTK_MODULE_USE_EXTERNAL_freetype to true, without success.

Is there anyway to compile VTK with external freetype?


If freetype is being build by Conan independently, then I believe you need to disable it in VTK configuration and add freetype as a required package in the VTK’s Conan recipe. If you enable it in VTK’s CMakeLists.txt, then freetype will be built again with likely adverse results.



I am not sure I understand. What do you mean with VTKs conan recipe? I havent found any recipe for VTK. What I did was to create a conanfile to specify VTK dependencies, mainly Qt6, and when I tried to use the Qt6Config package generated by Conan, that included freetype.

How can I disable freetype in VTK CMakeLists? I tried VTK_MODULE_USE_EXTERNAL_freetype/vtkfreetype, but none of them work. I could of course rework a lot of parts of VTKs CMakeLists to fetch an external freetype, but I was expecting some supported way of using an external freetype.

How do you use Conan to build VTK?

Actually I am building ParaView, so I created a conanfile to specify Qt as a dependency. Then I just run cmake normally, but specifying the conan_toolchain file produced by conan, which makes cmake use the FooConfig.cmake packages created by conan.

That brings freetype (Qt has a dependency on freetype), and VTK compilation fails because it sees there is already an external freetype and it can’t compile its own

Well, then you need to disable it when running CMake to configure VTK. You know you can pass CMake varibales via command line. E.g.: cmake ... -DVTK_MODULE_USE_EXTERNAL_vtkfreetype=true -D..., right?

Not sure if you read my question, but I clearly said I tried using that option without success…

This is because the target name for VTK::freetype is freetype internally. Fixing this issue would resolve it. I suppose it is higher priority now.