]> git.lyx.org Git - lyx.git/blob - po/CMakeLists.txt
Force BibTeX rerun upon add/remove/change citation (fixes #6955).
[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 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} -E copy_if_different "${TOP_SRC_DIR}/lib/layouttranslations" "${_dst}"
47       COMMAND ${LYX_PYTHON_EXECUTABLE}
48       ARGS "${TOP_SRC_DIR}/po/lyx_pot.py" -b "${TOP_SRC_DIR}" -o "${_dst}" -t ${_par1} "--src_file=${_src_files}"
49       COMMAND  ${CMAKE_COMMAND} -E copy_if_different "${_dst}" "${TOP_SRC_DIR}/lib/layouttranslations"
50       DEPENDS ${_sources} ${_src_files} "${TOP_SRC_DIR}/lib/layouttranslations"
51       COMMENT "${LYX_PYTHON_EXECUTABLE} ${TOP_SRC_DIR}/po/lyx_pot.py -b ${TOP_SRC_DIR} -o  ${_dst} -t ${_par1} --src_file=${_src_files}"
52       )
53     ADD_CUSTOM_TARGET(layouttranslations1 DEPENDS "${_dst}")
54         set_target_properties(layouttranslations1 PROPERTIES FOLDER "i18n")
55     if (LYX_DATA_SUBDIR STREQUAL "")
56       install(FILES "${TOP_SRC_DIR}/lib/layouttranslations" DESTINATION .)
57     else()
58       install(FILES "${TOP_SRC_DIR}/lib/layouttranslations" DESTINATION ${LYX_DATA_SUBDIR})
59     endif()
60   else()
61     ADD_CUSTOM_COMMAND(
62       OUTPUT "${_dst}"
63       PRE_BUILD
64       COMMAND ${LYX_PYTHON_EXECUTABLE}
65       ARGS "${TOP_SRC_DIR}/po/lyx_pot.py" -b "${TOP_SRC_DIR}" -o "${_dst}" -t ${_par1} "--src_file=${_src_files}"
66       DEPENDS ${_sources} ${_src_files}
67       COMMENT "${LYX_PYTHON_EXECUTABLE} ${TOP_SRC_DIR}/po/lyx_pot.py -b ${TOP_SRC_DIR} -o  ${_dst} -t ${_par1} --src_file=${_src_files}"
68       )
69     LIST(APPEND _py_sources "${_dst}")
70   endif()
71   SET_SOURCE_FILES_PROPERTIES("${_dst}" GENERATED)
72   SET_SOURCE_FILES_PROPERTIES("${_src_files}" GENERATED)
73 endmacro(add_gettext_python)
74
75 SET_SOURCE_FILES_PROPERTIES("${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.cat.pot" GENERATED)
76 SET_SOURCE_FILES_PROPERTIES("${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.fmt.pot" GENERATED)
77 SET_SOURCE_FILES_PROPERTIES("${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.pot" GENERATED)
78
79 add_gettext_python(qt4 src/frontends/qt4/ui *.ui)
80 add_gettext_python(layouts lib/layouts *.layout *.inc *.module)
81 add_gettext_python(languages lib languages)
82 add_gettext_python(latexfonts lib latexfonts)
83 add_gettext_python(encodings lib encodings)
84 add_gettext_python(ui lib/ui *.ui *.inc)
85 add_gettext_python(external lib external_templates)
86 add_gettext_python(formats lib configure.py)
87 add_gettext_python(layouttranslations lib/layouts *.layout *.inc *.module)
88
89 ADD_CUSTOM_COMMAND(
90     OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.cat.pot"
91     COMMAND ${LYX_PYTHON_EXECUTABLE}
92     ARGS   "${TOP_CMAKE_PATH}/po/cat.py" ${_py_sources} > "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.cat.pot"
93     COMMAND ${LYX_PYTHON_EXECUTABLE}
94       ARGS   "${TOP_CMAKE_PATH}/po/dos2unix.py" "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.cat.pot"
95     DEPENDS ${_py_sources}
96     )
97
98 ADD_CUSTOM_COMMAND(
99     OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.fmt.pot"
100     COMMAND ${GETTEXT_MSGUNIQ_EXECUTABLE}
101     ARGS -o "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.fmt.pot" "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.cat.pot"
102     DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.cat.pot"
103     )
104
105 SET(_potfiles_dep)
106
107 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/POTFILES.in "")
108 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)
109 list(SORT _tmp_potfiles)
110 # list(REMOVE_ITEM _tmp_potfiles src/support/Package.cpp)
111
112 foreach(_f ${_tmp_potfiles})
113   # we don't need to select only relevant files because the outcome of xgettext
114   # will stay the same.
115   # Relevant files are files containing the string '_(".*")'
116   LIST(APPEND _potfiles_dep "${TOP_SRC_DIR}/${_f}")
117   file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/POTFILES.in "${_f}\n")
118 endforeach(_f)
119
120 ADD_CUSTOM_COMMAND(
121     OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.pot"
122     COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.fmt.pot" "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.pot"
123     COMMAND ${GETTEXT_XGETTEXT_EXECUTABLE}
124       --default-domain=${_lyxname} --directory=${TOP_SRC_DIR}
125       --add-comments=TRANSLATORS:
126       --language=C++ --join-existing --keyword=_ --keyword=N_ --keyword=B_ --keyword=qt_
127       --files-from=${CMAKE_CURRENT_BINARY_DIR}/POTFILES.in
128       --copyright-holder="LyX Developers" --msgid-bugs-address=lyx-devel@lists.lyx.org
129       -o "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.pot"
130     DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.fmt.pot" ${_potfiles_dep}
131     )
132
133 #
134 # We have to copy the po-files first,
135 # otherwise they would be modified (inside the macro GETTEXT_CREATE_TRANSLATIONS())
136 # This makes the "git pull" on po-files work again
137 file(GLOB LYX_BASE_PO_FILES RELATIVE ${TOP_SRC_DIR}/po ${TOP_SRC_DIR}/po/*.po)
138 list(SORT LYX_BASE_PO_FILES)
139 set(LYX_PO_FILES)
140 SET(LYX_UPDATED_PO_FILES)
141 SET(LYX_DEST_PO ${TOP_SRC_DIR}/po)
142
143 set(CONFIGURED_LANGUAGES)               # from file LINGUAS
144 set(INSTALLED_LANGUAGES)                # from names of existing po-files
145
146 file(STRINGS "${TOP_SRC_DIR}/po/LINGUAS" _lang_lines)
147 foreach(_c_l ${_lang_lines})
148   if(NOT _c_l MATCHES "^#.*")
149     string(REPLACE " " ";" _c_l ${_c_l}) #Split ${_c_l}
150     list(APPEND CONFIGURED_LANGUAGES ${_c_l})
151   endif()
152 endforeach(_c_l)
153
154 foreach(_pofile ${LYX_BASE_PO_FILES})
155   string(REGEX REPLACE "^(.*)\\.po$" "\\1" _inst_lng ${_pofile})
156   list(FIND CONFIGURED_LANGUAGES ${_inst_lng} _lng_idx)
157   if(_lng_idx GREATER -1)
158     list(APPEND INSTALLED_LANGUAGES "${_inst_lng} ")
159   endif()
160   add_custom_command(
161     OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_pofile}
162     COMMAND ${CMAKE_COMMAND} -E copy ${TOP_SRC_DIR}/po/${_pofile} ${CMAKE_CURRENT_BINARY_DIR}/${_pofile}
163     DEPENDS ${TOP_SRC_DIR}/po/${_pofile}
164     )
165   list(APPEND LYX_PO_FILES ${CMAKE_CURRENT_BINARY_DIR}/${_pofile})
166 endforeach(_pofile)
167
168 set(LYX_UPDATED_PO_FILES)
169 foreach(_pofile ${LYX_BASE_PO_FILES})
170   if(WIN32)
171     add_custom_command(
172       OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_pofile}.copied
173       COMMAND ${LYX_PYTHON_EXECUTABLE}
174         ARGS   "${TOP_CMAKE_PATH}/po/unix2dos.py" "${CMAKE_CURRENT_BINARY_DIR}/${_pofile}"
175       COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/${_pofile} ${LYX_DEST_PO}/${_pofile}
176       COMMAND ${CMAKE_COMMAND} -E touch ${_pofile}.copied
177       DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_pofile}
178       )
179   else()
180     add_custom_command(
181       OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_pofile}.copied
182       COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/${_pofile} ${LYX_DEST_PO}/${_pofile}
183       COMMAND ${CMAKE_COMMAND} -E touch ${_pofile}.copied
184       DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_pofile}
185       )
186   endif()
187   list(APPEND LYX_UPDATED_PO_FILES ${CMAKE_CURRENT_BINARY_DIR}/${_pofile}.copied)
188 endforeach(_pofile)
189
190 if(LYX_CPACK OR LYX_INSTALL)
191   set(_addALLOption ALL)
192 endif()
193 GETTEXT_CREATE_TRANSLATIONS(${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.pot ${_addALLOption} ${LYX_PO_FILES})
194
195 # Create a new target to remerge po files
196 # ALL omitted here, to prevent from automatic creation
197 ADD_CUSTOM_TARGET(update-po DEPENDS ${LYX_UPDATED_PO_FILES})
198 set_target_properties(update-po PROPERTIES FOLDER "i18n")
199 add_dependencies(update-po translations)
200