1 # check for lupdate and lrelease: we can't
2 # do it using qmake as it doesn't have
3 # QMAKE_LUPDATE and QMAKE_LRELEASE variables :(
5 # I18N_LANGUAGE - if not empty, wraps only chosen language
8 # One problem is that FindQt4.cmake will look for these and cache the results
9 # If users have lrelease from Qt3 (e.g., Debian, Ubuntu)
12 # First remove these from cache
13 set(QT_LUPDATE_EXECUTABLE NOTFOUND CACHE FILEPATH "" FORCE)
14 set(QT_LRELEASE_EXECUTABLE NOTFOUND CACHE FILEPATH "" FORCE)
15 set(QT_LCONVERT_EXECUTABLE NOTFOUND CACHE FILEPATH "" FORCE)
17 FIND_PROGRAM(QT_LUPDATE_EXECUTABLE NAMES lupdate-qt4 lupdate PATHS
18 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\4.0.0;InstallDir]/bin"
19 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Versions\\4.0.0;InstallDir]/bin"
23 if(QT_LUPDATE_EXECUTABLE)
24 message(STATUS "Found lupdate: ${QT_LUPDATE_EXECUTABLE}")
25 else(QT_LUPDATE_EXECUTABLE)
26 if(LinguistForTrojita_FIND_REQUIRED)
27 message(FATAL_ERROR "Could NOT find lupdate")
28 endif(LinguistForTrojita_FIND_REQUIRED)
29 endif(QT_LUPDATE_EXECUTABLE)
31 FIND_PROGRAM(QT_LRELEASE_EXECUTABLE NAMES lrelease-qt4 lrelease PATHS
32 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\4.0.0;InstallDir]/bin"
33 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Versions\\4.0.0;InstallDir]/bin"
37 if(QT_LRELEASE_EXECUTABLE)
38 message(STATUS "Found lrelease: ${QT_LRELEASE_EXECUTABLE}")
39 else(QT_LRELEASE_EXECUTABLE)
40 if(LinguistForTrojita_FIND_REQUIRED)
41 message(FATAL_ERROR "Could NOT find lrelease")
42 endif(LinguistForTrojita_FIND_REQUIRED)
43 endif(QT_LRELEASE_EXECUTABLE)
45 FIND_PROGRAM(QT_LCONVERT_EXECUTABLE NAMES lconvert-qt4 lconvert PATHS
46 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\4.0.0;InstallDir]/bin"
47 "[HKEY_CURRENT_USER\\Software\\Trolltech\\Versions\\4.0.0;InstallDir]/bin"
51 if(QT_LCONVERT_EXECUTABLE)
52 message(STATUS "Found lconvert: ${QT_LCONVERT_EXECUTABLE}")
53 else(QT_LCONVERT_EXECUTABLE)
54 if(LinguistForTrojita_FIND_REQUIRED)
55 message(FATAL_ERROR "Could NOT find lconvert")
56 endif(LinguistForTrojita_FIND_REQUIRED)
57 endif(QT_LCONVERT_EXECUTABLE)
59 mark_as_advanced(QT_LUPDATE_EXECUTABLE QT_LRELEASE_EXECUTABLE QT_LCONVERT_EXECUTABLE)
61 if(QT_LUPDATE_EXECUTABLE AND QT_LRELEASE_EXECUTABLE AND QT_LCONVERT_EXECUTABLE)
62 set(LinguistForTrojita_FOUND TRUE)
64 # QT4_WRAP_TS(outfiles infiles ...)
65 # outfiles receives .qm generated files from
66 # .ts files in arguments
67 # a target lupdate is created for you
68 # update/generate your translations files
69 # example: QT4_WRAP_TS(foo_QM ${foo_TS})
70 MACRO (QT4_WRAP_TS outfiles)
71 # a target to manually run lupdate
72 #ADD_CUSTOM_TARGET(lupdate
73 #COMMAND ${QT_LUPDATE_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR} -ts ${ARGN}
74 #WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
77 GET_FILENAME_COMPONENT(it ${it} ABSOLUTE)
78 GET_FILENAME_COMPONENT(outfile ${it} NAME_WE)
80 SET(outfile ${CMAKE_CURRENT_BINARY_DIR}/${outfile}.qm)
81 ADD_CUSTOM_COMMAND(OUTPUT ${outfile}
82 COMMAND ${QT_LRELEASE_EXECUTABLE}
83 ARGS -compress -removeidentical -silent ${it} -qm ${outfile}
87 SET(${outfiles} ${${outfiles}} ${outfile})
89 ENDMACRO (QT4_WRAP_TS)
91 # QT_WRAP_PO(outfiles infiles ...)
92 # outfiles receives .qm generated files from
93 # .po files in arguments
94 # example: QT4_WRAP_PO(foo_TS ${foo_PO})
95 MACRO (QT4_WRAP_PO outfiles)
97 GET_FILENAME_COMPONENT(it ${it} ABSOLUTE)
98 # PO files are foo-en_GB.po not foo_en_GB.po like Qt expects
99 GET_FILENAME_COMPONENT(fileWithDash ${it} NAME_WE)
100 if(NOT I18N_LANGUAGE)
102 else(NOT I18N_LANGUAGE)
103 string(REGEX MATCH "${I18N_LANGUAGE}" ln ${fileWithDash})
109 endif(NOT I18N_LANGUAGE)
111 STRING(REPLACE "-" "_" filenameBase "${fileWithDash}")
112 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/locale)
113 SET(tsfile ${CMAKE_CURRENT_BINARY_DIR}/locale/${filenameBase}.ts)
114 SET(qmfile ${CMAKE_CURRENT_BINARY_DIR}/locale/${filenameBase}.qm)
116 if (NOT EXISTS "${it}")
117 GET_FILENAME_COMPONENT(path ${it} PATH)
118 STRING(REGEX MATCH "[^-]+$" lang "${fileWithDash}")
119 set (it "${path}/${lang}.po")
120 endif (NOT EXISTS "${it}")
122 # lconvert from PO to TS and then run lupdate to generate the correct strings
123 # finally run lrelease as used above
124 ADD_CUSTOM_COMMAND(OUTPUT ${qmfile}
125 COMMAND ${QT_LCONVERT_EXECUTABLE}
126 ARGS -i ${it} -o ${tsfile}
127 COMMAND ${QT_LUPDATE_EXECUTABLE}
128 ARGS ${CMAKE_CURRENT_SOURCE_DIR} -silent -noobsolete -ts ${tsfile}
129 COMMAND ${QT_LRELEASE_EXECUTABLE}
130 ARGS -compress -removeidentical -silent ${tsfile} -qm ${qmfile}
134 SET(${outfiles} ${${outfiles}} ${qmfile})
137 ENDMACRO (QT4_WRAP_PO)
139 else(QT_LUPDATE_EXECUTABLE AND QT_LRELEASE_EXECUTABLE AND QT_LCONVERT_EXECUTABLE)
140 set(LinguistForTrojita_FOUND FALSE)
141 endif(QT_LUPDATE_EXECUTABLE AND QT_LRELEASE_EXECUTABLE AND QT_LCONVERT_EXECUTABLE)