diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2021-07-02 17:43:58 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2021-07-05 13:02:05 +0200 |
commit | 785df612319d3023ad994f3153d42a067a1adaa9 (patch) | |
tree | 8e02bbbe2c781d173a0b7ded732234136a77090c /src/corelib/Qt6CoreMacros.cmake | |
parent | b0e428124b31217cdc23d8a48496c0779442544b (diff) |
CMake: Fix qt6_extract_metatypes to work with VS Generators
CMake has an optimization where it skips creation of a
${target}_autogen target and instead uses PRE_BUILD events for
AUTOMOC. That breaks qt6_extract_metatypes which expects the
autogen target to always exist.
Disable the optimization by generating a dummy header file and
adding it as a source to the target.
Pick-to: 6.2
Fixes: QTBUG-94944
Change-Id: Ic3d923cc6d3a149fea8c5c7b111576b64d19f608
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/corelib/Qt6CoreMacros.cmake')
-rw-r--r-- | src/corelib/Qt6CoreMacros.cmake | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index 539c6bd159..1dca7f887c 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -1013,6 +1013,32 @@ function(qt6_extract_metatypes target) endif() if (NOT use_dep_files) + # When a project is configured with a Visual Studio generator, CMake's + # cmQtAutoGenInitializer::InitAutogenTarget() can take one of two code paths on how to + # handle AUTOMOC rules. + # It either creates a ${target}_autogen custom target or uses PRE_BUILD build events. + # + # The latter in considered an optimization and is used by CMake when possible. + # Unfortunately that breaks our add_dependency call because we expect on _autogen target + # to always exist. + # + # Ensure the PRE_BUILD path is not taken by generating a dummy header file and adding it + # as a source file to the target. This causes the file to be added to + # cmQtAutoGenInitializer::AutogenTarget.DependFiles, which disables the PRE_BUILD path. + if(CMAKE_GENERATOR MATCHES "Visual Studio") + # The file name should be target specific, but still short, so we don't hit path + # length issues. + string(MAKE_C_IDENTIFIER "ddf_${target}" dummy_dependency_file) + set(dummy_out_file "${CMAKE_CURRENT_BINARY_DIR}/${dummy_dependency_file}.h") + + # The content shouldn't be empty so we don't trigger AUTOMOC warnings about it. + file(GENERATE OUTPUT "${dummy_out_file}" CONTENT "//") + set_source_files_properties("${dummy_out_file}" PROPERTIES + GENERATED TRUE + SKIP_AUTOGEN OFF) + target_sources("${target}" PRIVATE "${dummy_out_file}") + endif() + add_custom_target(${target}_automoc_json_extraction DEPENDS ${QT_CMAKE_EXPORT_NAMESPACE}::cmake_automoc_parser BYPRODUCTS ${type_list_file} |