CMake: Add target update-gmo

This target will update the gmo files if and only if the associated
po-file is modified. To determine whether a file is modified, 'git
status --porcelain' is used.

This follows up on commit 06782542.
This commit is contained in:
Vincent van Ravesteijn 2014-02-03 17:27:07 +01:00
parent cda585baf5
commit f63221aba4
2 changed files with 28 additions and 7 deletions

View File

@ -0,0 +1,7 @@
#! /usr/bin/env python
###############
import sys, os, shutil
if os.stat(sys.argv[1]).st_size > 0:
shutil.copyfile(sys.argv[2], sys.argv[3])

View File

@ -165,16 +165,29 @@ foreach(_pofile ${LYX_BASE_PO_FILES})
list(APPEND LYX_PO_FILES ${CMAKE_CURRENT_BINARY_DIR}/${_pofile})
endforeach(_pofile)
FIND_PROGRAM(LYX_GITVERSION git)
set(LYX_UPDATED_GMO_FILES)
foreach(_gmo_base ${INSTALLED_LANGUAGES})
set(_gmo ${_gmo_base}.gmo)
add_custom_command(
OUTPUT "${LYX_DEST_PO}/${_gmo}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_BINARY_DIR}/${_gmo}" "${LYX_DEST_PO}/${_gmo}"
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_gmo}"
)
list(APPEND LYX_UPDATED_GMO_FILES "${LYX_DEST_PO}/${_gmo}")
ADD_CUSTOM_TARGET(update-${_gmo_base}-gmo DEPENDS "${LYX_DEST_PO}/${_gmo}")
if(LYX_GITVERSION)
add_custom_command(
OUTPUT "${LYX_DEST_PO}/${_gmo}"
COMMAND "${LYX_GITVERSION}" "status" "--porcelain" "${_gmo_base}.po" ">" "${CMAKE_CURRENT_BINARY_DIR}/${_gmo}.tobeupdated"
COMMAND ${LYX_PYTHON_EXECUTABLE} "${TOP_CMAKE_PATH}/po/update-gmo.py"
"${CMAKE_CURRENT_BINARY_DIR}/${_gmo}.tobeupdated"
"${CMAKE_CURRENT_BINARY_DIR}/${_gmo}"
"${LYX_DEST_PO}/${_gmo}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_gmo}"
)
else()
add_custom_command(
OUTPUT "${LYX_DEST_PO}/${_gmo}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_BINARY_DIR}/${_gmo}" "${LYX_DEST_PO}/${_gmo}"
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_gmo}"
)
endif()
endforeach()
set(LYX_UPDATED_PO_FILES)
@ -206,7 +219,8 @@ GETTEXT_CREATE_TRANSLATIONS(${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.pot ${_addAL
# Create a new target to remerge po files
# ALL omitted here, to prevent from automatic creation
ADD_CUSTOM_TARGET(update-gmo DEPENDS ${LYX_UPDATED_GMO_FILES})
ADD_CUSTOM_TARGET(update-po DEPENDS ${LYX_UPDATED_PO_FILES} ${LYX_UPDATED_GMO_FILES})
set_target_properties(update-po PROPERTIES FOLDER "i18n")
set_target_properties(update-po update-gmo PROPERTIES FOLDER "i18n")
add_dependencies(update-po translations)