Warning, /graphics/kst-plot/cmake/modules/FindQt5LinguistForTrojita.cmake is written in an unsupported language. File is not indexed.

0001 # adapted from [trojita.git] / cmake / FindQt5LinguistForKst.cmake
0002 # check for lupdate and lrelease: we can't
0003 # do it using qmake as it doesn't have
0004 # QMAKE_LUPDATE and QMAKE_LRELEASE variables :(
0005 #
0006 #  I18N_LANGUAGE - if not empty, wraps only chosen language
0007 #
0008 
0009 get_filename_component(LINGUIST_PATH ${Qt5LinguistTools_DIR} PATH)
0010 get_filename_component(LINGUIST_PATH ${LINGUIST_PATH} PATH)
0011 get_filename_component(LINGUIST_PATH ${LINGUIST_PATH} PATH)
0012 set(LINGUIST_PATH ${LINGUIST_PATH}/bin)
0013 
0014 FIND_PROGRAM(QT_LUPDATE_EXECUTABLE NAMES lupdate-qt5 lupdate PATHS
0015     ${LINGUIST_PATH}
0016     NO_DEFAULT_PATH
0017 )
0018 
0019 if(QT_LUPDATE_EXECUTABLE)
0020   message(STATUS "Found lupdate: ${QT_LUPDATE_EXECUTABLE}")
0021 else(QT_LUPDATE_EXECUTABLE)
0022   if(Qt5LinguistForKst_FIND_REQUIRED)
0023     message(FATAL_ERROR "Could NOT find lupdate")
0024   endif(Qt5LinguistForKst_FIND_REQUIRED)
0025 endif(QT_LUPDATE_EXECUTABLE)
0026 
0027 FIND_PROGRAM(QT_LRELEASE_EXECUTABLE NAMES lrelease-qt5 lrelease PATHS
0028     ${LINGUIST_PATH}
0029     NO_DEFAULT_PATH
0030 )
0031 
0032 if(QT_LRELEASE_EXECUTABLE)
0033   message(STATUS "Found lrelease: ${QT_LRELEASE_EXECUTABLE}")
0034 else(QT_LRELEASE_EXECUTABLE)
0035   if(Qt5LinguistForKst_FIND_REQUIRED)
0036     message(FATAL_ERROR "Could NOT find lrelease")
0037   endif(Qt5LinguistForKst_FIND_REQUIRED)
0038 endif(QT_LRELEASE_EXECUTABLE)
0039 
0040 FIND_PROGRAM(QT_LCONVERT_EXECUTABLE NAMES lconvert-qt5 lconvert PATHS
0041     ${LINGUIST_PATH}
0042     NO_DEFAULT_PATH
0043 )
0044 
0045 if(QT_LCONVERT_EXECUTABLE)
0046   message(STATUS "Found lconvert: ${QT_LCONVERT_EXECUTABLE}")
0047 else(QT_LCONVERT_EXECUTABLE)
0048   if(Qt5LinguistForKst_FIND_REQUIRED)
0049     message(FATAL_ERROR "Could NOT find lconvert")
0050   endif(Qt5LinguistForKst_FIND_REQUIRED)
0051 endif(QT_LCONVERT_EXECUTABLE)
0052 
0053 mark_as_advanced(QT_LUPDATE_EXECUTABLE QT_LRELEASE_EXECUTABLE QT_LCONVERT_EXECUTABLE)
0054 
0055 if(QT_LUPDATE_EXECUTABLE AND QT_LRELEASE_EXECUTABLE AND QT_LCONVERT_EXECUTABLE)
0056   set(Qt5LinguistForKst_FOUND TRUE)
0057 
0058 # QT5_WRAP_TS(outfiles infiles ...)
0059 # outfiles receives .qm generated files from
0060 # .ts files in arguments
0061 # a target lupdate is created for you
0062 # update/generate your translations files
0063 # example: QT5_WRAP_TS(foo_QM ${foo_TS})
0064 MACRO (QT5_WRAP_TS outfiles)
0065   # a target to manually run lupdate
0066   #ADD_CUSTOM_TARGET(lupdate
0067                     #COMMAND ${QT_LUPDATE_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR} -ts ${ARGN}
0068                     #WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
0069   #)
0070   FOREACH (it ${ARGN})
0071     GET_FILENAME_COMPONENT(it ${it} ABSOLUTE)
0072     GET_FILENAME_COMPONENT(outfile ${it} NAME_WE)
0073 
0074     SET(outfile ${CMAKE_CURRENT_BINARY_DIR}/${outfile}.qm)
0075     ADD_CUSTOM_COMMAND(OUTPUT ${outfile}
0076                        COMMAND ${QT_LRELEASE_EXECUTABLE}
0077                        ARGS -compress -removeidentical -silent ${it} -qm ${outfile}
0078                        DEPENDS ${it}
0079     )
0080 
0081     SET(${outfiles} ${${outfiles}} ${outfile})
0082   ENDFOREACH (it)
0083 ENDMACRO (QT5_WRAP_TS)
0084 
0085 # QT_WRAP_PO(outfiles infiles ...)
0086 # outfiles receives .qm generated files from
0087 # .po files in arguments
0088 # example: QT5_WRAP_PO(foo_TS ${foo_PO})
0089 MACRO (QT5_WRAP_PO outfiles)
0090    FOREACH (it ${ARGN})
0091       GET_FILENAME_COMPONENT(it ${it} ABSOLUTE)
0092       # PO files are foo-en_GB.po not foo_en_GB.po like Qt expects
0093       GET_FILENAME_COMPONENT(fileWithDash ${it} NAME_WE)
0094       if(NOT I18N_LANGUAGE)
0095         set(do_wrap ON)
0096       else(NOT I18N_LANGUAGE)
0097         string(REGEX MATCH "${I18N_LANGUAGE}" ln ${fileWithDash})
0098         if(ln)
0099           set(do_wrap ON)
0100         else(ln)
0101           set(do_wrap OFF)
0102         endif(ln)
0103       endif(NOT I18N_LANGUAGE)      
0104       if(do_wrap)
0105         STRING(REPLACE "-" "_" filenameBase "${fileWithDash}")
0106         file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/locale)
0107         SET(tsfile ${CMAKE_CURRENT_BINARY_DIR}/locale/${filenameBase}.ts)
0108         SET(qmfile ${CMAKE_CURRENT_BINARY_DIR}/locale/${filenameBase}.qm)
0109 
0110         if (NOT EXISTS "${it}")
0111            GET_FILENAME_COMPONENT(path ${it} PATH)
0112            STRING(REGEX MATCH "[^-]+$" lang "${fileWithDash}")
0113            set (it "${path}/${lang}.po")
0114         endif (NOT EXISTS "${it}")
0115 
0116         # lconvert from PO to TS and then run lupdate to generate the correct strings
0117         # finally run lrelease as used above
0118         ADD_CUSTOM_COMMAND(OUTPUT ${qmfile}
0119                          COMMAND ${QT_LCONVERT_EXECUTABLE}
0120                          ARGS -i ${it} -o ${tsfile}
0121                          COMMAND ${QT_LUPDATE_EXECUTABLE}
0122                          ARGS ${CMAKE_CURRENT_SOURCE_DIR} -silent -noobsolete -ts ${tsfile}
0123                          COMMAND ${QT_LRELEASE_EXECUTABLE}
0124                          ARGS -compress -removeidentical -silent ${tsfile} -qm ${qmfile}
0125                          DEPENDS ${it}
0126                          )
0127 
0128         SET(${outfiles} ${${outfiles}} ${qmfile})
0129       endif(do_wrap)
0130    ENDFOREACH (it)
0131 ENDMACRO (QT5_WRAP_PO)
0132 
0133 else(QT_LUPDATE_EXECUTABLE AND QT_LRELEASE_EXECUTABLE AND QT_LCONVERT_EXECUTABLE)
0134   set(Qt5LinguistForKst_FOUND FALSE)
0135 endif(QT_LUPDATE_EXECUTABLE AND QT_LRELEASE_EXECUTABLE AND QT_LCONVERT_EXECUTABLE)