|
Packit |
0eec03 |
# FindIntltool.cmake
|
|
Packit |
0eec03 |
#
|
|
Packit |
0eec03 |
# Searches for intltool and gettext. It aborts, if anything cannot be found.
|
|
Packit |
0eec03 |
# Requires GETTEXT_PO_DIR to be set to full path of the po/ directory.
|
|
Packit |
0eec03 |
#
|
|
Packit |
0eec03 |
# Output is:
|
|
Packit |
0eec03 |
# INTLTOOL_UPDATE - an intltool-update executable path, as found
|
|
Packit |
0eec03 |
# INTLTOOL_EXTRACT - an intltool-extract executable path, as found
|
|
Packit |
0eec03 |
# INTLTOOL_MERGE - an intltool-merge executable path, as found
|
|
Packit |
0eec03 |
#
|
|
Packit |
0eec03 |
# and anything from the FindGettext module.
|
|
Packit |
0eec03 |
#
|
|
Packit |
0eec03 |
# The below provided macros require GETTEXT_PACKAGE to be set.
|
|
Packit |
0eec03 |
#
|
|
Packit |
0eec03 |
# intltool_add_check_potfiles_target()
|
|
Packit |
0eec03 |
# Adds a check-potfiles target, which verifies that all files with translations
|
|
Packit |
0eec03 |
# are added in the POTFILES.in file inside GETTEXT_PO_DIR. This macro can be called
|
|
Packit |
0eec03 |
# only inside GETTEXT_PO_DIR.
|
|
Packit |
0eec03 |
#
|
|
Packit |
0eec03 |
# intltool_add_pot_file_target()
|
|
Packit |
0eec03 |
# Creates a new target pot-file, which generates ${GETTEXT_PACKAGE}.pot file into
|
|
Packit |
0eec03 |
# the CMAKE_CURERNT_BINARY_DIR. This target is not part of ALL.
|
|
Packit |
0eec03 |
# This can be called only inside GETTEXT_PO_DIR.
|
|
Packit |
0eec03 |
#
|
|
Packit |
0eec03 |
# intltool_process_po_files()
|
|
Packit |
0eec03 |
# Processes all files in the GETTEXT_PO_DIR and generates .gmo files for them
|
|
Packit |
0eec03 |
# in CMAKE_CURRENT_BINARY_DIR. These are added into a new target gmo-files.
|
|
Packit |
0eec03 |
# It also installs them into proper location under LOCALE_INSTALL_DIR.
|
|
Packit |
0eec03 |
# This can be called only inside GETTEXT_PO_DIR.
|
|
Packit |
0eec03 |
#
|
|
Packit |
0eec03 |
# intltool_setup_po_dir()
|
|
Packit |
0eec03 |
# Shortcut to setup intltool's po/ directory by adding all custom targets
|
|
Packit |
0eec03 |
# and such. this can be called only inside GETTEXT_PO_DIR.
|
|
Packit |
0eec03 |
#
|
|
Packit |
0eec03 |
# intltool_merge(_in_filename _out_filename ...args)
|
|
Packit |
0eec03 |
# Adds rule to call intltool-merge. The args are optional arguments.
|
|
Packit |
0eec03 |
# This can be called in any folder, only the GETTEXT_PO_DIR should
|
|
Packit |
0eec03 |
# be properly set, otherwise the call will fail.
|
|
Packit |
0eec03 |
#
|
|
Packit |
0eec03 |
# add_appdata_file(_infilename _outfilename)
|
|
Packit |
0eec03 |
# A shortcut to call intltool-merge() for an appdata file and install it
|
|
Packit |
0eec03 |
# to ${SHARE_INSTALL_PREFIX}/metainfo
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
include(FindGettext)
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
if(NOT GETTEXT_FOUND)
|
|
Packit |
0eec03 |
message(FATAL_ERROR "gettext not found, please install at least 0.18.3 version")
|
|
Packit |
0eec03 |
endif(NOT GETTEXT_FOUND)
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
if(NOT GETTEXT_FOUND)
|
|
Packit |
0eec03 |
message(FATAL_ERROR "gettext not found, please install at least 0.18.3 version")
|
|
Packit |
0eec03 |
endif(NOT GETTEXT_FOUND)
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
if(GETTEXT_VERSION_STRING VERSION_LESS "0.18.3")
|
|
Packit |
0eec03 |
message(FATAL_ERROR "gettext version 0.18.3+ required, but version '${GETTEXT_VERSION_STRING}' found instead. Please update your gettext")
|
|
Packit |
0eec03 |
endif(GETTEXT_VERSION_STRING VERSION_LESS "0.18.3")
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
find_program(XGETTEXT xgettext)
|
|
Packit |
0eec03 |
if(NOT XGETTEXT)
|
|
Packit |
0eec03 |
message(FATAL_ERROR "xgettext executable not found. Please install or update your gettext to at least 0.18.3 version")
|
|
Packit |
0eec03 |
endif(NOT XGETTEXT)
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
find_program(INTLTOOL_UPDATE intltool-update)
|
|
Packit |
0eec03 |
if(NOT INTLTOOL_UPDATE)
|
|
Packit |
0eec03 |
message(FATAL_ERROR "intltool-update not found. Please install it (usually part of an 'intltool' package)")
|
|
Packit |
0eec03 |
endif(NOT INTLTOOL_UPDATE)
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
find_program(INTLTOOL_EXTRACT intltool-extract)
|
|
Packit |
0eec03 |
if(NOT INTLTOOL_EXTRACT)
|
|
Packit |
0eec03 |
message(FATAL_ERROR "intltool-extract not found. Please install it (usually part of an 'intltool' package)")
|
|
Packit |
0eec03 |
endif(NOT INTLTOOL_EXTRACT)
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
find_program(INTLTOOL_MERGE intltool-merge)
|
|
Packit |
0eec03 |
if(NOT INTLTOOL_MERGE)
|
|
Packit |
0eec03 |
message(FATAL_ERROR "intltool-merge not found. Please install it (usually part of an 'intltool' package)")
|
|
Packit |
0eec03 |
endif(NOT INTLTOOL_MERGE)
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
macro(intltool_add_check_potfiles_target)
|
|
Packit |
0eec03 |
if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL GETTEXT_PO_DIR)
|
|
Packit |
0eec03 |
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")
|
|
Packit |
0eec03 |
endif(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL GETTEXT_PO_DIR)
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
add_custom_target(check-potfiles
|
|
Packit |
0eec03 |
COMMAND ${INTLTOOL_UPDATE} -m
|
|
Packit |
0eec03 |
WORKING_DIRECTORY ${GETTEXT_PO_DIR}
|
|
Packit |
0eec03 |
)
|
|
Packit |
0eec03 |
endmacro(intltool_add_check_potfiles_target)
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
macro(intltool_add_pot_file_target)
|
|
Packit |
0eec03 |
if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL GETTEXT_PO_DIR)
|
|
Packit |
0eec03 |
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")
|
|
Packit |
0eec03 |
endif(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL GETTEXT_PO_DIR)
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${GETTEXT_PACKAGE}.pot
|
|
Packit |
0eec03 |
COMMAND ${CMAKE_COMMAND} -E env INTLTOOL_EXTRACT="${INTLTOOL_EXTRACT}" XGETTEXT="${XGETTEXT}" srcdir=${CMAKE_CURRENT_SOURCE_DIR} ${INTLTOOL_UPDATE} --gettext-package ${GETTEXT_PACKAGE} --pot
|
|
Packit |
0eec03 |
)
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
add_custom_target(pot-file
|
|
Packit |
0eec03 |
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${GETTEXT_PACKAGE}.pot
|
|
Packit |
0eec03 |
)
|
|
Packit |
0eec03 |
endmacro(intltool_add_pot_file_target)
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
macro(intltool_process_po_files)
|
|
Packit |
0eec03 |
if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL GETTEXT_PO_DIR)
|
|
Packit |
0eec03 |
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")
|
|
Packit |
0eec03 |
endif(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL GETTEXT_PO_DIR)
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
file(GLOB po_files ${GETTEXT_PO_DIR}/*.po)
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
set(LINGUAS)
|
|
Packit |
0eec03 |
set(LINGUAS_GMO)
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
foreach(file IN LISTS po_files)
|
|
Packit |
0eec03 |
get_filename_component(lang ${file} NAME_WE)
|
|
Packit |
0eec03 |
list(APPEND LINGUAS ${lang})
|
|
Packit |
0eec03 |
list(APPEND LINGUAS_GMO ${lang}.gmo)
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo
|
|
Packit |
0eec03 |
COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo ${CMAKE_CURRENT_SOURCE_DIR}/${lang}.po
|
|
Packit |
0eec03 |
DEPENDS ${lang}.po
|
|
Packit |
0eec03 |
)
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo
|
|
Packit |
0eec03 |
DESTINATION ${LOCALE_INSTALL_DIR}/${lang}/LC_MESSAGES/
|
|
Packit |
0eec03 |
RENAME ${GETTEXT_PACKAGE}.mo
|
|
Packit |
0eec03 |
)
|
|
Packit |
0eec03 |
if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo.m)
|
|
Packit |
0eec03 |
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo.m
|
|
Packit |
0eec03 |
DESTINATION ${LOCALE_INSTALL_DIR}/${lang}/LC_MESSAGES/
|
|
Packit |
0eec03 |
RENAME ${GETTEXT_PACKAGE}.mo.m
|
|
Packit |
0eec03 |
)
|
|
Packit |
0eec03 |
endif(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo.m)
|
|
Packit |
0eec03 |
endforeach(file)
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
add_custom_target(gmo-files ALL
|
|
Packit |
0eec03 |
DEPENDS ${LINGUAS_GMO}
|
|
Packit |
0eec03 |
)
|
|
Packit |
0eec03 |
endmacro(intltool_process_po_files)
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
macro(intltool_setup_po_dir)
|
|
Packit |
0eec03 |
if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL GETTEXT_PO_DIR)
|
|
Packit |
0eec03 |
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")
|
|
Packit |
0eec03 |
endif(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL GETTEXT_PO_DIR)
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
intltool_add_check_potfiles_target()
|
|
Packit |
0eec03 |
intltool_add_pot_file_target()
|
|
Packit |
0eec03 |
intltool_process_po_files()
|
|
Packit |
0eec03 |
endmacro(intltool_setup_po_dir)
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
macro(intltool_merge _in_filename _out_filename)
|
|
Packit |
0eec03 |
set(_in ${_in_filename})
|
|
Packit |
0eec03 |
set(_out ${_out_filename})
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
get_filename_component(_path ${_in} DIRECTORY)
|
|
Packit |
0eec03 |
if(_path STREQUAL "")
|
|
Packit |
0eec03 |
set(_in ${CMAKE_CURRENT_SOURCE_DIR}/${_in})
|
|
Packit |
0eec03 |
endif(_path STREQUAL "")
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
get_filename_component(_path ${_out} DIRECTORY)
|
|
Packit |
0eec03 |
if(_path STREQUAL "")
|
|
Packit |
0eec03 |
set(_out ${CMAKE_CURRENT_BINARY_DIR}/${_out})
|
|
Packit |
0eec03 |
endif(_path STREQUAL "")
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
set(_has_no_translations OFF)
|
|
Packit |
0eec03 |
set(_args)
|
|
Packit |
0eec03 |
foreach(_arg ${ARGN})
|
|
Packit |
0eec03 |
list(APPEND _args "${_arg}")
|
|
Packit |
0eec03 |
if(_arg STREQUAL "--no-translations")
|
|
Packit |
0eec03 |
set(_has_no_translations ON)
|
|
Packit |
0eec03 |
endif(_arg STREQUAL "--no-translations")
|
|
Packit |
0eec03 |
endforeach(_arg)
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
if(_has_no_translations)
|
|
Packit |
0eec03 |
add_custom_command(OUTPUT ${_out}
|
|
Packit |
0eec03 |
COMMAND ${INTLTOOL_MERGE} ${_args} --quiet "${_in}" "${_out}"
|
|
Packit |
0eec03 |
DEPENDS ${_in}
|
|
Packit |
0eec03 |
)
|
|
Packit |
0eec03 |
else(_has_no_translations)
|
|
Packit |
0eec03 |
add_custom_command(OUTPUT ${_out}
|
|
Packit |
0eec03 |
COMMAND ${INTLTOOL_MERGE} ${_args} --quiet --cache="${CMAKE_BINARY_DIR}/po/.intltool-merge-cache" "${GETTEXT_PO_DIR}" "${_in}" "${_out}"
|
|
Packit |
0eec03 |
DEPENDS ${_in}
|
|
Packit |
0eec03 |
)
|
|
Packit |
0eec03 |
endif(_has_no_translations)
|
|
Packit |
0eec03 |
endmacro(intltool_merge)
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
macro(add_appdata_file _infilename _outfilename)
|
|
Packit |
0eec03 |
if(NOT TARGET appdata-files)
|
|
Packit |
0eec03 |
add_custom_target(appdata-files ALL)
|
|
Packit |
0eec03 |
endif(NOT TARGET appdata-files)
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
set(_out ${_outfilename})
|
|
Packit |
0eec03 |
get_filename_component(_outtarget ${_out} NAME)
|
|
Packit |
0eec03 |
get_filename_component(_path ${_out} DIRECTORY)
|
|
Packit |
0eec03 |
if(_path STREQUAL "")
|
|
Packit |
0eec03 |
set(_out ${CMAKE_CURRENT_BINARY_DIR}/${_out})
|
|
Packit |
0eec03 |
endif(_path STREQUAL "")
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
intltool_merge(${_infilename} ${_out} --xml-style --utf8)
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
add_custom_target(appdata-${_outtarget}
|
|
Packit |
0eec03 |
DEPENDS ${_out}
|
|
Packit |
0eec03 |
)
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
add_dependencies(appdata-files appdata-${_outtarget})
|
|
Packit |
0eec03 |
|
|
Packit |
0eec03 |
install(FILES ${_out}
|
|
Packit |
0eec03 |
DESTINATION ${SHARE_INSTALL_PREFIX}/metainfo
|
|
Packit |
0eec03 |
)
|
|
Packit |
0eec03 |
endmacro(add_appdata_file)
|