"Fossies" - the Fresh Open Source Software Archive

Member "evolution-mapi-3.46.1/cmake/modules/FindIntltool.cmake" (2 Dec 2022, 8256 Bytes) of package /linux/misc/evolution-mapi-3.46.1.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) CMake source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 # FindIntltool.cmake
    2 #
    3 # Searches for intltool and gettext. It aborts, if anything cannot be found.
    4 # Requires GETTEXT_PO_DIR to be set to full path of the po/ directory.
    5 #
    6 # Output is:
    7 #   INTLTOOL_UPDATE  - an intltool-update executable path, as found
    8 #   INTLTOOL_EXTRACT  - an intltool-extract executable path, as found
    9 #   INTLTOOL_MERGE  - an intltool-merge executable path, as found
   10 #
   11 # and anything from the FindGettext module.
   12 #
   13 # The below provided macros require GETTEXT_PACKAGE to be set.
   14 #
   15 # intltool_add_check_potfiles_target()
   16 #    Adds a check-potfiles target, which verifies that all files with translations
   17 #    are added in the POTFILES.in file inside GETTEXT_PO_DIR. This macro can be called
   18 #    only inside GETTEXT_PO_DIR.
   19 #
   20 # intltool_add_pot_file_target()
   21 #    Creates a new target pot-file, which generates ${GETTEXT_PACKAGE}.pot file into
   22 #    the CMAKE_CURERNT_BINARY_DIR. This target is not part of ALL.
   23 #    This can be called only inside GETTEXT_PO_DIR.
   24 #
   25 # intltool_process_po_files()
   26 #    Processes all files in the GETTEXT_PO_DIR and generates .gmo files for them
   27 #    in CMAKE_CURRENT_BINARY_DIR. These are added into a new target gmo-files.
   28 #    It also installs them into proper location under LOCALE_INSTALL_DIR.
   29 #    This can be called only inside GETTEXT_PO_DIR.
   30 #
   31 # intltool_setup_po_dir()
   32 #    Shortcut to setup intltool's po/ directory by adding all custom targets
   33 #    and such. this can be called only inside GETTEXT_PO_DIR.
   34 #
   35 # intltool_merge(_in_filename _out_filename ...args)
   36 #    Adds rule to call intltool-merge. The args are optional arguments.
   37 #    This can be called in any folder, only the GETTEXT_PO_DIR should
   38 #    be properly set, otherwise the call will fail.
   39 #
   40 # add_appdata_file(_infilename _outfilename)
   41 #    A shortcut to call intltool-merge() for an appdata file and install it
   42 #    to ${SHARE_INSTALL_PREFIX}/metainfo
   43 
   44 include(FindGettext)
   45 
   46 if(NOT GETTEXT_FOUND)
   47     message(FATAL_ERROR "gettext not found, please install at least 0.18.3 version")
   48 endif(NOT GETTEXT_FOUND)
   49 
   50 if(GETTEXT_VERSION_STRING VERSION_LESS "0.18.3")
   51     message(FATAL_ERROR "gettext version 0.18.3+ required, but version '${GETTEXT_VERSION_STRING}' found instead. Please update your gettext")
   52 endif(GETTEXT_VERSION_STRING VERSION_LESS "0.18.3")
   53 
   54 find_program(XGETTEXT xgettext)
   55 if(NOT XGETTEXT)
   56     message(FATAL_ERROR "xgettext executable not found. Please install or update your gettext to at least 0.18.3 version")
   57 endif(NOT XGETTEXT)
   58 
   59 find_program(INTLTOOL_UPDATE intltool-update)
   60 if(NOT INTLTOOL_UPDATE)
   61     message(FATAL_ERROR "intltool-update not found. Please install it (usually part of an 'intltool' package)")
   62 endif(NOT INTLTOOL_UPDATE)
   63 
   64 find_program(INTLTOOL_EXTRACT intltool-extract)
   65 if(NOT INTLTOOL_EXTRACT)
   66     message(FATAL_ERROR "intltool-extract not found. Please install it (usually part of an 'intltool' package)")
   67 endif(NOT INTLTOOL_EXTRACT)
   68 
   69 find_program(INTLTOOL_MERGE intltool-merge)
   70 if(NOT INTLTOOL_MERGE)
   71     message(FATAL_ERROR "intltool-merge not found. Please install it (usually part of an 'intltool' package)")
   72 endif(NOT INTLTOOL_MERGE)
   73 
   74 macro(intltool_add_check_potfiles_target)
   75     if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL GETTEXT_PO_DIR)
   76         message(FATAL_ERROR "intltool_add_pot_file_target() can be called only inside GETTEXT_PO_DIR ('${GETTEXT_PO_DIR}'), but it is called inside '${CMAKE_CURRENT_SOURCE_DIR}' instead")
   77     endif(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL GETTEXT_PO_DIR)
   78 
   79     add_custom_target(check-potfiles
   80         COMMAND ${INTLTOOL_UPDATE} -m
   81         WORKING_DIRECTORY ${GETTEXT_PO_DIR}
   82     )
   83 endmacro(intltool_add_check_potfiles_target)
   84 
   85 macro(intltool_add_pot_file_target)
   86     if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL GETTEXT_PO_DIR)
   87         message(FATAL_ERROR "intltool_add_pot_file_target() can be called only inside GETTEXT_PO_DIR ('${GETTEXT_PO_DIR}'), but it is called inside '${CMAKE_CURRENT_SOURCE_DIR}' instead")
   88     endif(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL GETTEXT_PO_DIR)
   89 
   90     add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${GETTEXT_PACKAGE}.pot
   91         COMMAND ${CMAKE_COMMAND} -E env INTLTOOL_EXTRACT="${INTLTOOL_EXTRACT}" XGETTEXT="${XGETTEXT}" srcdir=${CMAKE_CURRENT_SOURCE_DIR} ${INTLTOOL_UPDATE} --gettext-package ${GETTEXT_PACKAGE} --pot
   92     )
   93 
   94     add_custom_target(pot-file
   95         DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${GETTEXT_PACKAGE}.pot
   96     )
   97 endmacro(intltool_add_pot_file_target)
   98 
   99 macro(intltool_process_po_files)
  100     if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL GETTEXT_PO_DIR)
  101         message(FATAL_ERROR "intltool_process_po_files() can be called only inside GETTEXT_PO_DIR ('${GETTEXT_PO_DIR}'), but it is called inside '${CMAKE_CURRENT_SOURCE_DIR}' instead")
  102     endif(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL GETTEXT_PO_DIR)
  103 
  104     file(GLOB po_files ${GETTEXT_PO_DIR}/*.po)
  105 
  106     set(LINGUAS)
  107     set(LINGUAS_GMO)
  108 
  109     foreach(file IN LISTS po_files)
  110         get_filename_component(lang ${file} NAME_WE)
  111         list(APPEND LINGUAS ${lang})
  112         list(APPEND LINGUAS_GMO ${lang}.gmo)
  113 
  114         add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo
  115             COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo ${CMAKE_CURRENT_SOURCE_DIR}/${lang}.po
  116             DEPENDS ${lang}.po
  117         )
  118 
  119         install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo
  120             DESTINATION ${LOCALE_INSTALL_DIR}/${lang}/LC_MESSAGES/
  121             RENAME ${GETTEXT_PACKAGE}.mo
  122         )
  123         if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo.m)
  124             install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo.m
  125                 DESTINATION ${LOCALE_INSTALL_DIR}/${lang}/LC_MESSAGES/
  126                 RENAME ${GETTEXT_PACKAGE}.mo.m
  127             )
  128         endif(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo.m)
  129     endforeach(file)
  130 
  131     add_custom_target(gmo-files ALL
  132         DEPENDS ${LINGUAS_GMO}
  133     )
  134 endmacro(intltool_process_po_files)
  135 
  136 macro(intltool_setup_po_dir)
  137     if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL GETTEXT_PO_DIR)
  138         message(FATAL_ERROR "intltool_setup_po_dir() can be called only inside GETTEXT_PO_DIR ('${GETTEXT_PO_DIR}'), but it is called inside '${CMAKE_CURRENT_SOURCE_DIR}' instead")
  139     endif(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL GETTEXT_PO_DIR)
  140 
  141     intltool_add_check_potfiles_target()
  142     intltool_add_pot_file_target()
  143     intltool_process_po_files()
  144 endmacro(intltool_setup_po_dir)
  145 
  146 macro(intltool_merge _in_filename _out_filename)
  147     set(_in ${_in_filename})
  148     set(_out ${_out_filename})
  149 
  150     get_filename_component(_path ${_in} DIRECTORY)
  151     if(_path STREQUAL "")
  152         set(_in ${CMAKE_CURRENT_SOURCE_DIR}/${_in})
  153     endif(_path STREQUAL "")
  154 
  155     get_filename_component(_path ${_out} DIRECTORY)
  156     if(_path STREQUAL "")
  157         set(_out ${CMAKE_CURRENT_BINARY_DIR}/${_out})
  158     endif(_path STREQUAL "")
  159 
  160     set(_has_no_translations OFF)
  161     set(_args)
  162     foreach(_arg ${ARGN})
  163         list(APPEND _args "${_arg}")
  164         if(_arg STREQUAL "--no-translations")
  165             set(_has_no_translations ON)
  166         endif(_arg STREQUAL "--no-translations")
  167     endforeach(_arg)
  168 
  169     if(_has_no_translations)
  170         add_custom_command(OUTPUT ${_out}
  171             COMMAND ${INTLTOOL_MERGE} ${_args} --quiet "${_in}" "${_out}"
  172             DEPENDS ${_in}
  173         )
  174     else(_has_no_translations)
  175         if(NOT TARGET intltool-merge-cache)
  176             add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/po/.intltool-merge-cache
  177                 COMMAND ${INTLTOOL_MERGE} ${_args} --quiet --cache="${CMAKE_BINARY_DIR}/po/.intltool-merge-cache" "${GETTEXT_PO_DIR}" "${_in}" "${_out}"
  178                 DEPENDS ${_in}
  179             )
  180             add_custom_target(intltool-merge-cache ALL
  181                 DEPENDS ${CMAKE_BINARY_DIR}/po/.intltool-merge-cache)
  182         endif(NOT TARGET intltool-merge-cache)
  183 
  184         add_custom_command(OUTPUT ${_out}
  185             COMMAND ${INTLTOOL_MERGE} ${_args} --quiet --cache="${CMAKE_BINARY_DIR}/po/.intltool-merge-cache" "${GETTEXT_PO_DIR}" "${_in}" "${_out}"
  186             DEPENDS ${_in} intltool-merge-cache
  187         )
  188     endif(_has_no_translations)
  189 endmacro(intltool_merge)
  190 
  191 macro(add_appdata_file _infilename _outfilename)
  192     if(NOT TARGET appdata-files)
  193         add_custom_target(appdata-files ALL)
  194     endif(NOT TARGET appdata-files)
  195 
  196     set(_out ${_outfilename})
  197     get_filename_component(_outtarget ${_out} NAME)
  198     get_filename_component(_path ${_out} DIRECTORY)
  199     if(_path STREQUAL "")
  200         set(_out ${CMAKE_CURRENT_BINARY_DIR}/${_out})
  201     endif(_path STREQUAL "")
  202 
  203     intltool_merge(${_infilename} ${_out} --xml-style --utf8)
  204 
  205     add_custom_target(appdata-${_outtarget}
  206         DEPENDS ${_out}
  207     )
  208 
  209     add_dependencies(appdata-files appdata-${_outtarget})
  210 
  211     install(FILES ${_out}
  212         DESTINATION ${SHARE_INSTALL_PREFIX}/metainfo
  213     )
  214 endmacro(add_appdata_file)