File: script.cmake

package info (click to toggle)
sdcv 0.5.5-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 596 kB
  • sloc: cpp: 3,082; sh: 226; xml: 23; makefile: 10
file content (103 lines) | stat: -rw-r--r-- 3,013 bytes parent folder | download | duplicates (4)
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
# ----- Set up variables.

# Read variables from the generated config.
include(${CMAKE_ARGV3})

# Transform keywords in to flags.
set(keywordArgs "")
foreach(keyword ${keywords})
  list(APPEND keywordArgs "--keyword=${keyword}")
endforeach()

# ----- Make the pot file.

message("Creating translation template...")

file(MAKE_DIRECTORY ${langDir})

set(potFile "${langDir}/${domain}.pot")

execute_process(COMMAND ${XGETTEXT_EXECUTABLE}
  "--output=${potFile}"
  "--omit-header" "--add-comments"
  ${keywordArgs}
  ${sourceFiles}
  WORKING_DIRECTORY ${sourcePrefix})

message(" '${domain}.pot' done.")

# ----- Copy and merge across the po files that come with the source.

message("Copying and updating stock translations...")

file(GLOB poFiles "${stockDir}/*.po")

foreach(file ${poFiles})
  # Get the language name, like en_US or zh_CN from the name of the po file, so
  # 'en_US.po' or 'zh_CN.po' become 'en_US' or 'zh_CN.po'
  get_filename_component(langName ${file} NAME_WE)
  
  set(newFile "${langDir}/${langName}.po")
  
  if(NOT EXISTS ${newFile})
    execute_process(COMMAND ${MSGMERGE_EXECUTABLE}
      "--output-file" ${newFile} ${file} ${potFile}
      OUTPUT_QUIET ERROR_VARIABLE error RESULT_VARIABLE ret)
    
    if(ret) # Have to do this hack as msgmerge prints to stderr.
      message(SEND_ERROR "${error}")
    endif()
    
    message(" '${langName}' copied.")
  elseif(${file} IS_NEWER_THAN ${newFile})
     execute_process(COMMAND ${MSGMERGE_EXECUTABLE}
       "--update" ${newFile} ${file}
       OUTPUT_QUIET ERROR_VARIABLE error RESULT_VARIABLE ret)
     
     if(ret) # Have to do this hack as msgmerge prints to stderr.
       message(SEND_ERROR "${error}")
     endif()
     
     message(" '${langName}' merged.")
  endif()
endforeach()

# ----- Process the files in to mo files.

message("Compiling translations...")

file(GLOB localPoFiles "${langDir}/*.po")

foreach(file ${localPoFiles})
  execute_process(COMMAND ${MSGMERGE_EXECUTABLE}
    "--update" ${file} ${potFile}
    OUTPUT_QUIET ERROR_VARIABLE error RESULT_VARIABLE ret)
  
  if(ret) # Have to do this hack as msgmerge prints to stderr.
    message(SEND_ERROR "${error}")
  endif()
  
  get_filename_component(langName ${file} NAME_WE)
  
  set(binaryFile "${hierarchy}")
  string(REPLACE "{1}" "${outDir}"   binaryFile "${binaryFile}")
  string(REPLACE "{2}" "${langName}" binaryFile "${binaryFile}")
  string(REPLACE "{3}" "LC_MESSAGES" binaryFile "${binaryFile}")
  string(REPLACE "{4}" "${domain}"   binaryFile "${binaryFile}")
  
  if(${file} IS_NEWER_THAN ${binaryFile})
    get_filename_component(binaryDir ${binaryFile} PATH)
    
    file(MAKE_DIRECTORY ${binaryDir})
    
    execute_process(COMMAND ${MSGFMT_EXECUTABLE}
      ${file} "--output-file" ${binaryFile}
      OUTPUT_QUIET ERROR_VARIABLE error RESULT_VARIABLE ret)
    
    if(ret) # Have to do this hack as msgfmt prints to stderr.
      message(SEND_ERROR "${error}")
    endif()
    
    message(" '${langName}' done.")
  endif()
endforeach()