CMake: Drop support for pre-generated po/*.gmo files

When a release tarball is created using Autotools, the tarball includes
po/*.gmo files which are binary files generated from po/*.po. Other
tarball creation methods don't and won't create the .gmo files.

It feels clearer if CMake will never install pre-generated binary files
from the source package. If people are able to install CMake, they
likely are able to install gettext tools as well (assuming they want
translations).
This commit is contained in:
Lasse Collin 2024-07-02 20:12:40 +03:00
parent fb99f8e8c5
commit b4b23c94fd
1 changed files with 21 additions and 45 deletions

View File

@ -321,7 +321,7 @@ if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.20")
find_package(Intl) find_package(Intl)
find_package(Gettext) find_package(Gettext)
if(Intl_FOUND) if(Intl_FOUND AND GETTEXT_FOUND)
set(XZ_NLS_DEFAULT ON) set(XZ_NLS_DEFAULT ON)
endif() endif()
endif() endif()
@ -340,22 +340,8 @@ if(XZ_NLS)
"Install libintl or set XZ_NLS=OFF.") "Install libintl or set XZ_NLS=OFF.")
endif() endif()
# If translation support is enabled but neither gettext tools or if(NOT GETTEXT_FOUND)
# pre-generated .gmo files exist, translation support cannot be enabled. message(FATAL_ERROR "XZ_NLS=ON but find_package(Gettext) failed. "
#
# The detection of pre-generated .gmo files is done by only
# checking for the existence of a single .gmo file; Ukrainian
# is one of many translations that gets regular updates.
if(NOT GETTEXT_FOUND AND
NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/po/uk.gmo")
# By default this message is shown only when new enough CMake is used
# and library support for translations was found. The assumptions is
# that in this situation the user might have interest in the
# translations. This also keeps this code simpler.
message(FATAL_ERROR "Native language support (NLS) requires either "
"gettext tools or pre-generated .gmo files. "
"The latter are only available in distribution "
"tarballs. "
"Install gettext tools or set XZ_NLS=OFF.") "Install gettext tools or set XZ_NLS=OFF.")
endif() endif()
@ -2128,37 +2114,27 @@ this many MiB of RAM if xz cannot determine the amount at runtime")
file(STRINGS po/LINGUAS LINGUAS) file(STRINGS po/LINGUAS LINGUAS)
# Where to find .gmo files. If msgfmt is available, the .po files # NOTE: gettext_process_po_files' INSTALL_DESTINATION is
# will be converted as part of the build. Otherwise we will use # incompatible with how Autotools requires the .po files to
# the pre-generated .gmo files which are included in XZ Utils # be named. CMake would require each .po file to be named with
# tarballs by Autotools. # the translation domain and thus each .po file would need its
set(GMO_DIR "${CMAKE_CURRENT_SOURCE_DIR}/po") # own language-specific directory (like "po/fi/xz.po"). On top
# of this, INSTALL_DESTINATION doesn't allow specifying COMPONENT
if(GETTEXT_FOUND) # and thus the .mo files go into "Unspecified" component. So we
# NOTE: gettext_process_po_files' INSTALL_DESTINATION is # can use gettext_process_po_files to convert the .po files but
# incompatible with how Autotools requires the .po files to # installation needs to be done with our own code.
# be named. CMake would require each .po file to be named with #
# the translation domain and thus each .po file would need its # Also, the .gmo files will go to root of the build directory
# own language-specific directory (like "po/fi/xz.po"). On top # instead of neatly into a subdirectory. This is hardcoded in
# of this, INSTALL_DESTINATION doesn't allow specifying COMPONENT # CMake's FindGettext.cmake.
# and thus the .mo files go into "Unspecified" component. So we foreach(LANG IN LISTS LINGUAS)
# can use gettext_process_po_files to convert the .po files but gettext_process_po_files("${LANG}" ALL
# installation needs to be done with our own code. PO_FILES "${CMAKE_CURRENT_SOURCE_DIR}/po/${LANG}.po")
# endforeach()
# Also, the .gmo files will go to root of the build directory
# instead of neatly into a subdirectory. This is hardcoded in
# CMake's FindGettext.cmake.
foreach(LANG IN LISTS LINGUAS)
gettext_process_po_files("${LANG}" ALL
PO_FILES "${CMAKE_CURRENT_SOURCE_DIR}/po/${LANG}.po")
endforeach()
set(GMO_DIR "${CMAKE_CURRENT_BINARY_DIR}")
endif()
foreach(LANG IN LISTS LINGUAS) foreach(LANG IN LISTS LINGUAS)
install( install(
FILES "${GMO_DIR}/${LANG}.gmo" FILES "${CMAKE_CURRENT_BINARY_DIR}/${LANG}.gmo"
DESTINATION "${CMAKE_INSTALL_LOCALEDIR}/${LANG}/LC_MESSAGES" DESTINATION "${CMAKE_INSTALL_LOCALEDIR}/${LANG}/LC_MESSAGES"
RENAME "${TRANSLATION_DOMAIN}.mo" RENAME "${TRANSLATION_DOMAIN}.mo"
COMPONENT xz_Runtime) COMPONENT xz_Runtime)