cmlib/CMLibQtTranslation.cmake

60 lines
1.9 KiB
CMake
Raw Normal View History

2019-02-12 16:31:17 +00:00
function(qt_translation)
2019-12-03 16:23:14 +00:00
find_package(
Qt5
COMPONENTS LinguistTools
REQUIRED)
2019-02-12 16:31:17 +00:00
set(options)
set(oneValueArgs TARGET TS_DIR)
set(multiValueArgs LANGUAGES)
2019-12-03 16:23:14 +00:00
cmake_parse_arguments(_QTTR "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
2019-02-12 16:31:17 +00:00
set(_target ${_QTTR_TARGET})
set(_ts_dir ${_QTTR_TS_DIR})
set(_languages ${_QTTR_LANGUAGES})
get_target_property(_sources ${_target} SOURCES)
set(L10N_QRC_BODY "")
make_directory(${_ts_dir})
foreach(_lang ${_languages})
set(_ts "${_target}_${_lang}.ts")
set(_qm "${_target}_${_lang}.qm")
list(APPEND _ts_list ${_ts_dir}/${_ts})
list(APPEND _l10n_targets "${_target}_l10n_${_lang}")
2019-12-03 16:23:14 +00:00
string(APPEND L10N_QRC_BODY
"<file alias=\"${_qm}\">${CMAKE_BINARY_DIR}/${_qm}</file>\n")
2019-12-03 16:23:14 +00:00
add_custom_target(
${_target}_l10n_${_lang}
COMMAND ${Qt5_LUPDATE_EXECUTABLE} ${_sources} -ts ${_ts_dir}/${_ts} -target-language
${_lang}
DEPENDS ${_sources})
if(NOT EXISTS "${_ts_dir}/${_ts}")
add_custom_target(${_ts} DEPENDS ${_target}_l10n_${_lang})
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(
OUTPUT ${CMAKE_BINARY_DIR}/${_qm}
COMMAND ${Qt5_LRELEASE_EXECUTABLE} ARGS ${_ts_dir}/${_ts} -qm
${CMAKE_BINARY_DIR}/${_qm}
DEPENDS ${_ts} ${_sources})
2019-02-12 16:31:17 +00:00
endforeach()
2019-12-03 16:23:14 +00:00
configure_file(${CMLIB_MODULE_DIR}/qrc/l10n.qrc.in
${CMAKE_BINARY_DIR}/${_target}_l10n.qrc)
2019-02-12 16:31:17 +00:00
qt5_add_resources(_qrc ${CMAKE_BINARY_DIR}/${_target}_l10n.qrc)
add_custom_target(${_target}_qrc DEPENDS ${_qrc})
add_custom_target(${_target}_l10n DEPENDS ${_l10n_targets})
if(NOT TARGET l10n)
add_custom_target(l10n)
endif()
add_dependencies(l10n ${_target}_l10n)
2019-02-12 16:31:17 +00:00
add_dependencies(${_target} ${_target}_qrc)
2019-02-12 16:31:17 +00:00
target_sources(${_target} PUBLIC ${_qrc})
endfunction()