summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2023-12-05 17:08:33 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-12-11 14:24:56 +0000
commitaef0c3cf32885699fa2c6985136814db17d90ec6 (patch)
tree522da04deb093f4d3a59ad3d6ec82e99cfe1c0f8
parent68bdc5764da2d4e442181b408751b6572f36fa74 (diff)
CMake: Fix qt_add_translations in different subdirs for VS generators
Commit 0338a2f7523e1fe21be325e76f6aba6b0c9e4467, was supposed to fix QTBUG-115166: XXX_lupdate targets where always run when using a VS generator. The fix introduced the regression QTBUG-119555 if qt_add_translations (or qt_add_lupdate) was run in different sub-directories. We were hitting yet another restriction in the VS project generator and project configuration errored out with: TARGET 'update_translations' was not created in this directory. This happened, because qt_add_lupdate added a PRE_BUILD step to update_translations, but for the VS generator, this must happen in the same subdirectory. We now work around this problem by building foo_lupdate with "cmake --build" in the COMMANDs of update_translations. As a consequence, we must create update_translations at the end of the project directory scope. Since we now require cmake_language(DEFER CALL), users who generate VS projects with CMake versions older than 3.19 will see a warning that the update_translations target cannot be created. The VS installation comes with a recent enough CMake version (on my machine it's 3.26.4), so this should not be a problem. [ChangeLog][CMake] When using CMake's Visual Studio project generator, the creation of the update_translations target requires now CMake 3.19 or newer. A warning is printed for older CMake versions. This warning can be disabled by setting QT_NO_GLOBAL_LUPDATE_TARGET_CREATION_WARNING to ON. Pick-to: 6.6 Fixes: QTBUG-119555 Task-number: QTBUG-115166 Change-Id: I16b6ebd467544caf852b8791f4db8699f8d4c483 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> (cherry picked from commit 66aebd35ab37cbe93ad728412116177b4e182b80) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/linguist/Qt6LinguistToolsMacros.cmake47
1 files changed, 37 insertions, 10 deletions
diff --git a/src/linguist/Qt6LinguistToolsMacros.cmake b/src/linguist/Qt6LinguistToolsMacros.cmake
index 9d803e73f..f7828f8d6 100644
--- a/src/linguist/Qt6LinguistToolsMacros.cmake
+++ b/src/linguist/Qt6LinguistToolsMacros.cmake
@@ -335,29 +335,56 @@ set(lupdate_subproject${n}_excluded \"${excluded}\")
endif()
if(NOT arg_NO_GLOBAL_TARGET)
- if(NOT TARGET ${QT_GLOBAL_LUPDATE_TARGET})
- add_custom_target(${QT_GLOBAL_LUPDATE_TARGET})
- endif()
if(CMAKE_GENERATOR MATCHES "^Visual Studio ")
# For the Visual Studio generators we cannot use add_dependencies, because this would
# enable ${lupdate_target} in the default build of the solution. See QTBUG-115166 and
- # upstream CMake issue #16668 for details. As a work-around, we run the
- # ${lupdate_target} through 'cmake --build' as PRE_BUILD step of the global lupdate
- # target.
- add_custom_command(
- TARGET ${QT_GLOBAL_LUPDATE_TARGET} PRE_BUILD
- COMMAND "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" -t ${lupdate_target}
- )
+ # upstream CMake issue #16668 for details. Instead, we record ${lupdate_target} and
+ # create an update_translations target at the end of the top-level directory scope.
+ if(${CMAKE_VERSION} VERSION_LESS "3.19.0")
+ if(NOT QT_NO_GLOBAL_LUPDATE_TARGET_CREATION_WARNING)
+ message(WARNING
+ "Cannot create target ${QT_GLOBAL_LUPDATE_TARGET} with this CMake version. "
+ "Please upgrade to CMake 3.19.0 or newer. "
+ "Set QT_NO_GLOBAL_LUPDATE_TARGET_CREATION_WARNING to ON to disable this "
+ "warning."
+ )
+ endif()
+ return()
+ endif()
+ set(property_name _qt_target_${QT_GLOBAL_LUPDATE_TARGET}_dependencies)
+ get_property(recorded_targets GLOBAL PROPERTY ${property_name})
+ if("${recorded_targets}" STREQUAL "")
+ cmake_language(EVAL CODE
+ "cmake_language(DEFER DIRECTORY \"${CMAKE_SOURCE_DIR}\" CALL _qt_internal_add_global_lupdate_target_deferred \"${QT_GLOBAL_LUPDATE_TARGET}\")"
+ )
+ endif()
+ set_property(GLOBAL APPEND PROPERTY ${property_name} ${lupdate_target})
# Exclude ${lupdate_target} from the solution's default build to avoid it being enabled
# should the user add a dependency to it.
set_property(TARGET ${lupdate_target} PROPERTY EXCLUDE_FROM_DEFAULT_BUILD ON)
else()
+ if(NOT TARGET ${QT_GLOBAL_LUPDATE_TARGET})
+ add_custom_target(${QT_GLOBAL_LUPDATE_TARGET})
+ endif()
add_dependencies(${QT_GLOBAL_LUPDATE_TARGET} ${lupdate_target})
endif()
endif()
endfunction()
+# Hack for the Visual Studio generator. Create the global lupdate target named ${target} and work
+# around the lack of a working add_dependencies by calling 'cmake --build' for every dependency.
+function(_qt_internal_add_global_lupdate_target_deferred target)
+ get_property(target_dependencies GLOBAL PROPERTY _qt_target_${target}_dependencies)
+ set(target_commands "")
+ foreach(dependency IN LISTS target_dependencies)
+ list(APPEND target_commands
+ COMMAND "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" -t ${dependency}
+ )
+ endforeach()
+ add_custom_target(${target} ${target_commands})
+endfunction()
+
function(_qt_internal_store_languages_from_ts_files_in_targets targets ts_files)
if(NOT APPLE)
return()