summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2019-08-02 12:01:00 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2019-08-06 08:41:51 +0000
commite343affd6345ef8db041789a96016c3a84830dc9 (patch)
treedbc13cb7a5d10dd0413272bdad8740893ac715f8 /cmake
parent5d88ba001ed44e21ae3456de2ce4d00eaac31e0c (diff)
Propagate library/plugin resources automatically when linking statically
The rcc generated code relies on global constructors to register the resources. The object file of the generated code is included by default in shared libraries and executables. However when the object file ends up in a static library, the linker will discard the object file when nothing references any of the symbols in that object file, when linking the static library into the executable/shared library. The solution is to link the object file straight into the final target, by means of a cmake object library. Change-Id: I02ad1173e4f7e8f907022c906640dc9086233676 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/QtBuild.cmake15
1 files changed, 14 insertions, 1 deletions
diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake
index 3e2d406d9b..e893ac26ba 100644
--- a/cmake/QtBuild.cmake
+++ b/cmake/QtBuild.cmake
@@ -2570,7 +2570,20 @@ function(add_qt_resource target resourceName)
DEPENDS ${files}
COMMENT "RCC ${resourceName}"
VERBATIM)
- target_sources(${target} PRIVATE "${generatedSourceCode}")
+
+ get_target_property(type "${target}" TYPE)
+ if(type STREQUAL STATIC_LIBRARY)
+ set(resourceTarget "${target}_resources_${resourceName}")
+ add_library("${resourceTarget}" OBJECT "${generatedSourceCode}")
+ qt_internal_add_target_aliases("${resourceTarget}")
+ qt_install(TARGETS "${resourceTarget}"
+ EXPORT "${INSTALL_CMAKE_NAMESPACE}${target}Targets"
+ DESTINATION ${INSTALL_LIBDIR}
+ )
+ target_link_libraries(${target} INTERFACE "$<TARGET_OBJECTS:${INSTALL_CMAKE_NAMESPACE}::${resourceTarget}>")
+ else()
+ target_sources(${target} PRIVATE "${generatedSourceCode}")
+ endif()
endfunction()