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