2020-04-13 16:44:42 +00:00
|
|
|
function(qt5_translation outfiles)
|
2020-04-11 07:12:20 +00:00
|
|
|
find_package(Qt5 COMPONENTS LinguistTools REQUIRED)
|
2019-02-12 16:31:17 +00:00
|
|
|
|
|
|
|
set(options)
|
2020-04-13 16:44:42 +00:00
|
|
|
set(oneValueArgs BASE_NAME OUTPUT_DIR)
|
2020-03-30 11:58:50 +00:00
|
|
|
set(multiValueArgs SOURCES LANGUAGES)
|
2019-02-12 16:31:17 +00:00
|
|
|
|
2019-12-03 16:23:14 +00:00
|
|
|
cmake_parse_arguments(_QTTR "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
2020-04-13 16:44:42 +00:00
|
|
|
set(_base_name ${_QTTR_BASE_NAME})
|
2020-03-30 11:58:50 +00:00
|
|
|
set(_sources ${_QTTR_SOURCES})
|
2020-04-13 16:44:42 +00:00
|
|
|
set(_output_dir ${_QTTR_OUTPUT_DIR})
|
2019-02-12 16:31:17 +00:00
|
|
|
set(_languages ${_QTTR_LANGUAGES})
|
|
|
|
|
2021-06-12 09:59:31 +00:00
|
|
|
set(_l10n_qrc_body "")
|
2020-04-13 16:44:42 +00:00
|
|
|
make_directory(${_output_dir})
|
2019-02-12 16:31:17 +00:00
|
|
|
|
2021-06-12 09:59:31 +00:00
|
|
|
foreach(lang ${_languages})
|
|
|
|
set(_ts "${_base_name}_${lang}.ts")
|
|
|
|
set(_qm "${_base_name}_${lang}.qm")
|
2020-04-13 16:44:42 +00:00
|
|
|
list(APPEND _ts_list ${_output_dir}/${_ts})
|
2021-06-12 09:59:31 +00:00
|
|
|
list(APPEND _l10n_names_list "${_base_name}_l10n_${lang}")
|
|
|
|
string(APPEND _l10n_qrc_body "<file alias=\"${_qm}\">${CMAKE_BINARY_DIR}/${_qm}</file>\n")
|
2019-06-14 05:35:39 +00:00
|
|
|
|
2019-12-03 16:23:14 +00:00
|
|
|
add_custom_target(
|
2021-06-12 09:59:31 +00:00
|
|
|
${_base_name}_l10n_${lang} COMMAND ${Qt5_LUPDATE_EXECUTABLE} ${_sources} -ts ${_output_dir}/${_ts}
|
|
|
|
-target-language ${lang} DEPENDS ${_sources})
|
2019-06-14 05:35:39 +00:00
|
|
|
|
2020-04-13 16:44:42 +00:00
|
|
|
if(NOT EXISTS "${_output_dir}/${_ts}")
|
2021-06-12 09:59:31 +00:00
|
|
|
add_custom_target(${_ts} DEPENDS ${_base_name}_l10n_${lang})
|
2019-06-14 05:35:39 +00:00
|
|
|
else()
|
|
|
|
add_custom_target(${_ts} COMMAND echo "Skipping lupdate for ${_ts}")
|
2019-02-12 16:31:17 +00:00
|
|
|
endif()
|
|
|
|
|
2019-12-03 16:23:14 +00:00
|
|
|
add_custom_command(
|
2020-04-13 16:44:42 +00:00
|
|
|
OUTPUT ${CMAKE_BINARY_DIR}/${_qm} COMMAND ${Qt5_LRELEASE_EXECUTABLE} ARGS ${_output_dir}/${_ts} -qm
|
2020-04-11 07:12:20 +00:00
|
|
|
${CMAKE_BINARY_DIR}/${_qm} DEPENDS ${_ts} ${_sources})
|
2019-02-12 16:31:17 +00:00
|
|
|
endforeach()
|
|
|
|
|
2020-04-13 16:44:42 +00:00
|
|
|
configure_file(${CMLIB_MODULE_DIR}/qrc/l10n.qrc.in ${CMAKE_BINARY_DIR}/${_base_name}_l10n.qrc)
|
2020-04-13 17:55:36 +00:00
|
|
|
qt5_add_resources(${outfiles} ${CMAKE_BINARY_DIR}/${_base_name}_l10n.qrc)
|
|
|
|
add_custom_target(${_base_name}_qrc DEPENDS ${_qrc})
|
2020-04-14 06:11:01 +00:00
|
|
|
add_custom_target(${_base_name}_l10n DEPENDS ${_l10n_names_list})
|
2019-06-27 02:18:29 +00:00
|
|
|
if(NOT TARGET l10n)
|
|
|
|
add_custom_target(l10n)
|
|
|
|
endif()
|
2020-04-13 17:55:36 +00:00
|
|
|
add_dependencies(l10n ${_base_name}_l10n)
|
2019-02-12 16:31:17 +00:00
|
|
|
|
2020-04-13 17:55:36 +00:00
|
|
|
# add_dependencies(${_target} ${_target}_qrc)
|
|
|
|
# target_sources(${_target} PUBLIC ${_qrc})
|
2020-04-13 16:44:42 +00:00
|
|
|
set(${outfiles} ${${outfiles}} PARENT_SCOPE)
|
2019-02-12 16:31:17 +00:00
|
|
|
endfunction()
|