diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-07-30 11:15:32 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-07-30 13:26:25 +0000 |
commit | 5528bcf99c79d7a2658b3444205e003fb36f1283 (patch) | |
tree | 5707dc01e77ddb41ecae4d40b87da8a92ede6af2 | |
parent | a285bcba26498f3a03da3891a253213e05dba621 (diff) |
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 <simon.hausmann@qt.io>
-rw-r--r-- | cmake/QtBuild.cmake | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index e00da0f17c..e51013a325 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 <private/qtrace_p.h>") 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: |