2011-01-20 20:45:07 +00:00
# Macro to compile po file
# It based on FindGettext.cmake files.
# The macro was adapted for PCSX2 need. Several pot file, language based on directory instead of file
# Copyright (c) 2007-2009 Kitware, Inc., Insight Consortium
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * The names of Kitware, Inc., the Insight Consortium, or the names of
# any consortium members, or of any contributors, may not be used to
# endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
MACRO ( GETTEXT_CREATE_TRANSLATIONS_PCSX2 _potFile _firstPoFileArg )
2021-07-04 05:24:21 +00:00
# make it a real variable, so we can modify it here
SET ( _firstPoFile "${_firstPoFileArg}" )
2011-01-20 20:45:07 +00:00
2021-07-04 05:24:21 +00:00
SET ( _gmoFiles )
GET_FILENAME_COMPONENT ( _potBasename ${ _potFile } NAME_WE )
GET_FILENAME_COMPONENT ( _absPotFile ${ _potFile } ABSOLUTE )
2011-01-20 20:45:07 +00:00
2021-07-04 05:24:21 +00:00
SET ( _addToAll )
IF ( ${ _firstPoFile } STREQUAL "ALL" )
SET ( _addToAll "ALL" )
SET ( _firstPoFile )
ENDIF ( ${ _firstPoFile } STREQUAL "ALL" )
2011-01-20 20:45:07 +00:00
2021-07-04 05:24:21 +00:00
FOREACH ( _currentPoFile ${ _firstPoFile } ${ ARGN } )
GET_FILENAME_COMPONENT ( _absFile ${ _currentPoFile } ABSOLUTE )
GET_FILENAME_COMPONENT ( _abs_PATH ${ _absFile } PATH )
GET_FILENAME_COMPONENT ( _gmoBase ${ _absFile } NAME_WE )
GET_FILENAME_COMPONENT ( _lang ${ _abs_PATH } NAME_WE )
SET ( _gmoFile ${ CMAKE_BINARY_DIR } / ${ _lang } __ ${ _gmoBase } .gmo )
IF ( APPLE )
# CMake doesn't support generator expressions as the OUTPUT of a custom command
# Instead, use ${_gmoFile} to detect changes, and output to the bundle as a side effect
# In addition, we have have to preprocess the po files to remove mnemonics:
# On Windows, menu items have "mnemonics", the items with a letter underlined that you can use with alt to select menu items. MacOS doesn't do this.
# Some languages don't use easily-typable characters, so it's common to add a dedicated character for the mnemonic (e.g. in Japanese on Windows, the File menu would be "ファイル(&F)").
# On MacOS, these extra letters in parentheses are useless and should be avoided.
SET ( _mnemonicless "${CMAKE_BINARY_DIR}/${_lang}__${_gmoBase}.nomnemonic.po" )
SET ( _extraCommands
C O M M A N D s e d - e " \ " s / [ ( ] & [ A - Z a - z ] [ ) ] / / g \ " " " $ { _ a b s F i l e } " > " $ { _ m n e m o n i c l e s s } "
C O M M A N D $ { C M A K E _ C O M M A N D } - E m a k e _ d i r e c t o r y " $ < T A R G E T _ F I L E _ D I R : P C S X 2 > / . . / R e s o u r c e s / $ { _ l a n g } / "
C O M M A N D $ { G E T T E X T _ M S G F M T _ E X E C U T A B L E } - o " $ < T A R G E T _ F I L E _ D I R : P C S X 2 > / . . / R e s o u r c e s / $ { _ l a n g } / $ { _ p o t B a s e n a m e } . m o " $ { _ m n e m o n i c l e s s } )
ELSE ( APPLE )
SET ( _extraCommands )
ENDIF ( APPLE )
2011-01-20 20:45:07 +00:00
2021-07-04 05:24:21 +00:00
IF ( _currentPoFile MATCHES "\\.git" )
continue ( )
ENDIF ( _currentPoFile MATCHES "\\.git" )
2019-01-01 07:02:34 +00:00
2021-07-04 05:24:21 +00:00
IF ( CMAKE_BUILD_PO )
ADD_CUSTOM_COMMAND ( OUTPUT ${ _gmoFile }
C O M M A N D $ { G E T T E X T _ M S G M E R G E _ E X E C U T A B L E } - - q u i e t - - u p d a t e - - b a c k u p = n o n e - s $ { _ a b s F i l e } $ { _ a b s P o t F i l e }
C O M M A N D $ { G E T T E X T _ M S G F M T _ E X E C U T A B L E } - o $ { _ g m o F i l e } $ { _ a b s F i l e }
$ { _ e x t r a C o m m a n d s }
D E P E N D S $ { _ a b s P o t F i l e } $ { _ a b s F i l e } )
ELSE ( CMAKE_BUILD_PO )
ADD_CUSTOM_COMMAND ( OUTPUT ${ _gmoFile }
C O M M A N D $ { G E T T E X T _ M S G F M T _ E X E C U T A B L E } - o $ { _ g m o F i l e } $ { _ a b s F i l e }
$ { _ e x t r a C o m m a n d s }
D E P E N D S $ { _ a b s P o t F i l e } $ { _ a b s F i l e } )
ENDIF ( CMAKE_BUILD_PO )
2011-01-20 20:45:07 +00:00
2021-07-04 05:24:21 +00:00
IF ( PACKAGE_MODE )
INSTALL ( FILES ${ _gmoFile } DESTINATION ${ CMAKE_INSTALL_LOCALEDIR } / ${ _lang } /LC_MESSAGES RENAME ${ _potBasename } .mo )
ELSE ( PACKAGE_MODE )
INSTALL ( FILES ${ _gmoFile } DESTINATION ${ CMAKE_SOURCE_DIR } /bin/Langs/ ${ _lang } RENAME ${ _potBasename } .mo )
ENDIF ( PACKAGE_MODE )
2011-01-20 20:45:07 +00:00
2021-07-04 05:24:21 +00:00
SET ( _gmoFiles ${ _gmoFiles } ${ _gmoFile } )
2011-01-20 20:45:07 +00:00
2021-07-04 05:24:21 +00:00
ENDFOREACH ( _currentPoFile )
2011-01-20 20:45:07 +00:00
2021-07-04 05:24:21 +00:00
IF ( NOT LINUX_PACKAGE )
ADD_CUSTOM_TARGET ( translations_ ${ _potBasename } ${ _addToAll } DEPENDS ${ _gmoFiles } )
ENDIF ( NOT LINUX_PACKAGE )
2011-01-20 20:45:07 +00:00
ENDMACRO ( GETTEXT_CREATE_TRANSLATIONS_PCSX2 )