diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2020-10-15 17:04:27 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2020-10-17 12:13:00 +0200 |
commit | b5af1408099dedd132f36e04d19cb5771a23ec28 (patch) | |
tree | 85109c13469dcde91aea87e29ed52c116732fbf8 | |
parent | 8ec4fd9cffe7977f6d7cb68ce38de4386a5795d6 (diff) |
Generalize the winmain/qtmain entry-point library
The use-case is relevant for other platforms as well.
Now that Qt has a module system we can also replace a lot of the
hand crafted logic for linking with simpler constructs.
Change-Id: Ib6853aaf81bfea79c31f2de741d65b4b56f23ef6
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rw-r--r-- | cmake/QtFindPackageHelpers.cmake | 6 | ||||
-rw-r--r-- | cmake/QtStartupHelpers.cmake | 6 | ||||
-rw-r--r-- | mkspecs/common/g++-win32.conf | 1 | ||||
-rw-r--r-- | mkspecs/common/msvc-desktop.conf | 1 | ||||
-rw-r--r-- | mkspecs/features/entrypoint.prf | 2 | ||||
-rw-r--r-- | mkspecs/features/win32/default_pre.prf | 2 | ||||
-rw-r--r-- | mkspecs/features/win32/idcidl.prf | 3 | ||||
-rw-r--r-- | mkspecs/features/win32/windows.prf | 11 | ||||
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/corelib/Qt6CoreMacros.cmake | 4 | ||||
-rw-r--r-- | src/corelib/doc/src/qtcore-index.qdoc | 2 | ||||
-rw-r--r-- | src/entrypoint/CMakeLists.txt (renamed from src/winmain/CMakeLists.txt) | 10 | ||||
-rw-r--r-- | src/entrypoint/entrypoint.pro | 30 | ||||
-rw-r--r-- | src/entrypoint/qtentrypoint_win.cpp (renamed from src/winmain/qtmain_win.cpp) | 4 | ||||
-rw-r--r-- | src/src.pro | 10 | ||||
-rw-r--r-- | src/winmain/winmain.pro | 31 |
16 files changed, 56 insertions, 69 deletions
diff --git a/cmake/QtFindPackageHelpers.cmake b/cmake/QtFindPackageHelpers.cmake index d2bacd48cc..9e2c749abc 100644 --- a/cmake/QtFindPackageHelpers.cmake +++ b/cmake/QtFindPackageHelpers.cmake @@ -195,14 +195,14 @@ endfunction() # This function records a dependency between ${main_target_name} and ${dep_target_name} # at the CMake package level. -# E.g. Qt6CoreConfig.cmake needs to find_package(Qt6WinMain). +# E.g. Qt6CoreConfig.cmake needs to find_package(Qt6EntryPoint). # main_target_name = Core -# dep_target_name = WinMain +# dep_target_name = EntryPoint # This is just a convenience function that deals with Qt targets and their associated packages # instead of raw package names. function(qt_record_extra_qt_package_dependency main_target_name dep_target_name dep_package_version) - # WinMain -> Qt6WinMain. + # EntryPoint -> Qt6EntryPoint. qt_internal_module_info(qtfied_target_name "${dep_target_name}") qt_record_extra_package_dependency("${main_target_name}" "${qtfied_target_name_versioned}" "${dep_package_version}") diff --git a/cmake/QtStartupHelpers.cmake b/cmake/QtStartupHelpers.cmake index 0e7288e9cf..0ec431cbf4 100644 --- a/cmake/QtStartupHelpers.cmake +++ b/cmake/QtStartupHelpers.cmake @@ -8,9 +8,9 @@ function(qt_internal_setup_startup_target) set(dependent_target "Core") - # On windows, find_package(Qt6Core) should call find_package(Qt6WinMain) so that Startup can - # link against WinMain. + # On windows, find_package(Qt6Core) should call find_package(Qt6EntryPoint) so that Startup can + # link against EntryPoint. if(WIN32) - qt_record_extra_qt_package_dependency("${dependent_target}" WinMain "${PROJECT_VERSION}") + qt_record_extra_qt_package_dependency("${dependent_target}" EntryPoint "${PROJECT_VERSION}") endif() endfunction() diff --git a/mkspecs/common/g++-win32.conf b/mkspecs/common/g++-win32.conf index a1e08ed63b..67ad1e3b8c 100644 --- a/mkspecs/common/g++-win32.conf +++ b/mkspecs/common/g++-win32.conf @@ -63,7 +63,6 @@ QMAKE_LIBS_OPENGL = -lglu32 -lopengl32 -lgdi32 -luser32 QMAKE_LIBS_OPENGL_ES2 = -lgdi32 -luser32 QMAKE_LIBS_OPENGL_ES2_DEBUG = -lgdi32 -luser32 QMAKE_LIBS_COMPAT = -ladvapi32 -lshell32 -lcomdlg32 -luser32 -lgdi32 -lws2_32 -QMAKE_LIBS_QT_ENTRY = -lmingw32 -lqtmain QMAKE_IDL = midl QMAKE_LIB = $${CROSS_COMPILE}ar -rc diff --git a/mkspecs/common/msvc-desktop.conf b/mkspecs/common/msvc-desktop.conf index a5993287ed..33b4dc70c6 100644 --- a/mkspecs/common/msvc-desktop.conf +++ b/mkspecs/common/msvc-desktop.conf @@ -105,7 +105,6 @@ QMAKE_LIBS_OPENGL = glu32.lib opengl32.lib gdi32.lib user32.lib QMAKE_LIBS_OPENGL_ES2 = gdi32.lib user32.lib QMAKE_LIBS_OPENGL_ES2_DEBUG = gdi32.lib user32.lib QMAKE_LIBS_COMPAT = advapi32.lib shell32.lib comdlg32.lib user32.lib gdi32.lib ws2_32.lib -QMAKE_LIBS_QT_ENTRY = -lqtmain QMAKE_IDL = midl QMAKE_LIB = lib /NOLOGO diff --git a/mkspecs/features/entrypoint.prf b/mkspecs/features/entrypoint.prf new file mode 100644 index 0000000000..8442f8930b --- /dev/null +++ b/mkspecs/features/entrypoint.prf @@ -0,0 +1,2 @@ +qt:!console:contains(TEMPLATE, ".*app"): \ + QT_PRIVATE += entrypoint diff --git a/mkspecs/features/win32/default_pre.prf b/mkspecs/features/win32/default_pre.prf index 4bd1653aee..be8e20130f 100644 --- a/mkspecs/features/win32/default_pre.prf +++ b/mkspecs/features/win32/default_pre.prf @@ -1,2 +1,2 @@ -CONFIG = windows $$CONFIG +CONFIG = windows $$CONFIG entrypoint load(default_pre) diff --git a/mkspecs/features/win32/idcidl.prf b/mkspecs/features/win32/idcidl.prf index 922ae3f99e..67d3cf0cb0 100644 --- a/mkspecs/features/win32/idcidl.prf +++ b/mkspecs/features/win32/idcidl.prf @@ -3,8 +3,7 @@ build_pass:console { warning("Remove 'console' from your CONFIG.") } -# Do not link qtmain.lib -QMAKE_LIBS_QT_ENTRY = +CONFIG -= entrypoint ACTIVEQT_VERSION = $$VERSION isEmpty(ACTIVEQT_VERSION):ACTIVEQT_VERSION = 1.0 diff --git a/mkspecs/features/win32/windows.prf b/mkspecs/features/win32/windows.prf index 272170d428..66ef21f2de 100644 --- a/mkspecs/features/win32/windows.prf +++ b/mkspecs/features/win32/windows.prf @@ -2,15 +2,4 @@ CONFIG -= console QMAKE_LFLAGS += $$QMAKE_LFLAGS_WINDOWS contains(TEMPLATE, ".*app") { QMAKE_LFLAGS += $$QMAKE_LFLAGS_EXE - mingw:DEFINES += QT_NEEDS_QMAIN - - qt:for(entryLib, $$list($$unique(QMAKE_LIBS_QT_ENTRY))) { - isEqual(entryLib, -lqtmain) { - lib = $$QT.core.libs/$${QMAKE_PREFIX_STATICLIB}qtmain$$QT_LIBINFIX$$qtPlatformTargetSuffix().$$QMAKE_EXTENSION_STATICLIB - PRE_TARGETDEPS += $$lib - QMAKE_LIBS += $$lib - } else { - QMAKE_LIBS += $${entryLib} - } - } } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 78ee63baae..aa4b1b06c4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -70,6 +70,6 @@ if(QT_FEATURE_gui AND QT_FEATURE_widgets) endif() add_subdirectory(plugins) -add_subdirectory(winmain) +add_subdirectory(entrypoint) add_subdirectory(android) diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index 4a60d61eea..26ab044856 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -1370,7 +1370,7 @@ function(_qt_internal_setup_startup_target) set_target_properties("${target}" PROPERTIES "${initialized_prop}" TRUE) endif() - # On Windows this enables automatic linkage to WinMain. + # On Windows this enables automatic linkage to QtEntryPoint. # On iOS this enables automatic passing of a linker flag that will change the default # entry point of the linked executable. set(isExe "$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>") @@ -1378,7 +1378,7 @@ function(_qt_internal_setup_startup_target) if(WIN32) set(isWin32 "$<BOOL:$<TARGET_PROPERTY:WIN32_EXECUTABLE>>") set(isPolicyNEW "$<TARGET_POLICY:CMP0020>") - set(finalGenex "$<$<AND:${isExe},${isWin32},${isNotExcluded},${isPolicyNEW}>:Qt::WinMain>") + set(finalGenex "$<$<AND:${isExe},${isWin32},${isNotExcluded},${isPolicyNEW}>:Qt::EntryPoint>") # Use set_target_properties instead of target_link_libraries because the latter has some # weird additional behavior of checking which project the target belongs to, and might diff --git a/src/corelib/doc/src/qtcore-index.qdoc b/src/corelib/doc/src/qtcore-index.qdoc index f904cd774f..5309eb14da 100644 --- a/src/corelib/doc/src/qtcore-index.qdoc +++ b/src/corelib/doc/src/qtcore-index.qdoc @@ -116,7 +116,7 @@ See \l{Qt Licensing} for further details. Executables on Windows potentially link - against \l{The qtmain Library}. This library is available + against \l{The QtEntryPoint Library}. This library is available under commercial licenses and also under the \l{BSD 3-clause "New" or "Revised" License}. diff --git a/src/winmain/CMakeLists.txt b/src/entrypoint/CMakeLists.txt index 3f3e6f0f1c..16c01540dd 100644 --- a/src/winmain/CMakeLists.txt +++ b/src/entrypoint/CMakeLists.txt @@ -4,7 +4,7 @@ if (NOT WIN32) return() endif() -qt_internal_add_module(WinMain +qt_internal_add_module(EntryPoint STATIC NO_SYNC_QT NO_MODULE_HEADERS @@ -22,14 +22,12 @@ if (MSVC) IN_CURRENT_SCOPE) endif() -set_property(TARGET WinMain PROPERTY OUTPUT_NAME qtmain) - -qt_internal_extend_target(WinMain CONDITION - SOURCES qtmain_win.cpp +qt_internal_extend_target(EntryPoint CONDITION WIN32 + SOURCES qtentrypoint_win.cpp LIBRARIES shell32 ) -qt_internal_extend_target(WinMain CONDITION MINGW +qt_internal_extend_target(EntryPoint CONDITION MINGW DEFINES QT_NEEDS_QMAIN ) # special case end diff --git a/src/entrypoint/entrypoint.pro b/src/entrypoint/entrypoint.pro new file mode 100644 index 0000000000..dd0618cd56 --- /dev/null +++ b/src/entrypoint/entrypoint.pro @@ -0,0 +1,30 @@ +# Additional Qt project file for QtEntryPoint lib +!win32:error("$$_FILE_ is intended only for Windows!") + +TARGET = QtEntryPoint + +CONFIG += static no_module_headers +QT = core + +DEFINES += QT_NO_FOREACH + +win32 { + SOURCES = qtentrypoint_win.cpp + CONFIG -= qt + + QMAKE_USE_PRIVATE += shell32 + + msvc { + QMAKE_CFLAGS_DEBUG -= -Zi + QMAKE_CXXFLAGS_DEBUG -= -Zi + QMAKE_CFLAGS_DEBUG *= -Z7 + QMAKE_CXXFLAGS_DEBUG *= -Z7 + } + mingw { + DEFINES += QT_NEEDS_QMAIN + MODULE_DEFINES += QT_NEEDS_QMAIN + LIBS += -lmingw32 + } +} + +load(qt_module) diff --git a/src/winmain/qtmain_win.cpp b/src/entrypoint/qtentrypoint_win.cpp index 5520a447a9..200eb5379d 100644 --- a/src/winmain/qtmain_win.cpp +++ b/src/entrypoint/qtentrypoint_win.cpp @@ -52,8 +52,8 @@ #include <shellapi.h> /* - This file contains the code in the qtmain library for Windows. - qtmain contains the Windows startup code and is required for + This file contains the code in the QtEntryPoint library for Windows. + QtEntryPoint contains the Windows startup code and is required for linking to the Qt DLL. When a Windows application starts, the WinMain function is diff --git a/src/src.pro b/src/src.pro index 91cd6d4558..34fbd9d0f3 100644 --- a/src/src.pro +++ b/src/src.pro @@ -64,9 +64,9 @@ src_tools_qvkgen.target = sub-qvkgen force_bootstrap: src_tools_qvkgen.depends = src_tools_bootstrap else: src_tools_qvkgen.depends = src_corelib -src_winmain.subdir = $$PWD/winmain -src_winmain.target = sub-winmain -src_winmain.depends = sub-corelib # just for the module .pri file +src_entrypoint.subdir = $$PWD/entrypoint +src_entrypoint.target = sub-entrypoint +src_entrypoint.depends = sub-corelib # just for the module .pri file src_corelib.subdir = $$PWD/corelib src_corelib.target = sub-corelib @@ -157,7 +157,9 @@ qtConfig(regularexpression):!qtConfig(system-pcre2):pcre2 { } TOOLS = src_tools_moc src_tools_rcc src_tools_tracegen src_tools_qlalr SUBDIRS += src_corelib src_tools_qlalr -win32:SUBDIRS += src_winmain + +win32:SUBDIRS += src_entrypoint + qtConfig(network) { SUBDIRS += src_network src_plugins.depends += src_network diff --git a/src/winmain/winmain.pro b/src/winmain/winmain.pro deleted file mode 100644 index 19ce9ffa82..0000000000 --- a/src/winmain/winmain.pro +++ /dev/null @@ -1,31 +0,0 @@ -# Additional Qt project file for qtmain lib on Windows -!win32:error("$$_FILE_ is intended only for Windows!") - -TEMPLATE = lib -TARGET = qtmain -DESTDIR = $$QT.core.libs - -CONFIG += static -QT = core - -DEFINES += QT_NO_FOREACH - -qtConfig(debug_and_release): CONFIG += build_all - -msvc: QMAKE_CFLAGS_DEBUG -= -Zi -msvc: QMAKE_CXXFLAGS_DEBUG -= -Zi -msvc: QMAKE_CFLAGS_DEBUG *= -Z7 -msvc: QMAKE_CXXFLAGS_DEBUG *= -Z7 -mingw: DEFINES += QT_NEEDS_QMAIN - -CONFIG -= qt -SOURCES = qtmain_win.cpp -QMAKE_USE_PRIVATE += shell32 - -load(qt_installs) - -TARGET = $$qtLibraryTarget($$TARGET$$QT_LIBINFIX) #do this towards the end - -load(qt_targets) -load(qt_build_paths) -load(qt_common) |