/lang/translations.cmake

http://github.com/tomahawk-player/tomahawk · CMake · 50 lines · 34 code · 10 blank · 6 comment · 1 complexity · 8a0e9006eb0a3c022aa9406249c3a3f5 MD5 · raw file

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