[Interest] Require a qt_finalize_target() call in CMake user projects that use a static Qt

Alexandru Croitor alexandru.croitor at qt.io
Wed May 5 12:24:33 CEST 2021


Project developers that use CMake and a static Qt 5 build probably know that the developer experience(DX) wasn't the best (depending on which Qt modules or plugins the project uses).

When we switched building Qt 6 to CMake, we hoped we could provide a nicer CMake project DX which involves static Qt builds. Everything just works™.

Unfortunately along the way we've been hitting limitations in CMake, which stopped us from providing the DX we want to offer.

If you search the bug tracker, you can see we've had a constant stream of issues: incorrect link line order causing failed linkage, missing plugins, discarded symbols from resource objects files, etc

We've been trying various workarounds to address these issues, but they either ended up being unreliable or just not fixing them.

We have an idea on how to address the issues properly, but we'd have to enforce user projects to call a qt provided function for each executable or library that uses a static Qt library.

The project would have to do

    add_library / add_executable(A)
    # .....
    # at the end of the project

Or if the project uses our qt provided wrappers for libraries and executables and a CMake version >= 3.19, it can just do

    qt_add_library(A) / qt_add_executable(A)

The project can use the wrappers with a lower CMake version as well, but it'd still have to call qt_finalize_target() at the end of the project then

    qt_add_library(A) / qt_add_executable(A)
    # ...
    # at the end of the project

This of course requires developers to adapt their projects (adding the qt_finalize_target calls, or switching to a new CMake version and use the Qt wrappers).

I think providing a DX where the developer doesn't have to worry about static library dependencies is worth the trade-off of having to adapt the not so many Qt 6 projects in the wild.

To reiterate, this requirement would only be for projects that use a static Qt. Projects that use a shared Qt build don't require the new functions.

I'd like to hear your thoughts on this.

More information about the Interest mailing list