Skip to content

Commit

Permalink
Fix dependency of msgmerge command
Browse files Browse the repository at this point in the history
Also added an option to install the updated PO files back into the
source code.
  • Loading branch information
Code7R committed Feb 29, 2024
1 parent 3270940 commit 2d1619f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 26 deletions.
7 changes: 6 additions & 1 deletion INSTALL-cmakebuild.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ Developer/Integrator notes:
```
-DEXTRA_LIBS="-lsupc++"
-DENABLE_LTO=ON
-DEXTRA_MSGMERGE=--verbose -DEXTRA_MSGFMT=--verbose
-DEXTRA_MSGMERGE=--verbose -DEXTRA_MSGFMT=--verbose --log-level=VERBOSE
```
* There is a special target called `update_pot` which refreshes the
translation master template
* Another special option is `-DPO_UPDATE=ON` which extends the `install`
target to replace the PO files in the input source code. NOTE: this might
trigger another recompilation of MO files later.

* There is a configuration example for cmake builds in rebuild.sh.
run: `./rebuild.sh -r --prefix=/usr`
Expand Down
67 changes: 42 additions & 25 deletions po/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,51 @@ if(gettext AND xgettext AND msgmerge AND msgfmt)
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Extracting translatable messages to ${_potFile} -- may require config restart!")
ADD_CUSTOM_TARGET(update_pot DEPENDS stamp-potfile)
message(VERBOSE "Adding update_pot target to update ${_potFile}")

if(EXISTS ${_potFile})
if(EXISTS ${_potFile})

if(SKIP_TRANSLATIONS)
ADD_CUSTOM_TARGET(translations)
else()
ADD_CUSTOM_TARGET(translations ALL)
endif()
if(SKIP_TRANSLATIONS)
message(VERBOSE "NOTE: SKIP_TRANSLATIONS is set, building i18n files is not part of the default build!")
ADD_CUSTOM_TARGET(translations)
else()
ADD_CUSTOM_TARGET(translations ALL)
endif()

foreach(_lang ${LANGUAGES})
SET(_tempPO "${CMAKE_CURRENT_BINARY_DIR}/${_lang}.po")
ADD_CUSTOM_COMMAND(OUTPUT ${_tempPO}
COMMAND msgmerge -o ${_tempPO} ${EXTRA_MSGMERGE} -s ${CMAKE_CURRENT_SOURCE_DIR}/${_lang}.po ${_potFile}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Updated: ${_tempPO}")
ADD_CUSTOM_TARGET(generate-${_lang}.po DEPENDS ${_tempPO})

SET(_tempMO "${CMAKE_CURRENT_BINARY_DIR}/${_lang}.gmo")
ADD_CUSTOM_COMMAND(OUTPUT ${_tempMO}
COMMAND msgfmt -o ${_tempMO} ${EXTRA_MSGFMT} ${_tempPO}
DEPENDS ${_tempPO}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
#COMMENT "Compiled: ${_tempMO}")
ADD_CUSTOM_TARGET(generate-${_lang}.gmo DEPENDS ${_tempMO})
install(FILES ${_tempMO} DESTINATION "${LOCDIR}/${_lang}/LC_MESSAGES/" RENAME "${PACKAGE}.mo" OPTIONAL)
add_dependencies(translations generate-${_lang}.gmo)
endforeach()
foreach(_lang ${LANGUAGES})
SET(_tempPO "${CMAKE_CURRENT_BINARY_DIR}/${_lang}.po")
set(_srcPO "${CMAKE_CURRENT_SOURCE_DIR}/${_lang}.po")
message(VERBOSE "Generating updated ${_tempPO} from ${_srcPO}")
ADD_CUSTOM_COMMAND(OUTPUT ${_tempPO}
COMMAND msgmerge -o "${_tempPO}" ${EXTRA_MSGMERGE} -s "${_srcPO}" "${_potFile}"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${_lang}.po" ${_potFile}
COMMENT "Updated: ${_tempPO}")
ADD_CUSTOM_TARGET(generate-${_lang}.po DEPENDS ${_tempPO})

endif()
if(PO_UPDATE)
set(SRC_UPDATE COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_tempPO}" "${_srcPO}")
else()
set(SRC_UPDATE )
endif()

SET(_tempMO "${CMAKE_CURRENT_BINARY_DIR}/${_lang}.gmo")
ADD_CUSTOM_COMMAND(OUTPUT "${_tempMO}"
COMMAND msgfmt -o ${_tempMO} ${EXTRA_MSGFMT} ${_tempPO}
${SRC_UPDATE}
DEPENDS ${_tempPO}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
#COMMENT "Compiled: ${_tempMO}")
ADD_CUSTOM_TARGET(generate-${_lang}.gmo DEPENDS ${_tempMO})
install(FILES ${_tempMO} DESTINATION "${LOCDIR}/${_lang}/LC_MESSAGES/" RENAME "${PACKAGE}.mo" OPTIONAL)
add_dependencies(translations generate-${_lang}.gmo)
endforeach()

endif()

else()
message(STATUS "Some of those tools not found, skipping translations! gettext, xgettext, msgmerge, msgfmt")

endif()

# vim: set noexpandtab:ts=2:shiftwidth=2:

0 comments on commit 2d1619f

Please sign in to comment.