summaryrefslogtreecommitdiffstats
path: root/tests/auto/cmake/linguist/test_i18n_source_language/CMakeLists.txt
blob: 72b5e5cde1e7aa6a07b8b5e8f5181f984a95e146 (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
# Copyright (C) 2023 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required(VERSION 3.16)
project(test_i18n_source_language)

# Set up the project structure.
find_package(Qt6 REQUIRED COMPONENTS Core Gui LinguistTools)
qt_standard_project_setup()
set(native_ts_files "")

function(my_add_library target)
    add_library("${target}" STATIC lib.cpp)
    target_link_libraries("${target}" PRIVATE Qt6::Core)
endfunction()

# qt_add_lupdate with just the native translation.
my_add_library(lib1 STATIC lib.cpp)
qt_add_lupdate(
    SOURCE_TARGETS lib1
    PLURALS_TS_FILE "${CMAKE_CURRENT_BINARY_DIR}/lib1_en.ts"
)

# qt_add_lupdate with just the native translation which has already been translated.
# check_ts_files.cmake checks that the numerus translations are preserved.
my_add_library(lib2 STATIC lib.cpp)
configure_file(lib2_en.ts.in lib2_en.ts COPYONLY)
qt_add_lupdate(
    SOURCE_TARGETS lib2
    PLURALS_TS_FILE "${CMAKE_CURRENT_BINARY_DIR}/lib2_en.ts"
)

# qt_add_lupdate with regular translations and the native translation.
my_add_library(lib3 STATIC lib.cpp)
qt_add_lupdate(
    SOURCE_TARGETS lib3
    TS_FILES "${CMAKE_CURRENT_BINARY_DIR}/lib3_hi.ts" "${CMAKE_CURRENT_BINARY_DIR}/lib3_ho.ts"
    PLURALS_TS_FILE "${CMAKE_CURRENT_BINARY_DIR}/lib3_en.ts"
)

# qt_add_translations with just the native translation.
my_add_library(lib4 STATIC lib.cpp)
qt_add_translations(
    TARGETS lib4
    SOURCE_TARGETS lib4
    PLURALS_TS_FILE "${CMAKE_CURRENT_BINARY_DIR}/lib4_en.ts"
)

# qt_add_translations with regular translations and the native translation.
my_add_library(lib5 STATIC lib.cpp)
qt_add_translations(
    TARGETS lib5
    SOURCE_TARGETS lib5
    TS_FILES "${CMAKE_CURRENT_BINARY_DIR}/lib5_hi.ts" "${CMAKE_CURRENT_BINARY_DIR}/lib5_ho.ts"
    PLURALS_TS_FILE "${CMAKE_CURRENT_BINARY_DIR}/lib5_en.ts"
)

# Find out how many targets we created above.
get_directory_property(targets BUILDSYSTEM_TARGETS)
list(FILTER targets INCLUDE REGEX "^lib[0-9]+$")
list(LENGTH targets targets_length)

# Build the 'update_translations' target by default and check the native language .ts files.
string(REPLACE ";" "\\\\;" native_ts_files "${native_ts_files}")
add_custom_target(force_ts_update ALL
    COMMAND "${CMAKE_COMMAND}" -DNR_OF_TARGETS=${targets_length}
            -P "${CMAKE_CURRENT_SOURCE_DIR}/check_ts_files.cmake"
)
add_dependencies(force_ts_update update_translations)