]> git.saurik.com Git - apt.git/blobdiff - CMake/Translations.cmake
This is 2016 and APT already requires use of mmap.
[apt.git] / CMake / Translations.cmake
index 584c5c5afe0831837c8ed6df6d833279d0cdd92b..79f2633a79534ef001484dd5ba3b8c9a96e8d55f 100644 (file)
@@ -4,13 +4,14 @@
 function(apt_add_translation_domain)
     set(options)
     set(oneValueArgs DOMAIN)
-    set(multiValueArgs TARGETS SCRIPTS)
+    set(multiValueArgs TARGETS SCRIPTS EXCLUDE_LANGUAGES)
     cmake_parse_arguments(NLS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
     # Build the list of source files of the target
     set(files "")
     set(abs_files "")
     set(scripts "")
     set(abs_scripts "")
+    set(mofiles)
     set(targets ${NLS_TARGETS})
     set(domain ${NLS_DOMAIN})
     set(xgettext_params
@@ -21,13 +22,7 @@ function(apt_add_translation_domain)
         --msgid-bugs-address=${PACKAGE_MAIL}
     )
     foreach(source ${NLS_SCRIPTS})
-            string(SUBSTRING ${source} 0 1 init_char)
-            string(COMPARE EQUAL ${init_char} "/" is_absolute)
-            if (${is_absolute})
-                set(file "${source}")
-            else()
-                set(file "${CMAKE_CURRENT_SOURCE_DIR}/${source}")
-            endif()
+            path_join(file "${CMAKE_CURRENT_SOURCE_DIR}" "${source}")
             file(RELATIVE_PATH relfile ${PROJECT_SOURCE_DIR} ${file})
             list(APPEND scripts ${relfile})
             list(APPEND abs_scripts ${file})
@@ -36,13 +31,7 @@ function(apt_add_translation_domain)
         get_target_property(source_dir ${target} SOURCE_DIR)
         get_target_property(sources ${target} SOURCES)
         foreach(source ${sources})
-            string(SUBSTRING ${source} 0 1 init_char)
-            string(COMPARE EQUAL ${init_char} "/" is_absolute)
-            if (${is_absolute})
-                set(file "${source}")
-            else()
-                set(file "${source_dir}/${source}")
-            endif()
+            path_join(file "${source_dir}" "${source}")
             file(RELATIVE_PATH relfile ${PROJECT_SOURCE_DIR} ${file})
             set(files ${files} ${relfile})
             set(abs_files ${abs_files} ${file})
@@ -54,7 +43,7 @@ function(apt_add_translation_domain)
     if("${scripts}" STREQUAL "")
         set(sh_pot "/dev/null")
     else()
-        set(sh_pot ${PROJECT_BINARY_DIR}/${domain}.sh.pot)
+        set(sh_pot ${CMAKE_CURRENT_BINARY_DIR}/${domain}.sh.pot)
         # Create the template for this specific sub-domain
         add_custom_command (OUTPUT ${sh_pot}
             COMMAND xgettext ${xgettext_params} -L Shell
@@ -66,10 +55,10 @@ function(apt_add_translation_domain)
     endif()
 
 
-    add_custom_command (OUTPUT ${PROJECT_BINARY_DIR}/${domain}.c.pot
+    add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${domain}.c.pot
         COMMAND xgettext ${xgettext_params} -k_ -kN_
                          --keyword=P_:1,2
-                         -o ${PROJECT_BINARY_DIR}/${domain}.c.pot ${files}
+                         -o ${CMAKE_CURRENT_BINARY_DIR}/${domain}.c.pot ${files}
         DEPENDS ${abs_files}
         VERBATIM
         WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
@@ -79,40 +68,46 @@ function(apt_add_translation_domain)
     # build a ${domain.pot}-tmp as a byproduct. The msgfmt command than depend
     # on the byproduct while their target depends on the output, so that msgfmt
     # does not have to be rerun if nothing in the template changed.
-    add_custom_command (OUTPUT ${PROJECT_BINARY_DIR}/${domain}.pot
-        BYPRODUCTS ${PROJECT_BINARY_DIR}/${domain}.pot-tmp
-        COMMAND msgcomm --more-than=0 --sort-by-file
+    #
+    # Make sure the .pot-tmp has no line numbers, to avoid useless rebuilding
+    # of .mo files.
+    add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot
+        BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot-tmp
+        COMMAND msgcomm --more-than=0 --omit-header --sort-by-file --add-location=file
                          ${sh_pot}
-                         ${PROJECT_BINARY_DIR}/${domain}.c.pot
-                         --output=${PROJECT_BINARY_DIR}/${domain}.pot
-        COMMAND msgcomm --more-than=0 --omit-header --sort-by-file
+                         ${CMAKE_CURRENT_BINARY_DIR}/${domain}.c.pot
+                         --output=${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot-tmp0
+        COMMAND msgcomm --more-than=0 --sort-by-file
                          ${sh_pot}
-                         ${PROJECT_BINARY_DIR}/${domain}.c.pot
-                         --output=${PROJECT_BINARY_DIR}/${domain}.pot-tmp0
+                         ${CMAKE_CURRENT_BINARY_DIR}/${domain}.c.pot
+                         --output=${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot
         COMMAND cmake -E copy_if_different
-                         ${PROJECT_BINARY_DIR}/${domain}.pot-tmp0
-                         ${PROJECT_BINARY_DIR}/${domain}.pot-tmp
+                         ${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot-tmp0
+                         ${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot-tmp
         DEPENDS ${sh_pot}
-                ${PROJECT_BINARY_DIR}/${domain}.c.pot
+                ${CMAKE_CURRENT_BINARY_DIR}/${domain}.c.pot
         WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
     )
 
     # We need a target to depend on otherwise, the msgmerge might not get called
     # with the make generator
-    add_custom_target(nls-${domain}-template DEPENDS ${PROJECT_BINARY_DIR}/${domain}.pot)
+    add_custom_target(nls-${domain}-template DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot)
 
     # Build .mo files
     file(GLOB translations "${PROJECT_SOURCE_DIR}/po/*.po")
     list(SORT translations)
     foreach(file ${translations})
         get_filename_component(langcode ${file} NAME_WE)
-        set(outdir ${PROJECT_BINARY_DIR}/locale/${langcode}/LC_MESSAGES)
+        if ("${langcode}" IN_LIST NLS_EXCLUDE_LANGUAGES)
+            continue()
+        endif()
+        set(outdir ${CMAKE_CURRENT_BINARY_DIR}/locale/${langcode}/LC_MESSAGES)
         file(MAKE_DIRECTORY ${outdir})
         # Command to merge and compile the messages. As explained in the custom
         # command for msgcomm, this depends on byproduct to avoid reruns
         add_custom_command(OUTPUT ${outdir}/${domain}.po
-            COMMAND msgmerge -qo ${outdir}/${domain}.po ${file} ${PROJECT_BINARY_DIR}/${domain}.pot-tmp
-            DEPENDS ${file} ${PROJECT_BINARY_DIR}/${domain}.pot-tmp
+            COMMAND msgmerge -qo ${outdir}/${domain}.po ${file} ${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot-tmp
+            DEPENDS ${file} ${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot-tmp
         )
         add_custom_command(OUTPUT ${outdir}/${domain}.mo
             COMMAND msgfmt --statistics -o ${outdir}/${domain}.mo  ${outdir}/${domain}.po
@@ -131,11 +126,11 @@ endfunction()
 function(apt_add_update_po)
     set(options)
     set(oneValueArgs TEMPLATE)
-    set(multiValueArgs DOMAINS)
+    set(multiValueArgs DOMAINS EXCLUDE_LANGUAGES)
     cmake_parse_arguments(NLS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
     set(output ${CMAKE_CURRENT_SOURCE_DIR}/${NLS_TEMPLATE}.pot)
     foreach(domain ${NLS_DOMAINS})
-        list(APPEND potfiles ${PROJECT_BINARY_DIR}/${domain}.pot)
+        list(APPEND potfiles ${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot)
     endforeach()
 
     get_filename_component(master_name ${output} NAME_WE)
@@ -151,8 +146,11 @@ function(apt_add_update_po)
     endif()
     foreach(translation ${translations})
             get_filename_component(langcode ${translation} NAME_WE)
+            if ("${langcode}" IN_LIST NLS_EXCLUDE_LANGUAGES)
+                continue()
+            endif()
             add_custom_target(update-po-${langcode}
-                COMMAND msgmerge -q --update --backup=none ${translation} ${output}
+                COMMAND msgmerge -q --previous --update --backup=none ${translation} ${output}
                 DEPENDS nls-${master_name}
             )
             add_dependencies(update-po update-po-${langcode})
@@ -160,14 +158,23 @@ function(apt_add_update_po)
     add_dependencies(update-po nls-${master_name})
 endfunction()
 
-function(apt_add_po_statistics)
+function(apt_add_po_statistics excluded)
     add_custom_target(statistics)
     file(GLOB translations "${PROJECT_SOURCE_DIR}/po/*.po")
     foreach(translation ${translations})
             get_filename_component(langcode ${translation} NAME_WE)
+            if ("${langcode}" IN_LIST excluded)
+                add_custom_command(
+                    TARGET statistics PRE_BUILD
+                    COMMAND printf "%-6s " "${langcode}:"
+                    COMMAND echo "ignored"
+                    VERBATIM
+                )
+                continue()
+            endif()
             add_custom_command(
                 TARGET statistics PRE_BUILD
-                COMMAND printf "%-7s" "${langcode}:"
+                COMMAND printf "%-6s " "${langcode}:"
                 COMMAND msgfmt --statistics -o /dev/null ${translation}
                 VERBATIM
             )