mirror of https://github.com/qt/qtbase.git
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>
This commit is contained in:
parent
5d88ba001e
commit
e343affd63
|
@ -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()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue