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

cmake_minimum_required(VERSION 3.16)
project(test_i18n_auto_ts_file_names)

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

function(my_add_library target)
    qt6_add_library("${target}" ${ARGN})
    target_link_libraries("${target}" PRIVATE Qt6::Core)
endfunction()

# Remove .ts files from older test runs.
file(GLOB_RECURSE old_ts_files "${CMAKE_CURRENT_SOURCE_DIR}/*.ts")
foreach(f IN LISTS old_ts_files)
    message("Removing: ${f}")
    file(REMOVE "${f}")
endforeach()

set(expected_files "")
set(unexpected_files "")

# Check defaults for the deferred call.
my_add_library(lib1 STATIC lib.cpp)
set(QT_I18N_TRANSLATED_LANGUAGES te st)
qt_add_translations(TARGETS lib1)
list(APPEND expected_files
    "${CMAKE_CURRENT_SOURCE_DIR}/test_i18n_auto_ts_file_names_en.ts"            # plurals-only file
    "${CMAKE_CURRENT_SOURCE_DIR}/test_i18n_auto_ts_file_names_te.ts"
    "${CMAKE_CURRENT_SOURCE_DIR}/test_i18n_auto_ts_file_names_st.ts")

# Check defaults for the immediate call.
my_add_library(lib2 STATIC lib.cpp)
set(QT_I18N_SOURCE_LANGUAGE hu)
set(QT_I18N_TRANSLATED_LANGUAGES hi ho)
qt_add_translations(TARGETS lib2 IMMEDIATE_CALL)
list(APPEND expected_files
    "${CMAKE_CURRENT_SOURCE_DIR}/test_i18n_auto_ts_file_names_hu.ts"            # plurals-only file
    "${CMAKE_CURRENT_SOURCE_DIR}/test_i18n_auto_ts_file_names_hi.ts"
    "${CMAKE_CURRENT_SOURCE_DIR}/test_i18n_auto_ts_file_names_ho.ts")

# Check defaults for deferred/immediate call in a subdir.
add_subdirectory(subdir)
list(APPEND expected_files
    "${CMAKE_CURRENT_SOURCE_DIR}/subdir/test_i18n_auto_ts_file_names_eo.ts"    # plurals-only file
    "${CMAKE_CURRENT_SOURCE_DIR}/subdir/test_i18n_auto_ts_file_names_de.ts"
    "${CMAKE_CURRENT_SOURCE_DIR}/subdir/test_i18n_auto_ts_file_names_ee.ts"    # plurals-only file
    "${CMAKE_CURRENT_SOURCE_DIR}/subdir/test_i18n_auto_ts_file_names_da.ts"
)

# Check whether TS_FILE_BASE works.
my_add_library(lib5 STATIC lib.cpp)
set(QT_I18N_SOURCE_LANGUAGE ne)
set(QT_I18N_TRANSLATED_LANGUAGES no)
qt_add_translations(TARGETS lib5 TS_FILE_BASE lib5)
list(APPEND expected_files
    "${CMAKE_CURRENT_SOURCE_DIR}/lib5_ne.ts"                                    # plurals-only file
    "${CMAKE_CURRENT_SOURCE_DIR}/lib5_no.ts")

# Check whether TS_FILE_DIR works.
my_add_library(lib6 STATIC lib.cpp)
set(QT_I18N_SOURCE_LANGUAGE so)                                                 # plurals-only file
set(QT_I18N_TRANSLATED_LANGUAGES sv)
qt_add_translations(TARGETS lib6 TS_FILE_DIR translations)
list(APPEND expected_files
    "${CMAKE_CURRENT_SOURCE_DIR}/translations/test_i18n_auto_ts_file_names_sv.ts")

# Check whether TS_FILE_BASE and TS_FILE_DIR work together.
my_add_library(lib7 STATIC lib.cpp)
set(QT_I18N_SOURCE_LANGUAGE fy)
set(QT_I18N_TRANSLATED_LANGUAGES fi)
qt_add_translations(TARGETS lib7 TS_FILE_BASE lib7 TS_FILE_DIR translations)
list(APPEND expected_files
    "${CMAKE_CURRENT_SOURCE_DIR}/translations/lib7_fy.ts"                       # plurals-only file
    "${CMAKE_CURRENT_SOURCE_DIR}/translations/lib7_fi.ts")

# Check defaults for the deferred call with just the native language set.
my_add_library(lib8 STATIC lib.cpp)
set(QT_I18N_TRANSLATED_LANGUAGES "")
set(QT_I18N_SOURCE_LANGUAGE nl)
qt_add_translations(TARGETS lib8)
list(APPEND expected_files
    "${CMAKE_CURRENT_SOURCE_DIR}/test_i18n_auto_ts_file_names_nl.ts")

# Check whether we can turn off the generation of the plurals-only file.
my_add_library(lib10 STATIC lib.cpp)
set(QT_I18N_TRANSLATED_LANGUAGES cy)
set(QT_I18N_SOURCE_LANGUAGE an)
qt_add_translations(TARGETS lib10 NO_GENERATE_PLURALS_TS_FILE)
list(APPEND expected_files
    "${CMAKE_CURRENT_SOURCE_DIR}/test_i18n_auto_ts_file_names_cy.ts")
list(APPEND unexpected_files
    "${CMAKE_CURRENT_SOURCE_DIR}/test_i18n_auto_ts_file_names_an.ts")

function(check_ts_file_paths)
    foreach(filepath IN LISTS expected_files)
        if(NOT EXISTS "${filepath}")
            message(FATAL_ERROR "Expected file '${filepath}' does not exist.")
        endif()
    endforeach()
    foreach(filepath IN LISTS unexpected_files)
        if(EXISTS "${filepath}")
            message(FATAL_ERROR "File '${filepath}' unexpectedly exists.")
        endif()
    endforeach()
endfunction()

if(CMAKE_VERSION VERSION_LESS "3.19")
    check_ts_file_paths()
else()
    cmake_language(DEFER CALL check_ts_file_paths)
endif()