summaryrefslogtreecommitdiffstats
path: root/src/entrypoint/EntryPointMinGW32Target.cmake.in
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2021-10-28 12:19:15 +0200
committerJoerg Bornemann <joerg.bornemann@qt.io>2021-10-28 22:15:46 +0200
commit753199437943e2a89e458136fd11a5a43443b280 (patch)
tree53ded3aee4e97f84b4d50cf59c5784015964de9b /src/entrypoint/EntryPointMinGW32Target.cmake.in
parent825505c4398983deb279b9fc2655ab5b6d44fb9a (diff)
CMake: Fix undefined reference to WinMain errors with MinGW
When linking against Qt with MinGW, libmingw32.a must come before libQt6EntryPointImplementation.a on the linker command line. Otherwise the linker cannot find the WinMain symbol that's defined in the EntryPointImplementation library. Under certain circumstances, mingw32 was linked after EntryPointImplementation. To reliably ensure the order of said libraries, we introduce the imported library EntryPointMinGW32. This target represents libmingw32.a and links against EntryPointImplementation. The link dependencies look like this: EntryPointPrivate -> EntryPointMinGW32 -> EntryPointImplementation The imported library EntryPointMinGW32 is defined in a separate .cmake file which is included by both src/entrypoint/CMakeLists.txt and Qt6EntryPointConfig.cmake. This is needed, because the consumer outside of Qt must access this imported library, and we cannot export imported libraries. Pick-to: 6.2 Fixes: QTBUG-93671 Change-Id: Ib3c5e80cbcc9c793d000e5ad637325bcf735a1ec Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'src/entrypoint/EntryPointMinGW32Target.cmake.in')
-rw-r--r--src/entrypoint/EntryPointMinGW32Target.cmake.in7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/entrypoint/EntryPointMinGW32Target.cmake.in b/src/entrypoint/EntryPointMinGW32Target.cmake.in
new file mode 100644
index 0000000000..81ee970d6c
--- /dev/null
+++ b/src/entrypoint/EntryPointMinGW32Target.cmake.in
@@ -0,0 +1,7 @@
+# Add EntryPointMinGW32, an imported library that ensures that -lmingw32 comes before
+# EntryPointImplementation on the linker command line.
+include_guard()
+add_library(EntryPointMinGW32 INTERFACE IMPORTED)
+set_property(TARGET EntryPointMinGW32 PROPERTY IMPORTED_LIBNAME mingw32)
+target_link_libraries(EntryPointMinGW32
+ INTERFACE @INSTALL_CMAKE_NAMESPACE@::EntryPointImplementation)