summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2024-03-07 10:48:12 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2024-03-07 20:16:08 +0000
commiteb725df39c52da7642baf1de07d78d5a142efc01 (patch)
treeee4147911496f5b2a47b546f80d68bc3a28b0040
parenta9cc858ec72090061a3d4002739effc6c8968351 (diff)
CMake: Fix target-less call of qt_add_lupdate
A call to qt_add_lupdate like the following would lead to an error when updating translations, because we generated an invalid JSON file and fed it to lupdate. qt_add_lupdate( TS_FILES du_de.ts SOURCES main.cpp one.cpp two.cpp ) Fix this by ensuring that we don't generate subprojects entries in the JSON file if there aren't any subprojects (== targets). Fixes: QTBUG-123011 Change-Id: Ic6465654375a7bfb7d387a6951f8f30408cae452 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> (cherry picked from commit c12750987f2ca474f0016d553e508164957ba659) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit 66bed97bfd33875e8412cba5ea6a41b69a83365a)
-rw-r--r--src/linguist/GenerateLUpdateProject.cmake38
-rw-r--r--tests/auto/cmake/linguist/test_translation_api/CMakeLists.txt6
2 files changed, 27 insertions, 17 deletions
diff --git a/src/linguist/GenerateLUpdateProject.cmake b/src/linguist/GenerateLUpdateProject.cmake
index 6d8277bed..64c383867 100644
--- a/src/linguist/GenerateLUpdateProject.cmake
+++ b/src/linguist/GenerateLUpdateProject.cmake
@@ -80,13 +80,15 @@ get_filename_component(project_root "${lupdate_project_file}" DIRECTORY)
# Make relative paths absolute to the project root
set(path_variables sources include_paths translations)
-foreach(i RANGE 1 ${lupdate_subproject_count})
- list(APPEND path_variables
- subproject${i}_include_paths
- subproject${i}_sources
- subproject${i}_excluded
- )
-endforeach()
+if(lupdate_subproject_count GREATER 0)
+ foreach(i RANGE 1 ${lupdate_subproject_count})
+ list(APPEND path_variables
+ subproject${i}_include_paths
+ subproject${i}_sources
+ subproject${i}_excluded
+ )
+ endforeach()
+endif()
foreach(path_var IN LISTS path_variables)
set(absolute_${path_var} "")
foreach(path IN LISTS lupdate_${path_var})
@@ -113,21 +115,23 @@ set(content "{
\"translations\": ${json_translations},
\"subProjects\": [
")
-foreach(i RANGE 1 ${lupdate_subproject_count})
- prepare_json_sources(json_sources ${absolute_subproject${i}_sources})
- list_to_json_array("${absolute_subproject${i}_include_paths}" json_include_paths)
- list_to_json_array("${absolute_subproject${i}_excluded}" json_sources_exclusions)
- string(APPEND content " {
+if(lupdate_subproject_count GREATER 0)
+ foreach(i RANGE 1 ${lupdate_subproject_count})
+ prepare_json_sources(json_sources ${absolute_subproject${i}_sources})
+ list_to_json_array("${absolute_subproject${i}_include_paths}" json_include_paths)
+ list_to_json_array("${absolute_subproject${i}_excluded}" json_sources_exclusions)
+ string(APPEND content " {
\"projectFile\": \"${lupdate_subproject${i}_source_dir}/CMakeLists.txt\",
\"includePaths\": ${json_include_paths},
\"sources\": ${json_sources},
\"excluded\": ${json_sources_exclusions}
}")
- if(i LESS lupdate_subproject_count)
- string(APPEND content ",")
- endif()
- string(APPEND content "\n")
-endforeach()
+ if(i LESS lupdate_subproject_count)
+ string(APPEND content ",")
+ endif()
+ string(APPEND content "\n")
+ endforeach()
+endif()
string(APPEND content " ]
}
")
diff --git a/tests/auto/cmake/linguist/test_translation_api/CMakeLists.txt b/tests/auto/cmake/linguist/test_translation_api/CMakeLists.txt
index 68835b2ef..781927f37 100644
--- a/tests/auto/cmake/linguist/test_translation_api/CMakeLists.txt
+++ b/tests/auto/cmake/linguist/test_translation_api/CMakeLists.txt
@@ -140,6 +140,12 @@ qt6_add_translations(app6
TS_FILES myobject_cs.ts
SOURCES myi18nobject.cpp)
+# Explicitly specify SOURCES with target-less qt_add_lupdate.
+qt6_add_lupdate(
+ TS_FILES myobject_sk.ts
+ SOURCES myi18nobject.cpp
+)
+
# Explicitly specify INCLUDE_DIRECTORIES.
create_app(app7)
qt6_add_translations(app7