Skip to content

Commit

Permalink
Allow adding linker flags to qmake module pris
Browse files Browse the repository at this point in the history
The flags go before the library in the final linker line, as opposed
to the dependencies declared in LIBS.

This allows us to declare the flags for the entrypoint
in the project file of the entrypoint, instead of in
a standalone prf.

Change-Id: I35c054fe9fdaa6add7cd0e8ba3f7304f975ff80f
Reviewed-by: Joerg Bornemann <[email protected]>
Reviewed-by: Alexandru Croitor <[email protected]>
  • Loading branch information
torarnv committed Nov 2, 2020
1 parent 2096463 commit 6032a9c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
5 changes: 4 additions & 1 deletion cmake/QtPriHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,11 @@ function(qt_generate_module_pri_file target)
"${property_prefix}QT_MODULE_USES")
get_target_property(module_pri_extra_content "${target}"
"${property_prefix}QT_MODULE_PRI_EXTRA_CONTENT")
get_target_property(module_ldflags "${target}"
"${property_prefix}QT_MODULE_LDFLAGS")

foreach(var enabled_features disabled_features enabled_private_features disabled_private_features
module_internal_config module_uses module_pri_extra_content)
module_internal_config module_uses module_pri_extra_content module_ldflags)
if(${var} STREQUAL "${var}-NOTFOUND")
set(${var} "")
else()
Expand Down Expand Up @@ -265,6 +267,7 @@ function(qt_generate_module_pri_file target)
QT.${config_module_name}.name = ${module}
QT.${config_module_name}.module = ${module_name_in_pri}${QT_LIBINFIX}
QT.${config_module_name}.libs = $$QT_MODULE_LIB_BASE
QT.${config_module_name}.ldflags = ${module_ldflags}
QT.${config_module_name}.includes = ${public_module_includes}
QT.${config_module_name}.frameworks = ${public_module_frameworks}
QT.${config_module_name}.bins = $$QT_MODULE_BIN_BASE${module_plugin_types_assignment}
Expand Down
11 changes: 1 addition & 10 deletions mkspecs/features/entrypoint.prf
Original file line number Diff line number Diff line change
@@ -1,11 +1,2 @@
qt:!console:contains(TEMPLATE, ".*app") {
# This library needs to come before the entry-point library in the
# linker line, so that the static linker will pick up the WinMain
# symbol from the entry-point library. Unfortunately qmake and the
# module system doesn't allow specifying linker flags or dependencies
# as part of the module that end up _before_ the library itself, so
# we have to work around it by declaring the dependency here.
mingw: LIBS += -lmingw32

qt:!console:contains(TEMPLATE, ".*app"): \
QT_PRIVATE += entrypoint_private
}
4 changes: 4 additions & 0 deletions mkspecs/features/qt.prf
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ for(ever) {
MODULE_NAME = $$eval(QT.$${QTLIB}.name)
MODULE_MODULE = $$eval(QT.$${QTLIB}.module)
MODULE_INCLUDES = $$eval(QT.$${QTLIB}.includes)
MODULE_LDFLAGS = $$eval(QT.$${QTLIB}.ldflags)
MODULE_LIBS = $$eval(QT.$${QTLIB}.libs)
MODULE_FRAMEWORKS = $$eval(QT.$${QTLIB}.frameworks)
MODULE_USES = $$eval(QT.$${QTLIB}.uses)
Expand All @@ -200,6 +201,9 @@ for(ever) {

MODULE_INCLUDES -= $$QMAKE_DEFAULT_INCDIRS

# Add linker flags before lib
LIBS$$var_sfx += $$MODULE_LDFLAGS

# Frameworks shouldn't need include paths, but much code does not use
# module-qualified #includes, so by default we add paths which point
# directly into the frameworks. Private modules have somewhat convoluted
Expand Down
1 change: 1 addition & 0 deletions mkspecs/features/qt_module_pris.prf
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ defineReplace(qtExportLibsForModule) {
"" \
"QT.$${MODULE_ID}.name = $$TARGET" \
"QT.$${MODULE_ID}.module = $$module_module" \
"QT.$${MODULE_ID}.ldflags = $$MODULE_LDFLAGS" \
"QT.$${MODULE_ID}.libs = $$module_libs" \
$$module_master \
"QT.$${MODULE_ID}.includes = $$MODULE_INCLUDES" \
Expand Down
11 changes: 9 additions & 2 deletions src/entrypoint/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ set_target_properties(EntryPoint PROPERTIES
INTERFACE_QT_MODULE_INTERNAL_CONFIG "staticlib"
)

set(module_pri_entrypoint_ldflags "")


# ---- While the static library target does the work ----
qt_internal_add_cmake_library(EntryPointImplementation STATIC
Expand Down Expand Up @@ -65,16 +67,21 @@ if(WIN32)
if(MINGW)
# The mingw32 library needs to come before the entry-point library in the
# linker line, so that the static linker will pick up the WinMain symbol
# from the entry-point library. The logic is duplicated in entrypoint.prf
# on the qmake side.
# from the entry-point library.
target_link_libraries(EntryPoint INTERFACE mingw32)
list(APPEND module_pri_entrypoint_ldflags "-lmingw32")

target_compile_definitions(EntryPoint INTERFACE QT_NEEDS_QMAIN)
qt_internal_extend_target(EntryPointImplementation DEFINES QT_NEEDS_QMAIN)
endif()
endif()

# ---- Finally, make sure the static library can be consumed by clients -----

set_target_properties(EntryPoint PROPERTIES
INTERFACE_QT_MODULE_LDFLAGS "${module_pri_entrypoint_ldflags}"
)

# Must be added last, so that any library dependencies added above will
# precede the entrypoint library at link time.
target_link_libraries(EntryPoint INTERFACE EntryPointImplementation)
Expand Down
5 changes: 5 additions & 0 deletions src/entrypoint/entrypoint.pro
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ win32 {
mingw {
DEFINES += QT_NEEDS_QMAIN
MODULE_DEFINES += QT_NEEDS_QMAIN

# This library needs to come before the entry-point library in the
# linker line, so that the static linker will pick up the WinMain
# symbol from the entry-point library.
MODULE_LDFLAGS += -lmingw32
}
}

Expand Down

0 comments on commit 6032a9c

Please sign in to comment.