Fix top level builds where AUTOMOC_EXECUTABLE was unset on some targets

The qt_example_build_end() command tries to recursively find all build
system targets by descending into all source directories. Some sets of
examples re-use the same source directory multiple times with different
build directories, but this hides all but one of those re-used source
directories from the recursive search. This resulted in some targets
being missed, which in turn prevented qt_autogen_tools() from being
called on them. In top level builds, this meant AUTOMOC_EXECUTABLE
wasn't set, so CMake tried to verify the moc it wanted to use, which
doesn't exist for the first configure of a top level build, resulting
in a fatal error. Since we can't find all targets reliably with a
recursive search, manually handle the ones that could be missed.

There was a similar problem with qt_autogen_tools() not being called
for a target created to compile a doc snippet. The error message is
the same as the case above, the cause is again AUTOMOC_EXECUTABLE
not being set, but for a different reason. Apply the same fix and
call it manually, which should have been the case originally.

Fixes: QTBUG-96118
Fixes: QTBUG-96159
Change-Id: I079c696cf74f77d7caa2c59e6263d3fb1c55d20e
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 920a5f727b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Craig Scott 2021-09-02 20:34:33 +10:00 committed by Qt Cherry-pick Bot
parent 52b60051b5
commit 067253fb2f
2 changed files with 22 additions and 4 deletions

View File

@ -10,7 +10,7 @@ qt_internal_add_example(keyinteraction)
qt_internal_add_example(layouts)
add_subdirectory(localstorage)
add_subdirectory(models)
#qt_internal_add_example(views)
qt_internal_add_example(views)
add_subdirectory(tableview)
qt_internal_add_example(mousearea)
qt_internal_add_example(positioners)
@ -19,12 +19,12 @@ add_subdirectory(scenegraph)
qt_internal_add_example(shadereffects)
qt_internal_add_example(text)
qt_internal_add_example(threading)
#qt_internal_add_example(touchinteraction)
qt_internal_add_example(touchinteraction)
add_subdirectory(tutorials)
add_subdirectory(customitems)
qt_internal_add_example(imageprovider)
qt_internal_add_example(imageresponseprovider)
#qt_internal_add_example(window)
qt_internal_add_example(window)
add_subdirectory(particles)
qt_internal_add_example(delegatechooser)
qt_internal_add_example(shapes)
@ -37,3 +37,20 @@ endif()
if(TARGET Qt::QuickWidgets AND TARGET Qt::Widgets AND (QT_FEATURE_opengl OR QT_FEATURE_opengles2 OR QT_FEATURE_opengles3))
add_subdirectory(quickwidgets)
endif()
# qt_examples_build_end() misses at least some of these due to some
# source subdirectories being added multiple times. See QTBUG-96159.
set(reused_dir_targets
view_shared
touchinteraction_shared
window_shared
shapes_shared
)
foreach(target IN LISTS reused_dir_targets)
if(TARGET ${target})
qt_autogen_tools(${target} ENABLE_AUTOGEN_TOOLS moc rcc)
if(TARGET Qt::Widgets)
qt_autogen_tools(${target} ENABLE_AUTOGEN_TOOLS uic)
endif()
endif()
endforeach()

View File

@ -685,6 +685,7 @@ qt_internal_add_docs(Qml
)
# include snippet projects for developer builds
if(NOT QT_SUPERBUILD AND QT_FEATURE_private_tests AND CMAKE_VERSION VERSION_GREATER_EQUAL "3.19")
if(QT_FEATURE_private_tests AND CMAKE_VERSION VERSION_GREATER_EQUAL "3.19")
add_subdirectory(doc/snippets/cmake/qt_target_qml_sources)
qt_autogen_tools(qt_target_qml_sources_example ENABLE_AUTOGEN_TOOLS moc)
endif()