forked from p-e-w/finalterm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGettext.cmake
772 lines (731 loc) · 26.1 KB
/
Gettext.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
#
# cmake/Gettext.cmake
# Copyright (C) 2012, 2013, Valama development team
#
# Valama is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Valama is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
##
#
# Heavily based on Jim Nelson's Gettext.cmake in Geary project:
# https://github.com/ypcs/geary
#
##
# Add find_package handler for gettext programs msgmerge, msgfmt, msgcat and
# xgettext.
##
# Constant:
# XGETTEXT_OPTIONS_DEFAULT: Provide common xgettext options.
# XGETTEXT_VALA_OPTIONS_DEFAULT: Provide common xgettext options for Vala files.
# XGETTEXT_GLADE_OPTIONS_DEFAULT: Provide common xgettext options for glade.
# XGETTEXT_TEXTMENU_OPTIONS_DEFAULT: Provide common xgettext options for
# TextMenu files.
##
# The gettext_create_pot macro creates .pot files with xgettext from multiple
# source files.
# Provide target 'pot' to generate .pot file.
#
# Supported sections:
#
# PACKAGE (optional)
# Gettext package name. Get exported to parent scope.
# Default: ${PROJECT_NAME}
#
# VERSION (optional)
# Gettext package version. Get exported to parent scope.
# Default: ${${GETTEXT_PACKAGE_NAME}_VERSION}
# (${GETTEXT_PACKAGE_NAME} is package name from option above)
#
# OPTIONS (optional)
# Pass list of xgettext options (you can use XGETTEXT_OPTIONS_DEFAULT,
# XGETTEXT_VALA_OPTIONS_DEFAULT, XGETTEXT_GLADE_OPTIONS_DEFAULT and
# XGETTEXT_TEXTMENU_OPTIONS_DEFAULT constants).
# Default: ${XGETTEXT_{,VALA,GLADE,TEXTMENU}_OPTIONS_DEFAULT}
#
# SRCFILES (optional/mandatory)
# List of source files to extract gettext strings from. Globbing is
# supported.
#
# GLADEFILES (optional/mandatory)
# List of glade source files to extract gettext strings from. Globbing is
# supported.
#
# TEXTMENUFILES (optional/mandatory)
# List of ftmenu files to extract gettext strings from. Globbing is
# supported.
#
# DESKTOPFILES (optional/mandatory)
# List of .desktop files to extract gettext strings from. Globbing is
# supported.
# intltool required.
#
# GSETTINGSFILES (optional/mandatory)
# List of gsettings (.gschema.xml) files to extract gettext strings from.
# Globbing is supported.
# intltool required.
#
# Either SRCFILES or GLADEFILES or TEXTMENUFILES or DESKTOPFILES or
# GSETTINGSFILES (or all of them) has to be filled with some files.
#
##
# The gettext_create_translations function generates .gmo files from .po files
# and install them as .mo files.
# Provide target 'translations' to build .gmo files.
#
# Supported sections:
#
# ALL (optional)
# Make translations target a dependency of the 'all' target. (Build
# translations with every build.)
#
# PODIR (optional)
# Directory with .po files.
# Default: ${CMAKE_CURRENT_SOURCE_DIR}
#
# LOCALEDIR (optional)
# Base directory where to install translations.
# Default: share/cmake
#
# LANGUAGES (optional)
# List of language 'short names'. This is in generel the part before the .po.
# With English locale this is e.g. 'en_GB' or 'en_US' etc.
#
# POFILES (optional)
# List of .po files.
#
##
#
# The following call is a simple example (within project po directory):
#
# include(Gettext)
# if(XGETTEXT_FOUND)
# set(potfile "${CMAKE_CURRENT_SOURCE_DIR}/my_project.pot")
# gettext_create_pot("${potfile}"
# SRCFILES
# "${PROJECT_SOURCE_DIR}/src/*.vala"
# )
# gettext_create_translations("${potfile}" ALL)
# endif()
#
##
#
# Gettext functions imported from Valama project:
# https://github.com/Valama/valama
#
# 2013/09/13: Merge upstream changes (in-source build support, proper quoting)
# 2013/05/30: Merge upstream changes (.desktop and .gschema.xml support).
# 2013/05/23: Dominique Lasserre <[email protected]>
# - Support .ftmenu files.
#
##
find_program(GETTEXT_MSGMERGE_EXECUTABLE msgmerge)
find_program(GETTEXT_MSGFMT_EXECUTABLE msgfmt)
find_program(GETTEXT_MSGCAT_EXECUTABLE msgcat)
find_program(XGETTEXT_EXECUTABLE xgettext)
mark_as_advanced(GETTEXT_MSGMERGE_EXECUTABLE)
mark_as_advanced(GETTEXT_MSGFMT_EXECUTABLE)
mark_as_advanced(GETTEXT_MSGCAT_EXECUTABLE)
mark_as_advanced(XGETTEXT_EXECUTABLE)
if(XGETTEXT_EXECUTABLE)
execute_process(
COMMAND
"${XGETTEXT_EXECUTABLE}" "--version"
OUTPUT_VARIABLE
gettext_version
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(gettext_version MATCHES "^xgettext \\(.*\\) [0-9]")
string(REGEX REPLACE "^xgettext \\([^\\)]*\\) ([0-9\\.]+[^ \n]*).*" "\\1" GETTEXT_VERSION_STRING "${gettext_version}")
endif()
unset(gettext_version)
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Gettext
REQUIRED_VARS
XGETTEXT_EXECUTABLE
GETTEXT_MSGMERGE_EXECUTABLE
GETTEXT_MSGFMT_EXECUTABLE
GETTEXT_MSGCAT_EXECUTABLE
VERSION_VAR
GETTEXT_VERSION_STRING
)
if(XGETTEXT_EXECUTABLE AND GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE AND GETTEXT_MSGCAT_EXECUTABLE)
set(XGETTEXT_FOUND TRUE)
# Export variable to use it as status info.
set(TRANSLATION_BUILD TRUE PARENT_SCOPE)
else()
set(XGETTEXT_FOUND FALSE)
set(TRANSLATION_BUILD FALSE PARENT_SCOPE)
endif()
set(XGETTEXT_OPTIONS_DEFAULT
"-s"
"--escape"
"--add-comments=\"TRANSLATORS:\"" #TODO: Make this configurable.
"--from-code=UTF-8"
)
set(XGETTEXT_VALA_OPTIONS_DEFAULT
"--language" "C"
"--keyword=_"
"--keyword=N_"
"--keyword=C_:1c,2"
"--keyword=NC_:1c,2"
)
set(XGETTEXT_GLADE_OPTIONS_DEFAULT
"--language" "Glade"
"--omit-header"
)
set(XGETTEXT_TEXTMENU_OPTIONS_DEFAULT
"--language" "C"
)
set(XGETTEXT_INTLTOOL_OPTIONS
"--language" "C"
"--keyword=N_:1"
)
set(_INTLTOOL_DESKTOPFILES)
if(XGETTEXT_FOUND)
macro(gettext_create_pot potfile)
cmake_parse_arguments(ARGS "" "PACKAGE;VERSION;WORKING_DIRECTORY"
"OPTIONS;VALA_OPTIONS;GLADE_OPTIONS;TEXTMENU_OPTIONS;SRCFILES;GLADEFILES;TEXTMENUFILES;DESKTOPFILES;GSETTINGSFILES" ${ARGN})
if(ARGS_PACKAGE)
set(package_name "${ARGS_PACKAGE}")
elseif(GETTEXT_PACKAGE)
set(package_name "${GETTEXT_PACKAGE}")
else()
set(package_name "${PROJECT_NAME}")
endif()
if(ARGS_VERSION)
set(package_version "${ARGS_VERSION}")
elseif(VERSION)
set(package_version "${VERSION}")
else()
set(package_version "${${package_name}_VERSION}")
endif()
# Export for status information.
set(GETTEXT_PACKAGE_NAME "${package_name}" PARENT_SCOPE)
set(GETTEXT_PACKAGE_VERSION "${package_version}" PARENT_SCOPE)
if(NOT ARGS_WORKING_DIRECTORY)
set(ARGS_WORKING_DIRECTORY "../")
endif()
set(xgettext_options "--package-name" "${package_name}")
if(package_version)
list(APPEND xgettext_options "--package-version" "${package_version}")
endif()
if(ARGS_OPTIONS)
list(APPEND xgettext_options ${ARGS_OPTIONS})
else()
list(APPEND xgettext_options ${XGETTEXT_OPTIONS_DEFAULT})
endif()
if(ARGS_XGETTEXT_VALA_OPTIONS_DEFAULT)
set(xgettext_vala_options ${ARGS_XGETTEXT_VALA_OPTIONS_DEFAULT})
else()
set(xgettext_vala_options ${XGETTEXT_VALA_OPTIONS_DEFAULT})
endif()
if(ARGS_XGETTEXT_GLADE_OPTIONS_DEFAULT)
set(xgettext_glade_options ${ARGS_XGETTEXT_GLADE_OPTIONS_DEFAULT})
else()
set(xgettext_glade_options ${XGETTEXT_GLADE_OPTIONS_DEFAULT})
endif()
if(ARGS_XGETTEXT_TEXTMENU_OPTIONS_DEFAULT)
set(xgettext_ftmenu_options ${ARGS_XGETTEXT_TEXTMENU_OPTIONS_DEFAULT})
else()
set(xgettext_ftmenu_options ${XGETTEXT_TEXTMENU_OPTIONS_DEFAULT})
endif()
if(ARGS_SRCFILES OR ARGS_GLADEFILES OR ARGS_TEXTMENUFILES OR ARGS_DESKTOPFILES OR ARGS_GSETTINGSFILES)
set(src_list)
set(src_list_abs)
foreach(globexpr ${ARGS_SRCFILES})
if(NOT IS_ABSOLUTE "${globexpr}")
get_filename_component(absDir "${ARGS_WORKING_DIRECTORY}" ABSOLUTE)
set(globexpr "${absDir}/${globexpr}")
endif()
set(tmpsrcfiles)
file(GLOB tmpsrcfiles ${globexpr})
if (tmpsrcfiles)
foreach(absFile ${tmpsrcfiles})
file(RELATIVE_PATH relFile "${CMAKE_CURRENT_SOURCE_DIR}" "${absFile}")
list(APPEND src_list "${relFile}")
list(APPEND src_list_abs "${absFile}")
endforeach()
else()
file(RELATIVE_PATH relFile "${CMAKE_CURRENT_SOURCE_DIR}" "${globexpr}")
list(APPEND src_list "${relFile}")
list(APPEND src_list_abs "${globexpr}")
endif()
endforeach()
set(glade_list)
set(glade_list_abs)
foreach(globexpr ${ARGS_GLADEFILES})
if(NOT IS_ABSOLUTE "${globexpr}")
get_filename_component(absDir "${ARGS_WORKING_DIRECTORY}" ABSOLUTE)
set(globexpr "${absDir}/${globexpr}")
endif()
set(tmpgladefiles)
file(GLOB tmpgladefiles ${globexpr})
if (tmpgladefiles)
foreach(absFile ${tmpgladefiles})
file(RELATIVE_PATH relFile "${CMAKE_CURRENT_SOURCE_DIR}" "${absFile}")
list(APPEND glade_list "${relFile}")
list(APPEND glade_list_abs "${absFile}")
endforeach()
else()
file(RELATIVE_PATH relFile "${CMAKE_CURRENT_SOURCE_DIR}" "${globexpr}")
list(APPEND glade_list "${relFile}")
list(APPEND glade_list_abs "${globexpr}")
endif()
endforeach()
set(ftmenu_list)
set(ftmenu_list_abs)
foreach(globexpr ${ARGS_TEXTMENUFILES})
if(NOT IS_ABSOLUTE "${globexpr}")
get_filename_component(absDir "${ARGS_WORKING_DIRECTORY}" ABSOLUTE)
set(globexpr "${absDir}/${globexpr}")
endif()
set(tmpftmenufiles)
file(GLOB tmpftmenufiles ${globexpr})
if (tmpftmenufiles)
foreach(absFile ${tmpftmenufiles})
file(RELATIVE_PATH relFile "${CMAKE_CURRENT_SOURCE_DIR}" "${absFile}")
list(APPEND ftmenu_list "${relFile}")
list(APPEND ftmenu_list_abs "${absFile}")
endforeach()
else()
file(RELATIVE_PATH relFile "${CMAKE_CURRENT_SOURCE_DIR}" "${globexpr}")
list(APPEND ftmenu_list "${relFile}")
list(APPEND ftmenu_list_abs "${globexpr}")
endif()
endforeach()
if(ARGS_DESKTOPFILES OR ARGS_GSETTINGSFILES)
find_package(Intltool REQUIRED)
endif()
set(desktop_list)
set(desktop_list_abs)
set(desktop_list_b)
set(desktop_list_b_abs)
set(desktop_list_h)
set(desktop_list_h_abs)
foreach(globexpr ${ARGS_DESKTOPFILES})
if(NOT IS_ABSOLUTE "${globexpr}")
get_filename_component(absDir "${ARGS_WORKING_DIRECTORY}" ABSOLUTE)
set(globexpr "${absDir}/${globexpr}")
endif()
set(tmpdesktopfiles)
file(GLOB tmpdesktopfiles ${globexpr})
if (tmpdesktopfiles)
foreach(absFile ${tmpdesktopfiles})
file(RELATIVE_PATH relFile "${CMAKE_CURRENT_SOURCE_DIR}" "${absFile}")
list(APPEND desktop_list "${relFile}")
list(APPEND desktop_list_abs "${absFile}")
file(RELATIVE_PATH relFile_b "${PROJECT_SOURCE_DIR}" "${absFile}")
list(APPEND desktop_list_b "${relFile_b}")
get_filename_component(absFile_b "${PROJECT_BINARY_DIR}/${relFile_b}" ABSOLUTE)
list(APPEND desktop_list_b_abs "${absFile_b}")
file(RELATIVE_PATH relFile_h "${CMAKE_CURRENT_SOURCE_DIR}" "${absFile_b}.h")
list(APPEND desktop_list_h "${relFile_h}")
list(APPEND desktop_list_h_abs "${absFile_b}.h")
add_custom_command(
OUTPUT
"${absFile_b}"
COMMAND
"${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/${relFile}" "${absFile_b}"
DEPENDS
"${absFile}"
VERBATIM
)
endforeach()
else()
file(RELATIVE_PATH relFile "${CMAKE_CURRENT_SOURCE_DIR}" "${globexpr}")
list(APPEND desktop_list "${relFile}")
list(APPEND desktop_list_abs "${globexpr}")
file(RELATIVE_PATH relFile_b "${PROJECT_SOURCE_DIR}" "${globexpr}")
list(APPEND desktop_list_b "${relFile_b}")
get_filename_component(absFile_b "${PROJECT_BINARY_DIR}/${relFile_b}" ABSOLUTE)
list(APPEND desktop_list_b_abs "${absFile_b}")
file(RELATIVE_PATH relFile_h "${CMAKE_CURRENT_SOURCE_DIR}" "${absFile_b}.h")
list(APPEND desktop_list_h "${relFile_h}")
list(APPEND desktop_list_h_abs "${absFile_b}.h")
add_custom_command(
OUTPUT
"${absFile_b}"
COMMAND
"${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/${relFile}" "${absFile_b}"
DEPENDS
"${absFile}"
VERBATIM
)
endif()
endforeach()
set(_INTLTOOL_DESKTOPFILES ${desktop_list_b})
set(gsettings_list)
set(gsettings_list_abs)
set(gsettings_list_b)
set(gsettings_list_b_abs)
set(gsettings_list_h)
set(gsettings_list_h_abs)
foreach(globexpr ${ARGS_GSETTINGSFILES})
if(NOT IS_ABSOLUTE "${globexpr}")
get_filename_component(absDir "${ARGS_WORKING_DIRECTORY}" ABSOLUTE)
set(globexpr "${absDir}/${globexpr}")
endif()
set(tmpgsettingsfiles)
file(GLOB tmpgsettingsfiles ${globexpr})
if (tmpgsettingsfiles)
foreach(absFile ${tmpgsettingsfiles})
file(RELATIVE_PATH relFile "${CMAKE_CURRENT_SOURCE_DIR}" "${absFile}")
list(APPEND gsettings_list "${relFile}")
list(APPEND gsettings_list_abs "${absFile}")
file(RELATIVE_PATH relFile_b "${PROJECT_SOURCE_DIR}" "${absFile}")
list(APPEND gsettings_list_b "${relFile_b}")
get_filename_component(absFile_b "${PROJECT_BINARY_DIR}/${relFile_b}" ABSOLUTE)
list(APPEND gsettings_list_b_abs "${absFile_b}")
file(RELATIVE_PATH relFile_h "${CMAKE_CURRENT_SOURCE_DIR}" "${absFile_b}.h")
list(APPEND gsettings_list_h "${relFile_h}")
list(APPEND gsettings_list_h_abs "${absFile_b}.h")
add_custom_command(
OUTPUT
"${absFile_b}"
COMMAND
"${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/${relFile}" "${absFile_b}"
DEPENDS
"${absFile}"
VERBATIM
)
endforeach()
else()
file(RELATIVE_PATH relFile "${CMAKE_CURRENT_SOURCE_DIR}" "${globexpr}")
list(APPEND gsettings_list "${relFile}")
list(APPEND gsettings_list_abs "${globexpr}")
file(RELATIVE_PATH relFile_b "${PROJECT_SOURCE_DIR}" "${globexpr}")
list(APPEND gsettings_list_b "${relFile_b}")
get_filename_component(absFile_b "${PROJECT_BINARY_DIR}/${relFile_b}" ABSOLUTE)
list(APPEND gsettings_list_b_abs "${absFile_b}")
file(RELATIVE_PATH relFile_h "${CMAKE_CURRENT_SOURCE_DIR}" "${absFile_b}.h")
list(APPEND gsettings_list_h "${relFile_h}")
list(APPEND gsettings_list_h_abs "${absFile_b}.h")
add_custom_command(
OUTPUT
"${absFile_b}"
COMMAND
"${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/${relFile}" "${absFile_b}"
VERBATIM
)
endif()
endforeach()
if(ARGS_SRCFILES)
add_custom_command(
OUTPUT
"${CMAKE_CURRENT_BINARY_DIR}/_source.pot"
COMMAND
"${XGETTEXT_EXECUTABLE}" ${xgettext_options} ${xgettext_vala_options} "-o" "${CMAKE_CURRENT_BINARY_DIR}/_source.pot" ${src_list}
COMMAND
# Make sure file exists even if no translatable strings available.
"${CMAKE_COMMAND}" -E touch "${CMAKE_CURRENT_BINARY_DIR}/_source.pot"
DEPENDS
${src_list_abs}
WORKING_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}"
VERBATIM
)
else()
add_custom_command(
OUTPUT
"${CMAKE_CURRENT_BINARY_DIR}/_source.pot"
COMMAND
"${CMAKE_COMMAND}" -E touch "${CMAKE_CURRENT_BINARY_DIR}/_source.pot"
VERBATIM
)
endif()
if(ARGS_GLADEFILES)
add_custom_command(
OUTPUT
"${CMAKE_CURRENT_BINARY_DIR}/_glade.pot"
COMMAND
"${XGETTEXT_EXECUTABLE}" ${xgettext_options} ${xgettext_glade_options} "-o" "${CMAKE_CURRENT_BINARY_DIR}/_glade.pot" ${glade_list}
COMMAND
"${CMAKE_COMMAND}" -E touch "${CMAKE_CURRENT_BINARY_DIR}/_glade.pot"
DEPENDS
${glade_list_abs}
WORKING_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}"
VERBATIM
)
else()
add_custom_command(
OUTPUT
"${CMAKE_CURRENT_BINARY_DIR}/_glade.pot"
COMMAND
"${CMAKE_COMMAND}" -E touch "${CMAKE_CURRENT_BINARY_DIR}/_glade.pot"
VERBATIM
)
endif()
if(ARGS_TEXTMENUFILES)
add_custom_command(
OUTPUT
"${CMAKE_CURRENT_BINARY_DIR}/_ftmenu.pot"
COMMAND
"${XGETTEXT_EXECUTABLE}" ${xgettext_options} ${xgettext_ftmenu_options} "-o" "${CMAKE_CURRENT_BINARY_DIR}/_ftmenu.pot" ${ftmenu_list}
COMMAND
"${CMAKE_COMMAND}" -E touch "${CMAKE_CURRENT_BINARY_DIR}/_ftmenu.pot"
DEPENDS
${ftmenu_list_abs}
WORKING_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}"
VERBATIM
)
else()
add_custom_command(
OUTPUT
"${CMAKE_CURRENT_BINARY_DIR}/_ftmenu.pot"
COMMAND
"${CMAKE_COMMAND}" -E touch "${CMAKE_CURRENT_BINARY_DIR}/_ftmenu.pot"
VERBATIM
)
endif()
if(ARGS_DESKTOPFILES)
add_custom_command(
OUTPUT
${desktop_list_h_abs}
COMMAND
"${INTLTOOL_EXTRACT_EXECUTABLE}" ${INTLTOOL_OPTIONS_DEFAULT} "--type" "gettext/ini" ${desktop_list_b}
DEPENDS
${desktop_list_b_abs}
WORKING_DIRECTORY
"${PROJECT_BINARY_DIR}"
VERBATIM
)
add_custom_command(
OUTPUT
"${CMAKE_CURRENT_BINARY_DIR}/_desktop.pot"
COMMAND
"${XGETTEXT_EXECUTABLE}" ${xgettext_options} ${XGETTEXT_INTLTOOL_OPTIONS} "-o" "${CMAKE_CURRENT_BINARY_DIR}/_desktop.pot" ${desktop_list_h}
COMMAND
"${CMAKE_COMMAND}" -E touch "${CMAKE_CURRENT_BINARY_DIR}/_desktop.pot"
DEPENDS
${desktop_list_h_abs}
WORKING_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}"
VERBATIM
)
else()
add_custom_command(
OUTPUT
"${CMAKE_CURRENT_BINARY_DIR}/_desktop.pot"
COMMAND
"${CMAKE_COMMAND}" -E touch "${CMAKE_CURRENT_BINARY_DIR}/_desktop.pot"
VERBATIM
)
endif()
if(ARGS_GSETTINGSFILES)
add_custom_command(
OUTPUT
${gsettings_list_h_abs}
COMMAND
"${INTLTOOL_EXTRACT_EXECUTABLE}" ${INTLTOOL_OPTIONS_DEFAULT} "--type" "gettext/gsettings" ${gsettings_list_b}
DEPENDS
${gsettings_list_b_abs}
WORKING_DIRECTORY
"${PROJECT_BINARY_DIR}"
VERBATIM
)
add_custom_command(
OUTPUT
"${CMAKE_CURRENT_BINARY_DIR}/_gsettings.pot"
COMMAND
"${XGETTEXT_EXECUTABLE}" ${xgettext_options} ${XGETTEXT_INTLTOOL_OPTIONS} "-o" "${CMAKE_CURRENT_BINARY_DIR}/_gsettings.pot" ${gsettings_list_h}
COMMAND
"${CMAKE_COMMAND}" -E touch "${CMAKE_CURRENT_BINARY_DIR}/_gsettings.pot"
DEPENDS
${gsettings_list_h_abs}
WORKING_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}"
VERBATIM
)
else()
add_custom_command(
OUTPUT
"${CMAKE_CURRENT_BINARY_DIR}/_gsettings.pot"
COMMAND
"${CMAKE_COMMAND}" -E touch "${CMAKE_CURRENT_BINARY_DIR}/_gsettings.pot"
VERBATIM
)
endif()
add_custom_target(pot
COMMAND
"${GETTEXT_MSGCAT_EXECUTABLE}" "-o" "${potfile}" "--use-first" "${CMAKE_CURRENT_BINARY_DIR}/_source.pot" "${CMAKE_CURRENT_BINARY_DIR}/_glade.pot" "${CMAKE_CURRENT_BINARY_DIR}/_ftmenu.pot" "${CMAKE_CURRENT_BINARY_DIR}/_desktop.pot" "${CMAKE_CURRENT_BINARY_DIR}/_gsettings.pot"
DEPENDS
"${CMAKE_CURRENT_BINARY_DIR}/_source.pot"
"${CMAKE_CURRENT_BINARY_DIR}/_glade.pot"
"${CMAKE_CURRENT_BINARY_DIR}/_ftmenu.pot"
"${CMAKE_CURRENT_BINARY_DIR}/_desktop.pot"
"${CMAKE_CURRENT_BINARY_DIR}/_gsettings.pot"
WORKING_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT
"Extract translatable messages to ${potfile}"
VERBATIM
)
endif()
endmacro()
function(gettext_create_translations potfile)
cmake_parse_arguments(ARGS "ALL;NOUPDATE;DESKTOPFILES_INSTALL"
"PODIR;LOCALEDIR" "LANGUAGES;POFILES" ${ARGN})
get_filename_component(_potBasename "${potfile}" NAME_WE)
get_filename_component(_absPotFile "${potfile}" ABSOLUTE)
if(ARGS_ALL)
set(make_all "ALL")
else()
set(make_all)
endif()
if(ARGS_LOCALEDIR)
set(_localedir "${ARGS_LOCALEDIR}")
elseif(localedir)
set(_localedir "${localedir}")
else()
set(_localedir "share/locale")
endif()
set(langs)
list(APPEND langs ${ARGS_LANGUAGES})
foreach(globexpr ${ARGS_POFILES})
set(tmppofiles)
file(GLOB tmppofiles ${globexpr})
if(tmppofiles)
foreach(tmppofile ${tmppofiles})
string(REGEX REPLACE ".*/([a-zA-Z_]+)(\\.po)?$" "\\1" lang "${tmppofile}")
list(APPEND langs "${lang}")
endforeach()
else()
string(REGEX REPLACE ".*/([a-zA-Z_]+)(\\.po)?$" "\\1" lang "${globexpr}")
list(APPEND langs "${lang}")
endif()
endforeach()
if(NOT langs AND NOT ARGS_PODIR)
set(ARGS_PODIR "${CMAKE_CURRENT_SOURCE_DIR}")
endif()
if(ARGS_PODIR)
file(GLOB pofiles "${ARGS_PODIR}/*.po")
foreach(pofile ${pofiles})
string(REGEX REPLACE ".*/([a-zA-Z_]+)\\.po$" "\\1" lang "${pofile}")
list(APPEND langs "${lang}")
endforeach()
endif()
if(langs)
list(REMOVE_DUPLICATES langs)
endif()
set(_gmoFile)
set(_gmoFiles)
foreach (lang ${langs})
get_filename_component(_absFile "${lang}.po" ABSOLUTE)
set(_gmoFile "${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo")
if(ARGS_NOUPDATE)
set(_absFile_new "${CMAKE_CURRENT_BINARY_DIR}/${lang}.po")
add_custom_command(
OUTPUT
"${_absFile_new}"
COMMAND
"${CMAKE_COMMAND}" -E copy "${_absFile}" "${_absFile_new}"
DEPENDS
"${_absPotFile}"
"${_absFile}"
VERBATIM
)
set(_absFile "${_absFile_new}")
endif()
add_custom_command(
OUTPUT
"${_gmoFile}"
COMMAND
"${GETTEXT_MSGMERGE_EXECUTABLE}" "--quiet" "--update" "--backup=none" "-s" "${_absFile}" "${_absPotFile}"
COMMAND
"${GETTEXT_MSGFMT_EXECUTABLE}" "-o" "${_gmoFile}" "${_absFile}"
DEPENDS
"${_absPotFile}"
"${_absFile}"
WORKING_DIRECTORY
"${CMAKE_CURRENT_BINARY_DIR}"
VERBATIM
)
install(
FILES
"${_gmoFile}"
DESTINATION
"${_localedir}/${lang}/LC_MESSAGES"
RENAME
"${_potBasename}.mo"
)
list(APPEND _gmoFiles "${_gmoFile}")
endforeach()
set(desktopfiles)
if(langs AND _INTLTOOL_DESKTOPFILES)
file(RELATIVE_PATH cursrcdir_rel "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}")
if(cursrcdir_rel STREQUAL "")
set(cursrcdir_rel ".")
endif()
foreach(desktopfiletmp ${_INTLTOOL_DESKTOPFILES})
string(REGEX REPLACE "(\\.desktop).*$" "\\1" desktopfile "${desktopfiletmp}")
set(desktopfile_abs "${PROJECT_BINARY_DIR}/${desktopfile}")
list(APPEND desktopfiles "${desktopfile_abs}")
file(RELATIVE_PATH desktopfile_rel "${CMAKE_CURRENT_BINARY_DIR}" "${desktopfile_abs}")
file(RELATIVE_PATH desktopfiletmp_rel "${CMAKE_CURRENT_BINARY_DIR}" "${PROJECT_BINARY_DIR}/${desktopfiletmp}")
add_custom_command(
OUTPUT
"${desktopfile_abs}"
COMMAND
"${INTLTOOL_MERGE_EXECUTABLE}" ${INTLTOOL_OPTIONS_DEFAULT} "--desktop-style" "${cursrcdir_rel}" "${desktopfiletmp_rel}" "${desktopfile_rel}"
DEPENDS
"${PROJECT_BINARY_DIR}/${desktopfiletmp}"
VERBATIM
)
if(ARGS_DESKTOPFILES_INSTALL AND NOT cursrcdir_rel STREQUAL ".")
add_custom_command(
OUTPUT
"${CMAKE_SOURCE_DIR}/${desktopfile}"
"desktopinstall.stamp"
COMMAND
"${CMAKE_COMMAND}" -E copy_if_different "${desktopfile_abs}" "${CMAKE_SOURCE_DIR}/${desktopfile}"
COMMAND
"${CMAKE_COMMAND}" -E touch "desktopinstall.stamp"
DEPENDS
"${desktopfile_abs}"
VERBATIM
)
else()
add_custom_command(
OUTPUT
"desktopinstall.stamp"
COMMAND
"${CMAKE_COMMAND}" -E touch "desktopinstall.stamp"
DEPENDS
"${desktopfile_abs}"
VERBATIM
)
endif()
list(APPEND desktopfiles "desktopinstall.stamp")
install(
FILES
"${desktopfile_abs}"
DESTINATION
"share/applications"
)
endforeach()
endif()
add_custom_target(translations
"${make_all}"
DEPENDS
${_gmoFiles}
${desktopfiles}
COMMENT
"Build translations."
)
endfunction()
endif()
# vim: set ai ts=2 sts=2 et sw=2