2013-10-15 19:17:36 +04:00
|
|
|
#.rst:
|
|
|
|
# FindGettext
|
|
|
|
# -----------
|
|
|
|
#
|
|
|
|
# Find GNU gettext tools
|
|
|
|
#
|
|
|
|
# This module looks for the GNU gettext tools. This module defines the
|
2007-02-02 20:46:52 +03:00
|
|
|
# following values:
|
2013-10-15 19:17:36 +04:00
|
|
|
#
|
|
|
|
# ::
|
|
|
|
#
|
|
|
|
# GETTEXT_MSGMERGE_EXECUTABLE: the full path to the msgmerge tool.
|
|
|
|
# GETTEXT_MSGFMT_EXECUTABLE: the full path to the msgfmt tool.
|
|
|
|
# GETTEXT_FOUND: True if gettext has been found.
|
|
|
|
# GETTEXT_VERSION_STRING: the version of gettext found (since CMake 2.8.8)
|
|
|
|
#
|
|
|
|
#
|
2007-02-02 20:46:52 +03:00
|
|
|
#
|
|
|
|
# Additionally it provides the following macros:
|
2013-10-15 19:17:36 +04:00
|
|
|
# GETTEXT_CREATE_TRANSLATIONS ( outputFile [ALL] file1 ... fileN )
|
|
|
|
#
|
|
|
|
# ::
|
|
|
|
#
|
|
|
|
# This will create a target "translations" which will convert the
|
|
|
|
# given input po files into the binary output mo file. If the
|
|
|
|
# ALL option is used, the translations will also be created when
|
|
|
|
# building the default target.
|
|
|
|
#
|
|
|
|
# GETTEXT_PROCESS_POT( <potfile> [ALL] [INSTALL_DESTINATION <destdir>]
|
|
|
|
# LANGUAGES <lang1> <lang2> ... )
|
|
|
|
#
|
|
|
|
# ::
|
|
|
|
#
|
|
|
|
# Process the given pot file to mo files.
|
|
|
|
# If INSTALL_DESTINATION is given then automatically install rules will be created,
|
|
|
|
# the language subdirectory will be taken into account (by default use share/locale/).
|
|
|
|
# If ALL is specified, the pot file is processed when building the all traget.
|
|
|
|
# It creates a custom target "potfile".
|
|
|
|
#
|
|
|
|
# GETTEXT_PROCESS_PO_FILES( <lang> [ALL] [INSTALL_DESTINATION <dir>]
|
|
|
|
# PO_FILES <po1> <po2> ... )
|
|
|
|
#
|
|
|
|
# ::
|
|
|
|
#
|
|
|
|
# Process the given po files to mo files for the given language.
|
|
|
|
# If INSTALL_DESTINATION is given then automatically install rules will be created,
|
|
|
|
# the language subdirectory will be taken into account (by default use share/locale/).
|
|
|
|
# If ALL is specified, the po files are processed when building the all traget.
|
|
|
|
# It creates a custom target "pofiles".
|
2007-02-02 20:46:52 +03:00
|
|
|
|
2009-09-28 19:45:50 +04:00
|
|
|
#=============================================================================
|
|
|
|
# Copyright 2007-2009 Kitware, Inc.
|
2011-08-10 04:28:26 +04:00
|
|
|
# Copyright 2007 Alexander Neundorf <neundorf@kde.org>
|
2009-09-28 19:45:50 +04:00
|
|
|
#
|
|
|
|
# Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
# see accompanying file Copyright.txt for details.
|
|
|
|
#
|
|
|
|
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
# See the License for more information.
|
|
|
|
#=============================================================================
|
2010-08-07 04:48:47 +04:00
|
|
|
# (To distribute this file outside of CMake, substitute the full
|
2009-09-28 19:45:50 +04:00
|
|
|
# License text for the above reference.)
|
2007-02-02 20:46:52 +03:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
find_program(GETTEXT_MSGMERGE_EXECUTABLE msgmerge)
|
2007-02-02 20:46:52 +03:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
find_program(GETTEXT_MSGFMT_EXECUTABLE msgfmt)
|
2007-02-02 20:46:52 +03:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
if(GETTEXT_MSGMERGE_EXECUTABLE)
|
|
|
|
execute_process(COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --version
|
2012-01-25 21:03:32 +04:00
|
|
|
OUTPUT_VARIABLE gettext_version
|
|
|
|
ERROR_QUIET
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
2014-04-06 23:30:00 +04:00
|
|
|
if (gettext_version MATCHES "^msgmerge \\([^\\)]*\\) ([0-9\\.]+[^ \n]*)")
|
|
|
|
set(GETTEXT_VERSION_STRING "${CMAKE_MATCH_1}")
|
2012-08-13 21:47:32 +04:00
|
|
|
endif()
|
|
|
|
unset(gettext_version)
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2012-01-25 21:03:32 +04:00
|
|
|
|
2012-09-08 21:03:26 +04:00
|
|
|
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
|
2012-01-25 21:03:32 +04:00
|
|
|
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Gettext
|
|
|
|
REQUIRED_VARS GETTEXT_MSGMERGE_EXECUTABLE GETTEXT_MSGFMT_EXECUTABLE
|
|
|
|
VERSION_VAR GETTEXT_VERSION_STRING)
|
2011-08-10 04:35:58 +04:00
|
|
|
|
2012-09-08 21:03:26 +04:00
|
|
|
include(${CMAKE_CURRENT_LIST_DIR}/CMakeParseArguments.cmake)
|
2011-08-10 04:28:26 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
function(_GETTEXT_GET_UNIQUE_TARGET_NAME _name _unique_name)
|
|
|
|
set(propertyName "_GETTEXT_UNIQUE_COUNTER_${_name}")
|
|
|
|
get_property(currentCounter GLOBAL PROPERTY "${propertyName}")
|
|
|
|
if(NOT currentCounter)
|
|
|
|
set(currentCounter 1)
|
|
|
|
endif()
|
|
|
|
set(${_unique_name} "${_name}_${currentCounter}" PARENT_SCOPE)
|
|
|
|
math(EXPR currentCounter "${currentCounter} + 1")
|
|
|
|
set_property(GLOBAL PROPERTY ${propertyName} ${currentCounter} )
|
|
|
|
endfunction()
|
2012-02-12 21:57:28 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
macro(GETTEXT_CREATE_TRANSLATIONS _potFile _firstPoFileArg)
|
2009-01-10 16:39:35 +03:00
|
|
|
# make it a real variable, so we can modify it here
|
2012-08-13 21:47:32 +04:00
|
|
|
set(_firstPoFile "${_firstPoFileArg}")
|
|
|
|
|
|
|
|
set(_gmoFiles)
|
|
|
|
get_filename_component(_potName ${_potFile} NAME)
|
|
|
|
string(REGEX REPLACE "^(.+)(\\.[^.]+)$" "\\1" _potBasename ${_potName})
|
|
|
|
get_filename_component(_absPotFile ${_potFile} ABSOLUTE)
|
|
|
|
|
|
|
|
set(_addToAll)
|
|
|
|
if(${_firstPoFile} STREQUAL "ALL")
|
|
|
|
set(_addToAll "ALL")
|
|
|
|
set(_firstPoFile)
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2012-08-13 21:47:32 +04:00
|
|
|
|
|
|
|
foreach (_currentPoFile ${_firstPoFile} ${ARGN})
|
|
|
|
get_filename_component(_absFile ${_currentPoFile} ABSOLUTE)
|
|
|
|
get_filename_component(_abs_PATH ${_absFile} PATH)
|
|
|
|
get_filename_component(_lang ${_absFile} NAME_WE)
|
|
|
|
set(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_lang}.gmo)
|
|
|
|
|
|
|
|
add_custom_command(
|
2011-08-10 04:28:26 +04:00
|
|
|
OUTPUT ${_gmoFile}
|
2007-02-02 20:46:52 +03:00
|
|
|
COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --quiet --update --backup=none -s ${_absFile} ${_absPotFile}
|
|
|
|
COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} ${_absFile}
|
2011-08-10 04:28:26 +04:00
|
|
|
DEPENDS ${_absPotFile} ${_absFile}
|
2007-02-02 20:46:52 +03:00
|
|
|
)
|
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
install(FILES ${_gmoFile} DESTINATION share/locale/${_lang}/LC_MESSAGES RENAME ${_potBasename}.mo)
|
|
|
|
set(_gmoFiles ${_gmoFiles} ${_gmoFile})
|
2007-02-02 20:46:52 +03:00
|
|
|
|
2012-08-13 21:50:14 +04:00
|
|
|
endforeach ()
|
2007-02-02 20:46:52 +03:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
if(NOT TARGET translations)
|
|
|
|
add_custom_target(translations)
|
|
|
|
endif()
|
2012-02-12 21:57:28 +04:00
|
|
|
|
|
|
|
_GETTEXT_GET_UNIQUE_TARGET_NAME(translations uniqueTargetName)
|
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
add_custom_target(${uniqueTargetName} ${_addToAll} DEPENDS ${_gmoFiles})
|
2012-02-12 21:57:28 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
add_dependencies(translations ${uniqueTargetName})
|
2007-02-02 20:46:52 +03:00
|
|
|
|
2012-08-13 21:50:14 +04:00
|
|
|
endmacro()
|
2007-02-02 20:46:52 +03:00
|
|
|
|
2011-08-10 04:28:26 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
function(GETTEXT_PROCESS_POT_FILE _potFile)
|
|
|
|
set(_gmoFiles)
|
|
|
|
set(_options ALL)
|
|
|
|
set(_oneValueArgs INSTALL_DESTINATION)
|
|
|
|
set(_multiValueArgs LANGUAGES)
|
2011-08-10 04:28:26 +04:00
|
|
|
|
|
|
|
CMAKE_PARSE_ARGUMENTS(_parsedArguments "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
|
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
get_filename_component(_potName ${_potFile} NAME)
|
|
|
|
string(REGEX REPLACE "^(.+)(\\.[^.]+)$" "\\1" _potBasename ${_potName})
|
|
|
|
get_filename_component(_absPotFile ${_potFile} ABSOLUTE)
|
2011-08-10 04:28:26 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
foreach (_lang ${_parsedArguments_LANGUAGES})
|
|
|
|
set(_poFile "${CMAKE_CURRENT_BINARY_DIR}/${_lang}.po")
|
|
|
|
set(_gmoFile "${CMAKE_CURRENT_BINARY_DIR}/${_lang}.gmo")
|
2011-08-10 04:28:26 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
add_custom_command(
|
2011-08-10 04:28:26 +04:00
|
|
|
OUTPUT "${_poFile}"
|
|
|
|
COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --quiet --update --backup=none -s ${_poFile} ${_absPotFile}
|
|
|
|
DEPENDS ${_absPotFile}
|
|
|
|
)
|
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
add_custom_command(
|
2011-08-10 04:28:26 +04:00
|
|
|
OUTPUT "${_gmoFile}"
|
|
|
|
COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} ${_poFile}
|
|
|
|
DEPENDS ${_absPotFile} ${_poFile}
|
|
|
|
)
|
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
if(_parsedArguments_INSTALL_DESTINATION)
|
|
|
|
install(FILES ${_gmoFile} DESTINATION ${_parsedArguments_INSTALL_DESTINATION}/${_lang}/LC_MESSAGES RENAME ${_potBasename}.mo)
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2012-08-13 21:47:32 +04:00
|
|
|
list(APPEND _gmoFiles ${_gmoFile})
|
2012-08-13 21:50:14 +04:00
|
|
|
endforeach ()
|
2011-08-10 04:28:26 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
if(NOT TARGET potfiles)
|
|
|
|
add_custom_target(potfiles)
|
|
|
|
endif()
|
2012-02-12 21:57:28 +04:00
|
|
|
|
|
|
|
_GETTEXT_GET_UNIQUE_TARGET_NAME( potfiles uniqueTargetName)
|
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
if(_parsedArguments_ALL)
|
|
|
|
add_custom_target(${uniqueTargetName} ALL DEPENDS ${_gmoFiles})
|
2012-08-13 21:50:14 +04:00
|
|
|
else()
|
2012-08-13 21:47:32 +04:00
|
|
|
add_custom_target(${uniqueTargetName} DEPENDS ${_gmoFiles})
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2012-02-12 21:57:28 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
add_dependencies(potfiles ${uniqueTargetName})
|
2012-02-12 21:57:28 +04:00
|
|
|
|
2012-08-13 21:50:14 +04:00
|
|
|
endfunction()
|
2011-08-10 04:28:26 +04:00
|
|
|
|
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
function(GETTEXT_PROCESS_PO_FILES _lang)
|
|
|
|
set(_options ALL)
|
|
|
|
set(_oneValueArgs INSTALL_DESTINATION)
|
|
|
|
set(_multiValueArgs PO_FILES)
|
|
|
|
set(_gmoFiles)
|
2011-08-10 04:28:26 +04:00
|
|
|
|
|
|
|
CMAKE_PARSE_ARGUMENTS(_parsedArguments "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
|
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
foreach(_current_PO_FILE ${_parsedArguments_PO_FILES})
|
|
|
|
get_filename_component(_name ${_current_PO_FILE} NAME)
|
|
|
|
string(REGEX REPLACE "^(.+)(\\.[^.]+)$" "\\1" _basename ${_name})
|
|
|
|
set(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.gmo)
|
|
|
|
add_custom_command(OUTPUT ${_gmoFile}
|
2011-08-10 04:28:26 +04:00
|
|
|
COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} ${_current_PO_FILE}
|
|
|
|
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
|
|
|
DEPENDS ${_current_PO_FILE}
|
|
|
|
)
|
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
if(_parsedArguments_INSTALL_DESTINATION)
|
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.gmo DESTINATION ${_parsedArguments_INSTALL_DESTINATION}/${_lang}/LC_MESSAGES/ RENAME ${_basename}.mo)
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2012-08-13 21:47:32 +04:00
|
|
|
list(APPEND _gmoFiles ${_gmoFile})
|
2012-08-13 21:50:14 +04:00
|
|
|
endforeach()
|
2011-08-10 04:28:26 +04:00
|
|
|
|
2012-02-12 21:57:28 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
if(NOT TARGET pofiles)
|
|
|
|
add_custom_target(pofiles)
|
|
|
|
endif()
|
2012-02-12 21:57:28 +04:00
|
|
|
|
|
|
|
_GETTEXT_GET_UNIQUE_TARGET_NAME( pofiles uniqueTargetName)
|
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
if(_parsedArguments_ALL)
|
|
|
|
add_custom_target(${uniqueTargetName} ALL DEPENDS ${_gmoFiles})
|
2012-08-13 21:50:14 +04:00
|
|
|
else()
|
2012-08-13 21:47:32 +04:00
|
|
|
add_custom_target(${uniqueTargetName} DEPENDS ${_gmoFiles})
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2012-02-12 21:57:28 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
add_dependencies(pofiles ${uniqueTargetName})
|
2012-02-12 21:57:28 +04:00
|
|
|
|
2012-08-13 21:50:14 +04:00
|
|
|
endfunction()
|