From feb5ee88861308446bda4aa3b8b48ccd840ef7a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Thu, 5 Oct 2023 19:05:02 +0200 Subject: core: fix build error if CMake option ENABLE_NLS is turned to off or if required dependencies are not found (closes #2026) --- po/CMakeLists.txt | 112 ++++++++++++++++++++++++++---------------------------- 1 file changed, 54 insertions(+), 58 deletions(-) (limited to 'po') diff --git a/po/CMakeLists.txt b/po/CMakeLists.txt index 1fda0cb38..578e78f72 100644 --- a/po/CMakeLists.txt +++ b/po/CMakeLists.txt @@ -17,6 +17,11 @@ # along with WeeChat. If not, see . # +# Check for programs xgettext, msgmerge and msgfmt +find_program(XGETTEXT_EXECUTABLE xgettext REQUIRED) +find_program(MSGMERGE_EXECUTABLE msgmerge REQUIRED) +find_program(MSGFMT_EXECUTABLE msgfmt REQUIRED) + set(PO_FILES cs.po de.po @@ -39,70 +44,61 @@ set(POT_FILE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${POT_FILE}") include(srcfiles.cmake) -# Looking for xgettext, msgmerge and msgfmt -find_program(XGETTEXT_EXECUTABLE xgettext) -find_program(MSGMERGE_EXECUTABLE msgmerge) -find_program(MSGFMT_EXECUTABLE msgfmt) - -if(XGETTEXT_EXECUTABLE AND MSGMERGE_EXECUTABLE AND MSGFMT_EXECUTABLE) - - # Create PO template file weechat.pot - set(SRC_FILES) - set(POT_DEPENDS) +# Create PO template file weechat.pot +set(SRC_FILES) +set(POT_DEPENDS) + +foreach(srcfile ${WEECHAT_SOURCES}) + set(SRC_FILES ${SRC_FILES} ${srcfile}) + set(POT_DEPENDS ${POT_DEPENDS} "${CMAKE_SOURCE_DIR}/${srcfile}") +endforeach() + +add_custom_command( + OUTPUT "${POT_FILE_PATH}" + COMMAND "${XGETTEXT_EXECUTABLE}" + ARGS -o "${POT_FILE_PATH}" --add-comments='TRANSLATORS:' --keyword='_' --keyword='weechat_gettext' --keyword='N_' --keyword='NG_:1,2' --keyword='weechat_ngettext:1,2' --no-location --from-code=UTF-8 --directory="${CMAKE_SOURCE_DIR}" --package-name='WeeChat' --package-version=${VERSION} --msgid-bugs-address=${BUGS_ADDRESS} --copyright-holder='NAME' ${SRC_FILES} + DEPENDS ${POT_DEPENDS} + COMMENT "Generating ${POT_FILE}" +) - foreach(srcfile ${WEECHAT_SOURCES}) - set(SRC_FILES ${SRC_FILES} ${srcfile}) - set(POT_DEPENDS ${POT_DEPENDS} "${CMAKE_SOURCE_DIR}/${srcfile}") - endforeach() +set(MO_FILES) +set(UPDATE_PO_TARGETS) +foreach(pofile ${PO_FILES}) + get_filename_component(polang ${pofile} NAME_WE) + # Compile .po files in build directory (to binary .mo files) + set(modir "${CMAKE_CURRENT_BINARY_DIR}/${polang}/LC_MESSAGES") + file(MAKE_DIRECTORY "${modir}") + set(mofile "${modir}/${PROJECT_NAME}.mo") add_custom_command( - OUTPUT "${POT_FILE_PATH}" - COMMAND "${XGETTEXT_EXECUTABLE}" - ARGS -o "${POT_FILE_PATH}" --add-comments='TRANSLATORS:' --keyword='_' --keyword='weechat_gettext' --keyword='N_' --keyword='NG_:1,2' --keyword='weechat_ngettext:1,2' --no-location --from-code=UTF-8 --directory="${CMAKE_SOURCE_DIR}" --package-name='WeeChat' --package-version=${VERSION} --msgid-bugs-address=${BUGS_ADDRESS} --copyright-holder='NAME' ${SRC_FILES} - DEPENDS ${POT_DEPENDS} - COMMENT "Generating ${POT_FILE}" + OUTPUT "${mofile}" + COMMAND "${MSGMERGE_EXECUTABLE}" ARGS --quiet -o "${CMAKE_CURRENT_BINARY_DIR}/${pofile}" "${CMAKE_CURRENT_SOURCE_DIR}/${pofile}" ${POT_FILE_PATH} + COMMAND "${MSGFMT_EXECUTABLE}" ARGS -o "${mofile}" "${CMAKE_CURRENT_BINARY_DIR}/${pofile}" + COMMAND "${MSGFMT_EXECUTABLE}" ARGS -c --statistics --verbose --output-file=/dev/null "${CMAKE_CURRENT_BINARY_DIR}/${pofile}" + DEPENDS "${POT_FILE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/${pofile}" + COMMENT "Compiling ${polang}.po" ) - set(MO_FILES) - set(UPDATE_PO_TARGETS) - foreach(pofile ${PO_FILES}) - get_filename_component(polang ${pofile} NAME_WE) - - # Compile .po files in build directory (to binary .mo files) - set(modir "${CMAKE_CURRENT_BINARY_DIR}/${polang}/LC_MESSAGES") - file(MAKE_DIRECTORY "${modir}") - set(mofile "${modir}/${PROJECT_NAME}.mo") - add_custom_command( - OUTPUT "${mofile}" - COMMAND "${MSGMERGE_EXECUTABLE}" ARGS --quiet -o "${CMAKE_CURRENT_BINARY_DIR}/${pofile}" "${CMAKE_CURRENT_SOURCE_DIR}/${pofile}" ${POT_FILE_PATH} - COMMAND "${MSGFMT_EXECUTABLE}" ARGS -o "${mofile}" "${CMAKE_CURRENT_BINARY_DIR}/${pofile}" - COMMAND "${MSGFMT_EXECUTABLE}" ARGS -c --statistics --verbose --output-file=/dev/null "${CMAKE_CURRENT_BINARY_DIR}/${pofile}" - DEPENDS "${POT_FILE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/${pofile}" - COMMENT "Compiling ${polang}.po" - ) - - # Update .po files in source directory (if needed) - add_custom_target( - update-${pofile} - COMMAND "${MSGMERGE_EXECUTABLE}" --quiet --update --previous --backup=none "${CMAKE_CURRENT_SOURCE_DIR}/${pofile}" "${POT_FILE_PATH}" - COMMENT "Updating ${polang}.po" - ) - set(UPDATE_PO_TARGETS ${UPDATE_PO_TARGETS} update-${pofile}) - - install(FILES "${mofile}" DESTINATION "${LOCALEDIR}/${polang}/LC_MESSAGES") - set(MO_FILES ${MO_FILES} ${mofile}) - endforeach() - - add_custom_target(translations ALL DEPENDS ${MO_FILES}) - - # Update weechat.pot in source directory (if needed) + # Update .po files in source directory (if needed) add_custom_target( - update-${POT_FILE} - COMMAND "${MSGMERGE_EXECUTABLE}" --quiet --update --backup=none "${CMAKE_CURRENT_SOURCE_DIR}/${POT_FILE}" "${POT_FILE_PATH}" - COMMENT "Updating ${POT_FILE}" + update-${pofile} + COMMAND "${MSGMERGE_EXECUTABLE}" --quiet --update --previous --backup=none "${CMAKE_CURRENT_SOURCE_DIR}/${pofile}" "${POT_FILE_PATH}" + COMMENT "Updating ${polang}.po" ) + set(UPDATE_PO_TARGETS ${UPDATE_PO_TARGETS} update-${pofile}) - # Update all .po and weechat.pot in source directory (if needed) - add_custom_target(update-po DEPENDS update-${POT_FILE} ${UPDATE_PO_TARGETS}) + install(FILES "${mofile}" DESTINATION "${LOCALEDIR}/${polang}/LC_MESSAGES") + set(MO_FILES ${MO_FILES} ${mofile}) +endforeach() + +add_custom_target(translations ALL DEPENDS ${MO_FILES}) + +# Update weechat.pot in source directory (if needed) +add_custom_target( + update-${POT_FILE} + COMMAND "${MSGMERGE_EXECUTABLE}" --quiet --update --backup=none "${CMAKE_CURRENT_SOURCE_DIR}/${POT_FILE}" "${POT_FILE_PATH}" + COMMENT "Updating ${POT_FILE}" +) -endif() +# Update all .po and weechat.pot in source directory (if needed) +add_custom_target(update-po DEPENDS update-${POT_FILE} ${UPDATE_PO_TARGETS}) -- cgit v1.2.3