diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2023-04-14 12:11:21 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2023-04-18 11:49:45 +0200 |
commit | 67c6d77e566b18f7b0b283eadadb5a11d9f27feb (patch) | |
tree | a70e5b4085f939f30f8f6ed8441844191616e7ce | |
parent | 4ec248512e9238acaebe7db089da4106473301aa (diff) | |
download | qttools-67c6d77e566b18f7b0b283eadadb5a11d9f27feb.tar.gz |
CMake: Mark qm files as GENERATED in the target scope
Projects with cmake_minimum_required(VERSION 3.19) or below, so with
no support for the CMP0118 policy, failed to configure when
translations were added in a subdirectory scope different from
the target scope.
qt_add_translations adds qm files to resources, that in turn calls
_qt_internal_expose_deferred_files_to_ide which adds the qm files
to the target sources.
Because qm files are created using add_custom_command, which by default
marks the files as GENERATED only in the directory scope of the
command (unless CMP0118 is set to NEW), that causes add_executable to
think the qm files are not generated, and error out with
"Cannot find source file:".
Explicitly set the GENERATED flag in the target directory scope to
avoid the issue when using CMake 3.18+.
The error still happens with CMake 3.17 or lower, but that's not the
only error that happens. Just adding resources in a different
subdirectory without exposing the source files already fails, and
that's not something we can really fix without a newer CMake version.
Pick-to: 6.5
Fixes: QTBUG-112841
Change-Id: I79eced94ac641a6f9239f3eb721cef5e35f847fa
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Amir Masoud Abdol <amir.abdol@qt.io>
-rw-r--r-- | src/linguist/Qt6LinguistToolsMacros.cmake | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/linguist/Qt6LinguistToolsMacros.cmake b/src/linguist/Qt6LinguistToolsMacros.cmake index 637202267..c992bfa41 100644 --- a/src/linguist/Qt6LinguistToolsMacros.cmake +++ b/src/linguist/Qt6LinguistToolsMacros.cmake @@ -246,6 +246,21 @@ function(qt6_add_lrelease target) ${lrelease_command} ${arg_OPTIONS} ${ts_file} -qm ${qm} DEPENDS ${QT_CMAKE_EXPORT_NAMESPACE}::lrelease "${ts_file}" VERBATIM) + + # Mark file as GENERATED, so that calling _qt_internal_expose_deferred_files_to_ide + # doesn't cause an error at generation time saying "Cannot find source file:" when + # qt6_add_lrelease is called from a subdirectory different than the target. + # The issue happend when the user project called cmake_minimum_required(VERSION) + # with a version less than 3.20 or set the CMP0118 policy value to OLD. + set(scope_args) + if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.18") + set(scope_args TARGET_DIRECTORY ${target}) + endif() + set_source_files_properties(${qm} + ${scope_args} + PROPERTIES GENERATED TRUE + ) + list(APPEND qm_files "${qm}") # QTBUG-103470: Save the target responsible for driving the build of the custom command |