diff options
| author | Alexandru Croitor <alexandru.croitor@qt.io> | 2025-09-19 15:02:25 +0200 |
|---|---|---|
| committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2025-09-22 15:06:11 +0200 |
| commit | 897034bc9361ae776de9dfb615af24daffaf3778 (patch) | |
| tree | 2695f8554b3a87b5d4360723aa6f07ef079e73ea /src/gui/util/qundostack.cpp | |
| parent | 2b19a22a4ff2d7a00222ea63b2b84cfdbb202003 (diff) | |
CMake: Handle TARGET_SUPPORTS_SHARED_LIBS for Emscripten better
The upstream emsdk / emscripten cmake toolchain file sets the
CMake global property TARGET_SUPPORTS_SHARED_LIBS to FALSE, claiming
that creation of true shared libraries is not supported. See the
following comment:
https://github.com/emscripten-core/emscripten/pull/8362#issuecomment-3050586255
Despite that, Qt for a while now set the global property to TRUE
both when building Qt and user projects, and things mostly worked.
This was done in QtWasmHelpers.cmake for shared lib Qt builds. And in
Qt6CoreConfigExtras.cmake.in for user projects in both shared or
static qt builds (which actually affects repos other than qtbase as
well).
Starting with CMake 3.30, which introduced policy CMP0164, if it's set
to NEW, and TARGET_SUPPORTS_SHARED_LIBS is FALSE, CMake will refuse to
create shared library targets (even IMPORTED ones) with an error like:
CMake Error at lib/cmake/Qt6Core/Qt6CoreTargets.cmake:50 (add_library):
ADD_LIBRARY called with SHARED option but the target platform does
not support dynamic linking.
Call Stack (most recent call first):
lib/cmake/Qt6Core/Qt6CoreConfig.cmake:57 (include)
lib/cmake/Qt6/Qt6Config.cmake:240 (find_package)
CMakeLists.txt:7 (find_package)
This usually popped up when configuring a user project or a qt repo
other than qtbase, when Qt is built with CMake 3.30. That's because
the auto-generated *Targets.cmake always enables all policies up to
the version of the used CMake version, with a command like
cmake_policy(VERSION 2.8.3...3.31)
The Qt6CoreConfigExtras.cmake file is included after the Targets file,
so its setting of TARGET_SUPPORTS_SHARED_LIBS to TRUE is too late.
To avoid this error, introduce a new
_qt_internal_handle_target_supports_shared_libs helper function
that sets TARGET_SUPPORTS_SHARED_LIBS to TRUE in
Qt6ConfigExtras.cmake. This will be executed before any imported
target creation in Qt*Targets.cmake files.
Because Qt6ConfigExtras.cmake is not loaded during the initial
configuration of the qtbase build, also replace the call in
QtWasmHelpers.cmake. Make it consistent and call the function
regardless of a shared or static Qt build.
Allow opting out of the TARGET_SUPPORTS_SHARED_LIBS assignment by
passing -DQT_NO_ENABLE_TARGET_SUPPORTS_SHARED_LIBS=ON.
Incidentally, CMake 4.2 is introducing it's own support for
Emscripten, and will set TARGET_SUPPORTS_SHARED_LIBS to TRUE if it
detects that the emsdk toolchain file is not loaded.
Pick-to: 6.8 6.9 6.10
Task-number: QTBUG-140211
Change-Id: I9313476abd885bcbe60309e62fe1d6ae568769e8
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src/gui/util/qundostack.cpp')
0 files changed, 0 insertions, 0 deletions
