blob: 68835b2ef82c02c6de3a47039bdaee01aaae8be9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(test_update_translation_macro)
find_package(Qt6 REQUIRED COMPONENTS Core LinguistTools)
function(create_app target)
add_executable(${target}
myi18nobject.cpp)
target_include_directories(${target}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/some_dir)
target_link_libraries(${target} Qt6::Core)
endfunction()
function(expect_target target)
if(NOT TARGET ${target})
message(FATAL_ERROR "Expected target '${target}' does not exist.")
endif()
endfunction()
function(not_expect_target target)
if(TARGET ${target})
message(FATAL_ERROR "Target '${target}' exists unexpectedly.")
endif()
endfunction()
function(expect_files_in_list list_var)
set(file_names "")
foreach(path IN LISTS "${list_var}")
get_filename_component(file_name "${path}" NAME)
list(APPEND file_names "${file_name}")
endforeach()
set(found_file_names "")
foreach(expected_file_name IN LISTS ARGN)
list(FIND file_names "${expected_file_name}" idx)
if(idx EQUAL -1)
message(FATAL_ERROR "Expected file name '${expected_file_name}' is not in "
"'${list_var}'. Its value is '${${list_var}}'.")
endif()
list(APPEND found_file_names "${expected_file_name}")
endforeach()
list(REMOVE_ITEM file_names ${found_file_names})
list(LENGTH file_names n)
if(NOT n EQUAL 0)
message(FATAL_ERROR "Unexpected file names in '${list_var}': ${file_names}\n"
"Value of '${list_var}' is '${${list_var}}'.")
endif()
endfunction()
# Test NO_GLOBAL_TARGET for lupdate.
# Also, use the old signature where the first argument is the target.
create_app(app1)
qt6_add_lupdate(app1
NO_GLOBAL_TARGET
TS_FILES myobject_de.ts)
expect_target(test_update_translation_macro_lupdate)
not_expect_target(app1_lrelease)
not_expect_target(update_translations)
not_expect_target(release_translations)
# Test NO_GLOBAL_TARGET for lrelease.
create_app(app2)
qt6_add_lrelease(app2
NO_GLOBAL_TARGET
TS_FILES myobject_de.ts myobject_en.ts
QM_FILES_OUTPUT_VARIABLE qm_files)
not_expect_target(app2_lupdate)
expect_target(test_update_translation_macro_lrelease)
not_expect_target(update_translations)
not_expect_target(release_translations)
expect_files_in_list(qm_files myobject_de.qm myobject_en.qm)
# Typical usage of qt_add_lupdate/qt_add_lrelease. Pass some options for good measure.
create_app(app3)
qt6_add_lupdate(
SOURCE_TARGETS app1 app2 app3
TS_FILES myobject_no.ts myobject_fi.ts
OPTIONS -source-language en_US)
qt6_add_lrelease(app3
TS_FILES myobject_no.ts myobject_fi.ts
LRELEASE_TARGET app3_lrelease
OPTIONS -compress
QM_FILES_OUTPUT_VARIABLE qm_files2)
expect_target(test_update_translation_macro_lupdate1)
expect_target(app3_lrelease)
expect_target(release_translations)
expect_files_in_list(qm_files2 myobject_no.qm myobject_fi.qm)
# Now do the same with qt6_add_translations.
create_app(app4)
qt6_add_translations(
IMMEDIATE_CALL
TARGETS app4
SOURCE_TARGETS app4
LUPDATE_TARGET app4_lupdate
LRELEASE_TARGET app4_lrelease
TS_FILES myobject_lv.ts myobject_et.ts
QM_FILES_OUTPUT_VARIABLE qm_files
LUPDATE_OPTIONS -source-language en_US
LRELEASE_OPTIONS -compress)
expect_target(app4_lupdate)
expect_target(app4_lrelease)
expect_target(release_translations)
expect_files_in_list(qm_files myobject_lv.qm myobject_et.qm)
# Typical usage of qt_add_translations with a generated resource.
create_app(app5)
qt6_add_translations(app5
IMMEDIATE_CALL
TS_FILES myobject_ru.ts
RESOURCE_PREFIX "/tränslehschns")
# qt_add_translations on a static lib with a generated resource and the default resource prefix.
# Extract the created resource targets.
add_library(staticlib1 STATIC
myi18nobject.cpp)
target_include_directories(staticlib1
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/some_dir)
target_link_libraries(staticlib1 PRIVATE Qt6::Core)
set(staticlib1_resource_targets "")
qt6_add_translations(staticlib1
IMMEDIATE_CALL
SOURCE_TARGETS staticlib1
TS_FILES myobject_da.ts
OUTPUT_TARGETS staticlib1_resource_targets)
if("${staticlib1_resource_targets}" STREQUAL "")
message(FATAL_ERROR "staticlib1_resource_targets is empty.")
endif()
# Explicitly specify SOURCES.
create_app(app6)
qt6_add_translations(app6
IMMEDIATE_CALL
SOURCE_TARGETS app6
TS_FILES myobject_cs.ts
SOURCES myi18nobject.cpp)
# Explicitly specify INCLUDE_DIRECTORIES.
create_app(app7)
qt6_add_translations(app7
IMMEDIATE_CALL
SOURCE_TARGETS app7
TS_FILES myobject_nl.ts
INCLUDE_DIRECTORIES some_dir)
# Build 'update_translations' before any of the '*_lrelease' targets.
get_directory_property(lrelease_targets BUILDSYSTEM_TARGETS)
list(FILTER lrelease_targets INCLUDE REGEX "_lrelease[0-9]*$")
foreach(target IN LISTS lrelease_targets)
add_dependencies(${target} update_translations)
endforeach()
|