From 2382c35b838e325d098f88a558d4a1db2d584e24 Mon Sep 17 00:00:00 2001 From: "gregory.hainaut@gmail.com" Date: Thu, 20 Jan 2011 20:45:07 +0000 Subject: [PATCH] cmake: (WIP) rule to compile translation file on linux. Note: to install them, you must call "make install" with root access. Files will be install into /usr/local/share/locales... git-svn-id: http://pcsx2.googlecode.com/svn/trunk@4238 96395faa-99c1-11dd-bbfe-3dabce05a288 --- CMakeLists.txt | 5 +++ cmake/SearchForStuff.cmake | 1 + cmake/Translation.cmake | 71 ++++++++++++++++++++++++++++++++++++++ locales/CMakeLists.txt | 22 ++++++++++++ 4 files changed, 99 insertions(+) create mode 100644 cmake/Translation.cmake create mode 100644 locales/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 482ab2e0ef..05cbf37c79 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,11 @@ include_directories(${PROJECT_SOURCE_DIR}/common/include ${PROJECT_SOURCE_DIR}/common/include/Utilities ${PROJECT_SOURCE_DIR}/common/include/x86emitter) +# make the translation +if(EXISTS "${PROJECT_SOURCE_DIR}/locales") + add_subdirectory(locales) +endif(EXISTS "${PROJECT_SOURCE_DIR}/locales") + # make 3rdParty if(EXISTS "${PROJECT_SOURCE_DIR}/3rdparty") add_subdirectory(3rdparty) diff --git a/cmake/SearchForStuff.cmake b/cmake/SearchForStuff.cmake index 099e21b9b8..f00f98adf9 100644 --- a/cmake/SearchForStuff.cmake +++ b/cmake/SearchForStuff.cmake @@ -28,6 +28,7 @@ endif(Linux) ## Use cmake package to find module find_package(ALSA) find_package(BZip2) +find_package(Gettext) # translation tool find_package(JPEG) find_package(OpenGL) # Tell cmake that we use SDL as a library and not as an application diff --git a/cmake/Translation.cmake b/cmake/Translation.cmake new file mode 100644 index 0000000000..361baeee04 --- /dev/null +++ b/cmake/Translation.cmake @@ -0,0 +1,71 @@ +# 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) + # make it a real variable, so we can modify it here + SET(_firstPoFile "${_firstPoFileArg}") + + SET(_gmoFiles) + GET_FILENAME_COMPONENT(_potBasename ${_potFile} NAME_WE) + GET_FILENAME_COMPONENT(_absPotFile ${_potFile} ABSOLUTE) + + SET(_addToAll) + IF(${_firstPoFile} STREQUAL "ALL") + SET(_addToAll "ALL") + SET(_firstPoFile) + ENDIF(${_firstPoFile} STREQUAL "ALL") + + 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_CURRENT_BINARY_DIR}/${_lang}/${_gmoBase}.gmo) + + ADD_CUSTOM_COMMAND( OUTPUT ${_gmoFile} + COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --quiet --update --backup=none -s ${_absFile} ${_absPotFile} + COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} ${_absFile} + DEPENDS ${_absPotFile} ${_absFile} ) + + INSTALL(FILES ${_gmoFile} DESTINATION share/locale/${_lang}/LC_MESSAGES RENAME ${_potBasename}.mo) + + SET(_gmoFiles ${_gmoFiles} ${_gmoFile}) + + ENDFOREACH (_currentPoFile ) + + IF(NOT LINUX_PACKAGE) + ADD_CUSTOM_TARGET(translations_${_potBasename} ${_addToAll} DEPENDS ${_gmoFiles}) + ENDIF(NOT LINUX_PACKAGE) + +ENDMACRO(GETTEXT_CREATE_TRANSLATIONS_PCSX2 ) diff --git a/locales/CMakeLists.txt b/locales/CMakeLists.txt new file mode 100644 index 0000000000..1841036ec5 --- /dev/null +++ b/locales/CMakeLists.txt @@ -0,0 +1,22 @@ +# Check that people use the good file +if(NOT TOP_CMAKE_WAS_SOURCED) + message(FATAL_ERROR " + You did not 'cmake' the good CMakeLists.txt file. Use the one in the top dir. + It is advice to delete all wrongly generated cmake stuff => CMakeFiles & CMakeCache.txt") +endif(NOT TOP_CMAKE_WAS_SOURCED) + +if (GETTEXT_FOUND) + include(Translation) + + file (GLOB_RECURSE PO_DEV_FILES ${PROJECT_SOURCE_DIR}}/locales pcsx2_Devel.po) + file (GLOB_RECURSE PO_ICO_FILES ${PROJECT_SOURCE_DIR}}/locales pcsx2_Iconized.po) + file (GLOB_RECURSE PO_MAIN_FILES ${PROJECT_SOURCE_DIR}/locales pcsx2_Main.po) + file (GLOB_RECURSE PO_TER_FILES ${PROJECT_SOURCE_DIR}}/locales pcsx2_Tertiary.po) + + # Macro to compile po file and install them + GETTEXT_CREATE_TRANSLATIONS_PCSX2(${PROJECT_SOURCE_DIR}/locales/templates/pcsx2_Devel.pot ALL ${PO_DEV_FILES}) + GETTEXT_CREATE_TRANSLATIONS_PCSX2(${PROJECT_SOURCE_DIR}/locales/templates/pcsx2_Iconized.pot ALL ${PO_ICO_FILES}) + GETTEXT_CREATE_TRANSLATIONS_PCSX2(${PROJECT_SOURCE_DIR}/locales/templates/pcsx2_Main.pot ALL ${PO_MAIN_FILES}) + GETTEXT_CREATE_TRANSLATIONS_PCSX2(${PROJECT_SOURCE_DIR}/locales/templates/pcsx2_Tertiary.pot ALL ${PO_TER_FILES}) + +endif (GETTEXT_FOUND)