Skip unnecessary commands when cross-building tools

Introduce a new macro qt_internal_return_unless_building_tools which
simply calls return() if tools are not built.  This macro is supposed to
be called after qt_internal_add_tool().

Using this macro avoids having to special-case code for when
qt_internal_add_tool() creates imported targets in cross-builds.

Adjust pro2cmake accordingly.

Task-number: QTBUG-85084
Change-Id: I9e1c455c29535dd8c318efa890ebd739c42effc1
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Joerg Bornemann 2021-09-14 21:02:14 +02:00
parent 326d94e94b
commit a0e56294c1
15 changed files with 24 additions and 0 deletions

View File

@ -441,6 +441,14 @@ function(qt_check_if_tools_will_be_built)
set(QT_WILL_BUILD_TOOLS ${will_build_tools} CACHE INTERNAL "Are tools going to be built" FORCE)
endfunction()
# Use this macro to exit a file or function scope unless we're building tools. This is supposed to
# be called after qt_internal_add_tools() to avoid special-casing operations on imported targets.
macro(qt_internal_return_unless_building_tools)
if(NOT QT_WILL_BUILD_TOOLS)
return()
endif()
endmacro()
# Equivalent of qmake's qtNomakeTools(directory1 directory2).
# If QT_BUILD_TOOLS_BY_DEFAULT is true, then targets within the given directories will be excluded
# from the default 'all' target, as well as from install phase. The private variable is checked by

View File

@ -97,6 +97,7 @@ qt_internal_add_tool(${target_name}
Qt::CorePrivate
QtLibraryInfo
)
qt_internal_return_unless_building_tools()
# Add QMAKE_VERSION_STR only if qmake is part of the build.
target_compile_definitions(QtLibraryInfo PUBLIC

View File

@ -19,6 +19,7 @@ qt_internal_add_tool(${target_name}
INCLUDE_DIRECTORIES
../shared
)
qt_internal_return_unless_building_tools()
set_target_properties(${target_name} PROPERTIES
WIN32_EXECUTABLE FALSE
)

View File

@ -17,6 +17,7 @@ qt_internal_add_tool(${target_name}
PUBLIC_LIBRARIES
Qt::Gui
)
qt_internal_return_unless_building_tools()
set_target_properties(${target_name} PROPERTIES
WIN32_EXECUTABLE FALSE
)

View File

@ -18,3 +18,4 @@ qt_internal_add_tool(${target_name}
INCLUDE_DIRECTORIES
${CMAKE_CURRENT_SOURCE_DIR}
)
qt_internal_return_unless_building_tools()

View File

@ -34,6 +34,7 @@ qt_internal_add_tool(${target_name}
../../3rdparty/tinycbor/src
../shared
)
qt_internal_return_unless_building_tools()
#### Keys ignored in scope 1:.:.:moc.pro:<TRUE>:
# QMAKE_TARGET_DESCRIPTION = "Qt Meta Object Compiler"

View File

@ -35,6 +35,7 @@ qt_internal_add_tool(${target_name}
# _LOADED = "qt_tool"
# _OPTION = "host_build"
)
qt_internal_return_unless_building_tools()
#### Keys ignored in scope 1:.:.:qdbuscpp2xml.pro:<TRUE>:
# QMAKE_TARGET_DESCRIPTION = "Qt D-Bus C++ to XML Compiler"

View File

@ -22,6 +22,7 @@ qt_internal_add_tool(${target_name}
# _LOADED = "qt_tool"
# _OPTION = "host_build"
)
qt_internal_return_unless_building_tools()
#### Keys ignored in scope 1:.:.:qdbusxml2cpp.pro:<TRUE>:
# QMAKE_TARGET_DESCRIPTION = "Qt D-Bus XML to C++ Compiler"

View File

@ -23,6 +23,7 @@ qt_internal_add_tool(${target_name}
PUBLIC_LIBRARIES
Qt::Core # special case
)
qt_internal_return_unless_building_tools()
#### Keys ignored in scope 1:.:.:qlalr.pro:<TRUE>:
# OTHER_FILES = "lalr.g"

View File

@ -15,6 +15,7 @@ qt_internal_add_tool(${target_name}
QT_NO_FOREACH
QTPATHS_VERSION_STR="2.0"
)
qt_internal_return_unless_building_tools()
## Scopes:
#####################################################################

View File

@ -14,6 +14,7 @@ qt_internal_add_tool(${target_name}
PUBLIC_LIBRARIES
Qt::Core # special case
)
qt_internal_return_unless_building_tools()
#### Keys ignored in scope 1:.:.:qvkgen.pro:<TRUE>:
# QMAKE_TARGET_DESCRIPTION = "Qt Vulkan Header Generator"

View File

@ -19,6 +19,7 @@ qt_internal_add_tool(${target_name}
INCLUDE_DIRECTORIES
${CMAKE_CURRENT_SOURCE_DIR}
)
qt_internal_return_unless_building_tools()
#### Keys ignored in scope 1:.:.:rcc.pro:<TRUE>:
# QMAKE_TARGET_DESCRIPTION = "Qt Resource Compiler"

View File

@ -18,6 +18,7 @@ qt_internal_add_tool(${target_name}
qtheaders.cpp qtheaders.h
tracegen.cpp
)
qt_internal_return_unless_building_tools()
#### Keys ignored in scope 1:.:.:tracegen.pro:<TRUE>:
# _OPTION = "host_build"

View File

@ -40,6 +40,7 @@ qt_internal_add_tool(${target_name}
#PUBLIC_LIBRARIES # special case remove
#Qt::Gui # special case remove
)
qt_internal_return_unless_building_tools()
#### Keys ignored in scope 1:.:.:uic.pro:<TRUE>:
# QMAKE_TARGET_DESCRIPTION = "Qt User Interface Compiler"

View File

@ -3246,6 +3246,9 @@ def write_main_part(
# Footer:
cm_fh.write(f"{spaces(indent)})\n")
if typename == "Tool":
cm_fh.write(f"{spaces(indent)}qt_internal_return_unless_building_tools()\n")
write_resources(cm_fh, name, scope, indent, target_ref=target_ref)
write_statecharts(cm_fh, name, scope, indent)