Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
CMake: avoid msgmerge during target 'translations'
  • Loading branch information
TheTumultuousUnicornOfDarkness committed May 2, 2020
1 parent 8c9dd89 commit f377ddf
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
46 changes: 46 additions & 0 deletions cmake/gettext_create_translations.cmake
@@ -0,0 +1,46 @@
# See: /usr/share/cmake-*.*/Modules/FindGettext.cmake
# This is the GETTEXT_CREATE_TRANSLATIONS macro without GETTEXT_MSGMERGE_EXECUTABLE command

macro(GETTEXT_CONVERT_TRANSLATIONS _potFile _firstPoFileArg)
# make it a real variable, so we can modify it here
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)
endif()

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(
OUTPUT ${_gmoFile}
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 ()

if(NOT TARGET translations)
add_custom_target(translations)
endif()

_GETTEXT_GET_UNIQUE_TARGET_NAME(translations uniqueTargetName)

add_custom_target(${uniqueTargetName} ${_addToAll} DEPENDS ${_gmoFiles})

add_dependencies(translations ${uniqueTargetName})

endmacro()
3 changes: 2 additions & 1 deletion po/CMakeLists.txt
Expand Up @@ -14,6 +14,7 @@ file(GLOB

if(GETTEXT_FOUND)
set(GETTEXT_FOUND ON PARENT_SCOPE)
include(gettext_create_translations)
add_custom_target(genpot
COMMAND xgettext
--language=C
Expand All @@ -31,7 +32,7 @@ if(GETTEXT_FOUND)
"*.c" "cpu-x.h"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src
)
GETTEXT_CREATE_TRANSLATIONS(${pot_file} ALL ${po_files})
GETTEXT_CONVERT_TRANSLATIONS(${pot_file} ALL ${po_files})
else(GETTEXT_FOUND)
set(GETTEXT_FOUND OFF PARENT_SCOPE)
endif(GETTEXT_FOUND)

0 comments on commit f377ddf

Please sign in to comment.