1 # macros to handle translation files
3 # qbt_add_translations(<target> QRC_FILE <filename> TS_FILES <filenames>)
4 # handles out of source builds for Qt resource files that include translations
5 # The function generates translations out of the supplied list of .ts files in the build directory,
6 # copies the .qrc file there, calls qt5_add_resources() adds its output to the target sources list.
7 function(qbt_add_translations _target)
8 set(oneValueArgs QRC_FILE)
9 set(multiValueArgs TS_FILES)
10 cmake_parse_arguments(QBT_TR "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
12 get_target_property(_binaryDir ${_target} BINARY_DIR)
14 if (NOT QBT_TR_QRC_FILE)
15 message(FATAL_ERROR "QRC file is empty")
17 if (NOT QBT_TR_TS_FILES)
18 message(FATAL_ERROR "TS_FILES files are empty")
21 if(IS_ABSOLUTE "${QBT_TR_QRC_FILE}")
22 file(RELATIVE_PATH _qrcToTs "${CMAKE_CURRENT_SOURCE_DIR}" "${QBT_TR_QRC_FILE}")
24 set(_qrcToTs "${QBT_TR_QRC_FILE}")
27 get_filename_component(_qrcToTsDir "${_qrcToTs}" DIRECTORY)
29 get_filename_component(_qmFilesBinaryDir "${CMAKE_CURRENT_BINARY_DIR}/${_qrcToTsDir}" ABSOLUTE)
30 # to make qt5_add_translation() work as we need
31 set_source_files_properties(${QBT_TR_TS_FILES} PROPERTIES OUTPUT_LOCATION "${_qmFilesBinaryDir}")
32 qt5_add_translation(_qmFiles ${QBT_TR_TS_FILES})
34 set(_qrc_dest_dir "${_binaryDir}/${_qrcToTsDir}")
35 set(_qrc_dest_file "${_binaryDir}/${QBT_TR_QRC_FILE}")
37 message(STATUS "copying ${QBT_TR_QRC_FILE} to ${_qrc_dest_dir}")
38 file(COPY ${QBT_TR_QRC_FILE} DESTINATION ${_qrc_dest_dir})
40 set_source_files_properties("${_qrc_dest_file}" PROPERTIES
42 OBJECT_DEPENDS "${_qmFiles}")
44 # With AUTORCC enabled rcc is ran by cmake before language files are generated,
45 # and thus we call rcc explicitly
46 qt5_add_resources(_resources "${_qrc_dest_file}")
47 target_sources(${_target} PRIVATE "${_resources}")