From 5528bcf99c79d7a2658b3444205e003fb36f1283 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Tue, 30 Jul 2019 11:15:32 +0200 Subject: [PATCH] Protect against extending imported host targets When cross-compiling qtdeclarative, add_qt_tools makes sure to import the host tool and not build it. But there are also some extend_target and add_qt_resource calls which try to extend the host tool. Make sure to protect those functions not to do anything if they are called on an imported target. Change-Id: Ifd8bcab8e56ad389a8c145382b23bd2c1bda5e81 Reviewed-by: Simon Hausmann --- cmake/QtBuild.cmake | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index e00da0f17c5..e51013a325b 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -350,6 +350,17 @@ function(qt_set_up_nonprefix_build) endif() endfunction() +function(qt_is_imported_target target out_var) + if(NOT TARGET "${target}") + set(target "${QT_CMAKE_EXPORT_NAMESPACE}::${target}") + endif() + if(NOT TARGET "${target}") + message(FATAL_ERROR "Invalid target given to qt_is_imported_target: ${target}") + endif() + get_target_property(is_imported "${target}" IMPORTED) + set(${out_var} "${is_imported}" PARENT_SCOPE) +endfunction() + # Generates module .pri files for consumption by qmake function(qt_generate_module_pri_file target target_path pri_files_var) set(flags INTERNAL_MODULE) @@ -854,6 +865,12 @@ endfunction() # This function can be used to add sources/libraries/etc. to the specified CMake target # if the provided CONDITION evaluates to true. function(extend_target target) + # Don't try to extend_target when cross compiling an imported host target (like a tool). + qt_is_imported_target("${target}" is_imported) + if(is_imported) + return() + endif() + if (NOT TARGET "${target}") message(FATAL_ERROR "Trying to extend non-existing target \"${target}\".") endif() @@ -2322,9 +2339,14 @@ function(qt_create_tracepoints name tracePointsFile) "#include ") endfunction() - - function(add_qt_resource target resourceName) + # Don't try to add resources when cross compiling, and the target is actually a host target + # (like a tool). + qt_is_imported_target("${target}" is_imported) + if(is_imported) + return() + endif() + qt_parse_all_arguments(rcc "add_qt_resource" "" "PREFIX;LANG;BASE" "FILES" ${ARGN}) # Generate .qrc file: