]> git.lyx.org Git - features.git/blob - po/CMakeLists.txt
Cmake build: Make sure that a sequence of commands to recreate layouttranslations...
[features.git] / po / CMakeLists.txt
1 # This file is part of LyX, the document processor.
2 # Licence details can be found in the file COPYING.
3 #
4 # Copyright (c) 2008-2011 Peter Kümmel, <syntheticpp@gmx.net>
5 # Copyright (c) 2008-2011 Kornel Benko, <Kornel.Benko@berlin.de>
6 #
7
8 project(po)
9
10 include_directories(${TOP_SRC_DIR}/po)
11
12 SET(_lyxname ${PACKAGE})
13 SET(_py_sources)
14 macro(add_gettext_python  _par _dir)
15   set(_sources)
16   foreach(_arg ${ARGN})
17     file(GLOB _s1 ${TOP_SRC_DIR}/${_dir}/${_arg})
18     list(SORT _s1)
19     list(APPEND _sources ${_s1})
20   endforeach(_arg)
21   if (${_par} MATCHES "layouttranslations")
22     SET(_dst "${CMAKE_CURRENT_BINARY_DIR}/${_par}")
23   else ()
24     SET(_dst "${CMAKE_CURRENT_BINARY_DIR}/${_par}_l10n.pot")
25   endif()
26   SET(_tmp_src_files "${CMAKE_CURRENT_BINARY_DIR}/${_par}_tmp_files")
27   SET(_src_files "${CMAKE_CURRENT_BINARY_DIR}/${_par}_files")
28   file(WRITE ${_tmp_src_files} "")
29   foreach(_s ${_sources})
30     FILE(APPEND ${_tmp_src_files} "${_s}\n")
31   endforeach()
32   if(${_par} MATCHES "^\(.*\)_[0-9]+$")
33     set(_par1 ${CMAKE_MATCH_1})
34   else()
35     set(_par1 ${_par})
36   endif()
37   ADD_CUSTOM_COMMAND(
38     OUTPUT ${_src_files}
39     COMMAND ${CMAKE_COMMAND} -E copy_if_different ${_tmp_src_files} ${_src_files}
40     DEPENDS ${_tmp_src_files}
41   )
42   if (${_par} MATCHES "layouttranslations")
43     ADD_CUSTOM_COMMAND(
44       OUTPUT "${_dst}"
45       PRE_BUILD
46       COMMAND  ${CMAKE_COMMAND}
47         "-DTOP_SRC_DIR=${TOP_SRC_DIR}"
48         "-DDestFile=${_dst}"
49         "-DLYX_PYTHON_EXECUTABLE=${LYX_PYTHON_EXECUTABLE}"
50         "-DParType=${_par1}"
51         "-DSources=${_src_files}"
52         -P "${TOP_SRC_DIR}/po/CreateLayoutTranslations.cmake"
53       DEPENDS ${_sources} ${_src_files} "${TOP_SRC_DIR}/lib/layouttranslations"
54       COMMENT "${LYX_PYTHON_EXECUTABLE} ${TOP_SRC_DIR}/po/lyx_pot.py -b ${TOP_SRC_DIR} -o  ${_dst} -t ${_par1} --src_file=${_src_files}"
55       )
56     ADD_CUSTOM_TARGET(layouttranslations1 DEPENDS "${_dst}")
57         set_target_properties(layouttranslations1 PROPERTIES FOLDER "i18n")
58     if (LYX_DATA_SUBDIR STREQUAL "")
59       install(FILES "${TOP_SRC_DIR}/lib/layouttranslations" DESTINATION .)
60     else()
61       install(FILES "${TOP_SRC_DIR}/lib/layouttranslations" DESTINATION ${LYX_DATA_SUBDIR})
62     endif()
63   else()
64     ADD_CUSTOM_COMMAND(
65       OUTPUT "${_dst}"
66       PRE_BUILD
67       COMMAND ${LYX_PYTHON_EXECUTABLE}
68       ARGS "${TOP_SRC_DIR}/po/lyx_pot.py" -b "${TOP_SRC_DIR}" -o "${_dst}" -t ${_par1} "--src_file=${_src_files}"
69       DEPENDS ${_sources} ${_src_files}
70       COMMENT "${LYX_PYTHON_EXECUTABLE} ${TOP_SRC_DIR}/po/lyx_pot.py -b ${TOP_SRC_DIR} -o  ${_dst} -t ${_par1} --src_file=${_src_files}"
71       )
72     LIST(APPEND _py_sources "${_dst}")
73   endif()
74   SET_SOURCE_FILES_PROPERTIES("${_dst}" GENERATED)
75   SET_SOURCE_FILES_PROPERTIES("${_src_files}" GENERATED)
76 endmacro(add_gettext_python)
77
78 SET_SOURCE_FILES_PROPERTIES("${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.cat.pot" GENERATED)
79 SET_SOURCE_FILES_PROPERTIES("${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.fmt.pot" GENERATED)
80 SET_SOURCE_FILES_PROPERTIES("${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.pot" GENERATED)
81
82 add_gettext_python(qt4 src/frontends/qt4/ui *.ui)
83 add_gettext_python(layouts lib/layouts *.layout *.inc *.module)
84 add_gettext_python(languages lib languages)
85 add_gettext_python(latexfonts lib latexfonts)
86 add_gettext_python(encodings lib encodings)
87 add_gettext_python(ui lib/ui *.ui *.inc)
88 add_gettext_python(external lib external_templates)
89 add_gettext_python(formats lib configure.py)
90 add_gettext_python(layouttranslations lib/layouts *.layout *.inc *.module)
91
92 ADD_CUSTOM_COMMAND(
93     OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.cat.pot"
94     COMMAND ${LYX_PYTHON_EXECUTABLE}
95     ARGS   "${TOP_CMAKE_PATH}/po/cat.py" ${_py_sources} > "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.cat_tmp.pot"
96     COMMAND ${CMAKE_COMMAND} -E copy_if_different
97       "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.cat_tmp.pot" "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.cat.pot"
98     DEPENDS ${_py_sources}
99     )
100
101 ADD_CUSTOM_COMMAND(
102     OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.fmt.pot"
103     COMMAND ${GETTEXT_MSGUNIQ_EXECUTABLE}
104     ARGS -o "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.fmt_tmp.pot" "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.cat.pot"
105     COMMAND ${CMAKE_COMMAND} -E copy_if_different
106       "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.fmt_tmp.pot" "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.fmt.pot"
107     DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.cat.pot"
108     )
109
110 SET(_potfiles_dep)
111
112 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/POTFILES.in.tmp "")
113 file(GLOB_RECURSE _tmp_potfiles RELATIVE ${TOP_SRC_DIR}/ ${TOP_SRC_DIR}/src/*.h  ${TOP_SRC_DIR}/src/*.cpp  ${TOP_SRC_DIR}/src/*.cpp.in)
114 list(SORT _tmp_potfiles)
115 # list(REMOVE_ITEM _tmp_potfiles src/support/Package.cpp)
116
117 foreach(_f ${_tmp_potfiles})
118   # we don't need to select only relevant files because the outcome of xgettext
119   # will stay the same.
120   # Relevant files are files containing the string '_(".*")'
121   LIST(APPEND _potfiles_dep "${TOP_SRC_DIR}/${_f}")
122   file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/POTFILES.in.tmp "${_f}\n")
123 endforeach(_f)
124
125 execute_process(
126   COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_BINARY_DIR}/POTFILES.in.tmp" "${CMAKE_CURRENT_BINARY_DIR}/POTFILES.in"
127   )
128
129 ADD_CUSTOM_COMMAND(
130     OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.pot"
131     COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.fmt.pot" "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.pot"
132     COMMAND ${GETTEXT_XGETTEXT_EXECUTABLE}
133       --from-code=UTF-8
134       --default-domain=${_lyxname} --directory=${TOP_SRC_DIR}
135       --add-comments=TRANSLATORS:
136       --language=C++ --join-existing --keyword=_ --keyword=N_ --keyword=B_ --keyword=qt_
137       --files-from=${CMAKE_CURRENT_BINARY_DIR}/POTFILES.in
138       --copyright-holder="LyX Developers" --msgid-bugs-address=lyx-devel@lists.lyx.org
139       -o "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.pot"
140     DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.fmt.pot" ${_potfiles_dep}
141     )
142
143 #
144 # We have to copy the po-files first,
145 # otherwise they would be modified (inside the macro GETTEXT_CREATE_TRANSLATIONS())
146 # This makes the "git pull" on po-files work again
147 file(GLOB LYX_BASE_PO_FILES RELATIVE ${TOP_SRC_DIR}/po ${TOP_SRC_DIR}/po/*.po)
148 list(SORT LYX_BASE_PO_FILES)
149 set(LYX_PO_FILES)
150 SET(LYX_UPDATED_PO_FILES)
151 SET(LYX_DEST_PO ${TOP_SRC_DIR}/po)
152
153 set(CONFIGURED_LANGUAGES)               # from file LINGUAS
154 set(INSTALLED_LANGUAGES)                # from names of existing po-files
155
156 file(STRINGS "${TOP_SRC_DIR}/po/LINGUAS" _lang_lines)
157 foreach(_c_l ${_lang_lines})
158   if(NOT _c_l MATCHES "^#.*")
159     string(REPLACE " " ";" _c_l ${_c_l}) #Split ${_c_l}
160     list(APPEND CONFIGURED_LANGUAGES ${_c_l})
161   endif()
162 endforeach(_c_l)
163
164 foreach(_pofile ${LYX_BASE_PO_FILES})
165   string(REGEX REPLACE "^(.*)\\.po$" "\\1" _inst_lng ${_pofile})
166   list(FIND CONFIGURED_LANGUAGES ${_inst_lng} _lng_idx)
167   if(_lng_idx GREATER -1)
168     list(APPEND INSTALLED_LANGUAGES ${_inst_lng})
169   endif()
170   add_custom_command(
171     OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_pofile}
172     COMMAND ${CMAKE_COMMAND} -E copy ${TOP_SRC_DIR}/po/${_pofile} ${CMAKE_CURRENT_BINARY_DIR}/${_pofile}
173     DEPENDS ${TOP_SRC_DIR}/po/${_pofile}
174     )
175   list(APPEND LYX_PO_FILES ${CMAKE_CURRENT_BINARY_DIR}/${_pofile})
176 endforeach(_pofile)
177
178 FIND_PROGRAM(LYX_GITVERSION git)
179 set(LYX_UPDATED_GMO_FILES)
180 foreach(_gmo_base ${INSTALLED_LANGUAGES})
181   set(_gmo ${_gmo_base}.gmo)
182   set(_tobeupdated "${CMAKE_CURRENT_BINARY_DIR}/${_gmo}.tobeupdated")
183   list(APPEND LYX_UPDATED_GMO_FILES "${_tobeupdated}")
184   if(LYX_GITVERSION)
185     add_custom_command(
186       OUTPUT "${_tobeupdated}"
187           COMMAND "${LYX_GITVERSION}" "status" "--porcelain" "${_gmo_base}.po" ">" "${_tobeupdated}"
188           COMMAND ${LYX_PYTHON_EXECUTABLE} "${TOP_CMAKE_PATH}/po/update-gmo.py" 
189                 "${_tobeupdated}"
190                 "${CMAKE_CURRENT_BINARY_DIR}/${_gmo}"
191                 "${LYX_DEST_PO}/${_gmo}"
192           WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
193       DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_gmo}"
194       )
195   else()
196     add_custom_command(
197       OUTPUT "${_tobeupdated}"
198       COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_BINARY_DIR}/${_gmo}" "${LYX_DEST_PO}/${_gmo}"
199       COMMAND ${CMAKE_COMMAND} -E touch "${_tobeupdated}"
200       DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_gmo}"
201     )
202   endif()
203 endforeach()
204
205 set(LYX_UPDATED_PO_FILES)
206 foreach(_pofile ${LYX_BASE_PO_FILES})
207   if(WIN32)
208     add_custom_command(
209       OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_pofile}.copied
210       COMMAND ${LYX_PYTHON_EXECUTABLE}
211         ARGS   "${TOP_CMAKE_PATH}/po/unix2dos.py" "${CMAKE_CURRENT_BINARY_DIR}/${_pofile}"
212       COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/${_pofile} ${LYX_DEST_PO}/${_pofile}
213       COMMAND ${CMAKE_COMMAND} -E touch ${_pofile}.copied
214       DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_pofile}
215       )
216   else()
217     add_custom_command(
218       OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_pofile}.copied
219       COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/${_pofile} ${LYX_DEST_PO}/${_pofile}
220       COMMAND ${CMAKE_COMMAND} -E touch ${_pofile}.copied
221       DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_pofile}
222       )
223   endif()
224   list(APPEND LYX_UPDATED_PO_FILES ${CMAKE_CURRENT_BINARY_DIR}/${_pofile}.copied)
225 endforeach(_pofile)
226
227 if(LYX_CPACK OR LYX_INSTALL)
228   set(_addALLOption ALL)
229 endif()
230 GETTEXT_CREATE_TRANSLATIONS(${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.pot ${_addALLOption} ${LYX_PO_FILES})
231
232 # Create a new target to remerge po files
233 # ALL omitted here, to prevent from automatic creation
234 ADD_CUSTOM_TARGET(update-gmo DEPENDS ${LYX_UPDATED_GMO_FILES})
235 ADD_CUSTOM_TARGET(update-po DEPENDS ${LYX_UPDATED_PO_FILES} ${LYX_UPDATED_GMO_FILES})
236 set_target_properties(update-po update-gmo PROPERTIES FOLDER "i18n")
237 add_dependencies(update-po translations)
238