Fix add_qt_resource to handle resources in static builds properly

Whenever the qml compiler is used to process qml files from a
resource, and there are no resources left after all qml files have
been processed, make sure to propagate the created resource target
to add_qt_resource, so that the target is associated properly with
an export name.

Additionally the generated qml cache loader file uses private Qml
headers. Thus the object library that contains the cpp file should
have qml as a dependency (and not the target that will link to the
object library).

Change-Id: Ib385a900823df3e015492cdd06acd8a0cb9f8e9a
Reviewed-by: Leander Beernaert <leander.beernaert@qt.io>
Reviewed-by: Qt CMake Build Bot
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
Alexandru Croitor 2019-08-30 15:06:34 +02:00
parent 2e3e42587b
commit 659d8cf3e5

View File

@ -30,7 +30,7 @@ endfunction()
# Inspect all files passed to a call to add_qt_resource. If there are any
# files present, invoke the quick compiler and return the remaining resource
# files that have not been prossed in REMAING_RESOURCES as well as the new
# files that have not been processed in OUTPUT_REMAINING_RESOURCES as well as the new
# name for the resource in OUTPUT_RESOURCE_NAME.
function(__qt_quick_compiler_process_resources target resource_name)
@ -150,7 +150,16 @@ function(__qt_quick_compiler_process_resources target resource_name)
if (resource_files)
set(resource_name ${chained_resource_name})
endif()
target_link_libraries(${target} PRIVATE @QT_CMAKE_EXPORT_NAMESPACE@::Qml)
# The generated qmlcache_loader source file uses private headers of Qml, so make sure
# if the object library was created, it depends on the Qml target. If there's no target,
# that means the target is a shared library and the sources are directly added to the target
# via target_sources, so add dependency in that case as well.
set(chosen_target "target") # shared library case
if(output_target)
set(chosen_target "output_target") # static library case.
endif()
target_link_libraries(${${chosen_target}} PRIVATE @QT_CMAKE_EXPORT_NAMESPACE@::Qml)
else()
set(resource_files ${arg_FILES})
endif()
@ -216,6 +225,9 @@ function(QT@PROJECT_VERSION_MAJOR@_PROCESS_RESOURCE target resourceName)
)
if (NOT resources)
if (rcc_OUTPUT_TARGET)
set(${rcc_OUTPUT_TARGET} "${output_target}" PARENT_SCOPE)
endif()
return()
endif()
set(generatedResourceFile "${CMAKE_CURRENT_BINARY_DIR}/generated_${newResourceName}.qrc")