PageRenderTime 246ms CodeModel.GetById 70ms app.highlight 45ms RepoModel.GetById 109ms app.codeStats 1ms

/lang/translations.cmake

http://github.com/tomahawk-player/tomahawk
CMake | 50 lines | 34 code | 10 blank | 6 comment | 1 complexity | 8a0e9006eb0a3c022aa9406249c3a3f5 MD5 | raw file
 1macro(add_tomahawk_translations language)
 2    list( APPEND TOMAHAWK_LANGUAGES ${ARGV} )
 3
 4    set( tomahawk_i18n_qrc_content "<!DOCTYPE RCC><RCC version=\"1.0\">\n" )
 5
 6    # tomahawk and qt language files
 7    set( tomahawk_i18n_qrc_content "${tomahawk_i18n_qrc_content}<qresource prefix=\"/lang\">\n" )
 8    foreach( lang ${TOMAHAWK_LANGUAGES} )
 9        set( tomahawk_i18n_qrc_content "${tomahawk_i18n_qrc_content}<file>tomahawk_${lang}.qm</file>\n" )
10        if( NOT lang STREQUAL "en" AND EXISTS ${QT_TRANSLATIONS_DIR}/qt_${lang}.qm )
11            file( COPY ${QT_TRANSLATIONS_DIR}/qt_${lang}.qm DESTINATION ${CMAKE_CURRENT_BINARY_DIR} )
12            set( tomahawk_i18n_qrc_content "${tomahawk_i18n_qrc_content}<file>qt_${lang}.qm</file>\n" )
13        endif()
14
15        # build explicitly enabled languages
16        list( APPEND TS_FILES "${CMAKE_SOURCE_DIR}/lang/tomahawk_${lang}.ts" )
17    endforeach()
18
19    set( tomahawk_i18n_qrc_content "${tomahawk_i18n_qrc_content}</qresource>\n" )
20    set( tomahawk_i18n_qrc_content "${tomahawk_i18n_qrc_content}</RCC>\n" )
21
22    # Write file and configure it aferwards to make it a BYPRODUCT: https://gitlab.kitware.com/cmake/cmake/issues/16367
23    file( WRITE ${CMAKE_BINARY_DIR}/lang/tomahawk_i18n.qrc.in "${tomahawk_i18n_qrc_content}" )
24    configure_file(${CMAKE_BINARY_DIR}/lang/tomahawk_i18n.qrc.in ${CMAKE_BINARY_DIR}/lang/tomahawk_i18n.qrc COPYONLY)
25
26    qt5_add_translation(QM_FILES ${TS_FILES})
27
28    ## HACK HACK HACK - around rcc limitations to allow out of source-tree building
29    set( trans_file tomahawk_i18n )
30    set( trans_srcfile ${CMAKE_BINARY_DIR}/lang/${trans_file}.qrc )
31    set( trans_infile ${CMAKE_CURRENT_BINARY_DIR}/${trans_file}.qrc )
32    set( trans_outfile ${CMAKE_CURRENT_BINARY_DIR}/qrc_${trans_file}.cxx )
33
34    # Copy the QRC file to the output directory
35    add_custom_command(
36        OUTPUT ${trans_infile}
37        COMMAND ${CMAKE_COMMAND} -E copy ${trans_srcfile} ${trans_infile}
38        MAIN_DEPENDENCY ${trans_srcfile}
39    )
40
41    # Run the resource compiler (rcc_options should already be set)
42    add_custom_command(
43        OUTPUT ${trans_outfile}
44        COMMAND ${QT_RCC_EXECUTABLE}
45        ARGS ${rcc_options} -name ${trans_file} -o ${trans_outfile} ${trans_infile}
46        MAIN_DEPENDENCY ${trans_infile}
47        DEPENDS ${QM_FILES}
48    )
49endmacro()
50