CMake: Fix 'Cannot find source file' error with older CMakes

Configuring a static plugin init library with CMake versions earlier
than 3.18.0 fails at generation phase with

CMake Error at Qt6CoreMacros.cmake:2071
(add_library):
  Cannot find source file:
    example/plugins/basictools/pnp_basictools_init.cpp
Call Stack (most recent call first):
    qtbase/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:1998
  (_qt_internal_add_library)
    qtbase/lib/cmake/Qt6/QtPublicPluginHelpers.cmake:243
  (qt6_add_library)
    qtbase/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:1967
  (__qt_internal_add_static_plugin_init_object_library)
    qtbase/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:1989
  (qt6_add_plugin)
    qtbase/plugins/basictools/CMakeLists.txt:1 (qt_add_plugin)

Marking the generated file as GENERATED explicitly solves the issue.

Similar to e2c6f2ba7e

Fixes: QTBUG-96197
Pick-to: 6.2
Change-Id: If730a1fcbe6910d6041eb6eba03d6e45a025c424
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
Alexandru Croitor 2021-09-03 17:35:59 +02:00
parent 0624eba1b1
commit d7c6d69a8c

View File

@ -233,6 +233,11 @@ function(__qt_internal_add_static_plugin_init_object_library
CONTENT "${import_content}"
)
# CMake versions earlier than 3.18.0 can't find the generated file for some reason,
# failing at generation phase.
# Explicitly marking the file as GENERATED fixes the issue.
set_source_files_properties("${generated_qt_plugin_file_name}" PROPERTIES GENERATED TRUE)
__qt_internal_get_static_plugin_init_target_name("${plugin_target}" plugin_init_target)
qt6_add_library("${plugin_init_target}" OBJECT "${generated_qt_plugin_file_name}")